Class TracingInterceptor
- Namespace
- Temporalio.Extensions.OpenTelemetry
- Assembly
- Temporalio.Extensions.OpenTelemetry.dll
Client and worker interceptor that will create and propagate diagnostic activities for clients, workflows, and activities. This can be instantiated and set as an interceptor on the client options and it will automatically apply to all uses including workers.
public class TracingInterceptor : IClientInterceptor, IWorkerInterceptor
- Inheritance
-
TracingInterceptor
- Implements
- Inherited Members
Remarks
This uses OpenTelemetry context propagation and Temporal headers to serialize the diagnostic activities across workers. Normal ActivitySource methods can be used for client and activity code. Workflows however are interruptible/resumable and therefore cannot support .NET activities (i.e. OpenTelemetry spans) that remain open across workers. Therefore, all uses of diagnostic activities inside workflows should only use TrackWorkflowDiagnosticActivity(ActivitySource, string, ActivityKind, IEnumerable<KeyValuePair<string, object?>>?, IEnumerable<ActivityLink>?, bool, bool, Action<Activity>?). See the project README for more information.
Constructors
TracingInterceptor(TracingInterceptorOptions?)
Initializes a new instance of the TracingInterceptor class.
public TracingInterceptor(TracingInterceptorOptions? options = null)
Parameters
options
TracingInterceptorOptionsOptional options.
Fields
ActivitiesSource
Source used for all activity inbound diagnostic activities.
public static readonly ActivitySource ActivitiesSource
Field Value
ClientSource
Source used for all client outbound diagnostic activities.
public static readonly ActivitySource ClientSource
Field Value
WorkflowsSource
Source used for all workflow inbound/outbound diagnostic activities.
public static readonly ActivitySource WorkflowsSource
Field Value
Properties
Options
Gets the options this interceptor was created with. This should never be mutated.
public TracingInterceptorOptions Options { get; init; }
Property Value
Methods
CreateInActivityTags()
Create tag collection from the current activity environment. Must be called within an activity.
protected virtual IEnumerable<KeyValuePair<string, object?>> CreateInActivityTags()
Returns
- IEnumerable<KeyValuePair<string, object>>
Tags.
CreateInWorkflowTags()
Create tag collection from the current workflow environment. Must be called within a workflow.
protected virtual IEnumerable<KeyValuePair<string, object?>> CreateInWorkflowTags()
Returns
- IEnumerable<KeyValuePair<string, object>>
Tags.
CreateUpdateTags(string, string?)
Create tag collection for the given workflow and update ID.
protected virtual IEnumerable<KeyValuePair<string, object?>> CreateUpdateTags(string workflowId, string? updateId)
Parameters
Returns
- IEnumerable<KeyValuePair<string, object>>
Tags.
CreateWorkflowTags(string)
Create tag collection for the given workflow ID.
protected virtual IEnumerable<KeyValuePair<string, object?>> CreateWorkflowTags(string workflowId)
Parameters
workflowId
stringWorkflow ID.
Returns
- IEnumerable<KeyValuePair<string, object>>
Tags.
HeadersFromContext(IDictionary<string, Payload>?, PropagationContext)
Serialize an OTel context to Temporal headers.
protected virtual IDictionary<string, Payload> HeadersFromContext(IDictionary<string, Payload>? headers, PropagationContext ctx)
Parameters
headers
IDictionary<string, Payload>Headers to mutate if present.
ctx
PropagationContextOTel context.
Returns
- IDictionary<string, Payload>
Created/updated headers.
HeadersToContext(IReadOnlyDictionary<string, Payload>?)
Deserialize Temporal headers to OTel context.
protected virtual PropagationContext? HeadersToContext(IReadOnlyDictionary<string, Payload>? headers)
Parameters
headers
IReadOnlyDictionary<string, Payload>Headers to deserialize from.
Returns
- PropagationContext?
OTel context if any on the headers.
InterceptActivity(ActivityInboundInterceptor)
Create an activity inbound interceptor to intercept calls.
public ActivityInboundInterceptor InterceptActivity(ActivityInboundInterceptor nextInterceptor)
Parameters
nextInterceptor
ActivityInboundInterceptorThe next interceptor in the chain to call.
Returns
- ActivityInboundInterceptor
Created interceptor.
InterceptClient(ClientOutboundInterceptor)
Create a client outbound interceptor to intercept calls.
public ClientOutboundInterceptor InterceptClient(ClientOutboundInterceptor nextInterceptor)
Parameters
nextInterceptor
ClientOutboundInterceptorThe next interceptor in the chain to call.
Returns
- ClientOutboundInterceptor
Created interceptor.
InterceptWorkflow(WorkflowInboundInterceptor)
Create a workflow inbound interceptor to intercept calls.
public WorkflowInboundInterceptor InterceptWorkflow(WorkflowInboundInterceptor nextInterceptor)
Parameters
nextInterceptor
WorkflowInboundInterceptorThe next interceptor in the chain to call.
Returns
- WorkflowInboundInterceptor
Created interceptor.