Skip to content

Commit

Permalink
Extended reporting of failed workflow with OTel (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkoutnycz authored May 29, 2024
1 parent ef70705 commit 1f6676b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Temporalio.Extensions.OpenTelemetry/TracingInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ protected virtual IDictionary<string, Payload> HeadersFromContext(
return ret;
}

private static void RecordExceptionWithStatus(Activity? activity, Exception exception)
{
activity?.SetStatus(ActivityStatusCode.Error, exception.Message);
activity?.RecordException(exception);
}

private sealed class ClientOutbound : ClientOutboundInterceptor
{
private readonly TracingInterceptor root;
Expand Down Expand Up @@ -370,7 +376,7 @@ public override async Task HandleSignalAsync(HandleSignalInput input)
}
catch (Exception e)
{
activity.Activity?.RecordException(e);
RecordExceptionWithStatus(activity.Activity, e);
throw;
}
}
Expand Down Expand Up @@ -406,7 +412,7 @@ public override void ValidateUpdate(HandleUpdateInput input)
}
catch (Exception e)
{
activity.Activity?.RecordException(e);
RecordExceptionWithStatus(activity.Activity, e);
throw;
}
}
Expand Down Expand Up @@ -447,7 +453,7 @@ public override void ValidateUpdate(HandleUpdateInput input)
"CompleteUpdate" : "WorkflowTaskFailure";
WorkflowsSource.TrackWorkflowDiagnosticActivity(
name: $"{namePrefix}:{input.Update}",
updateActivity: act => act.RecordException(e)).
updateActivity: act => RecordExceptionWithStatus(act, e)).
Dispose();
throw;
}
Expand All @@ -474,7 +480,7 @@ private static void ApplyWorkflowException(Exception e)
"CompleteWorkflow" : "WorkflowTaskFailure";
WorkflowsSource.TrackWorkflowDiagnosticActivity(
name: $"{namePrefix}:{Workflow.Info.WorkflowType}",
updateActivity: act => act.RecordException(e)).
updateActivity: act => RecordExceptionWithStatus(act, e)).
Dispose();
}

Expand Down Expand Up @@ -593,7 +599,7 @@ internal ActivityInbound(TracingInterceptor root, ActivityInboundInterceptor nex
}
catch (Exception e)
{
activity.RecordException(e);
RecordExceptionWithStatus(activity, e);
throw;
}
}
Expand Down

0 comments on commit 1f6676b

Please sign in to comment.