diff --git a/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs b/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs index 83382d4d9..e113c77ec 100644 --- a/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs +++ b/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs @@ -54,10 +54,6 @@ public class OpenTelemetryTracingWorkflowExecutionMiddleware(WorkflowMiddlewareD activity.AddEvent(new ActivityEvent("Faulted")); activity.SetStatus(ActivityStatusCode.Error); activity.SetTag("error", true); - activity.SetTag("hasIncidents", true); - - if (context.Incidents.Count > 0) - activity.SetTag("error.message", JsonSerializer.Serialize(context.Incidents, _incidentSerializerOptions)); } else { @@ -68,6 +64,16 @@ public class OpenTelemetryTracingWorkflowExecutionMiddleware(WorkflowMiddlewareD }))); } + if(context.Incidents.Any()) + { + activity.SetStatus(ActivityStatusCode.Error); + activity.SetTag("hasIncidents", true); + activity.SetTag("error", true); + + if (context.Incidents.Count > 0) + activity.SetTag("error.message", JsonSerializer.Serialize(context.Incidents, _incidentSerializerOptions)); + } + if (!string.IsNullOrWhiteSpace(context.CorrelationId)) activity.SetTag("correlationId", context.CorrelationId);