From 2aa312850db574e9200346572cd30f45372c5bc6 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 5 Oct 2024 11:19:02 +0200 Subject: [PATCH] Refactor incident tagging logic in tracing middleware Reorganized the logic for setting tags when incidents are present in `OpenTelemetryTracingWorkflowExecutionMiddleware`. The new structure ensures consistent tag setting for error status and incidents, improving code readability and maintainability. --- ...nTelemetryTracingWorkflowExecutionMiddleware.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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);