From 02f1b56eb14250c5a642b02304227ae25939871a Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 7 Oct 2024 10:15:35 +0200 Subject: [PATCH] Add tracing for trigger activities in workflow execution Enhanced the OpenTelemetry tracing middleware to include detailed information about the triggered activity within the workflow execution. This change adds tags for the activity ID, name, and type to provide better observability and debugging insights. --- .../OpenTelemetryTracingWorkflowExecutionMiddleware.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs b/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs index f374f1a78..f5d20b7c5 100644 --- a/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs +++ b/src/modules/Elsa.OpenTelemetry/Middleware/OpenTelemetryTracingWorkflowExecutionMiddleware.cs @@ -40,6 +40,15 @@ public class OpenTelemetryTracingWorkflowExecutionMiddleware(WorkflowMiddlewareD span.SetTag("workflowDefinition.version", workflow.Identity.Version); span.SetTag("workflowDefinition.name", workflow.WorkflowMetadata.Name); span.SetTag("workflowExecution.startTimeUtc", span.StartTimeUtc); + + if(context.TriggerActivityId != null) + { + var activity = context.FindActivityById(context.TriggerActivityId) ?? throw new Exception($"Trigger activity with ID {context.TriggerActivityId} not found. This should not happen."); + span.SetTag("workflowExecution.trigger.activityId", activity.Id); + span.SetTag("workflowExecution.trigger.activityName", activity.Name); + span.SetTag("workflowExecution.trigger.activityType", activity.Type); + } + span.AddEvent(new ActivityEvent("Executing", tags: CreateStatusTags(context))); await Next(context);