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.
This commit is contained in:
Sipke Schoorstra 2024-10-05 11:19:02 +02:00
parent 41e1062148
commit 2aa312850d

View file

@ -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);