tracing

package
v1.0.0-beta4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Replay-aware OpenTelemetry tracing

By default, Durable Task clients and workers only propagate W3C trace context. They emit no spans. When you opt in, the SDK exports durable orchestration, activity, sub-orchestration, timer, event, and entity spans through your application's OpenTelemetry provider, next to your own application spans. Your provider sends them to any OpenTelemetry-compatible backend. You don't need a scheduler-specific telemetry exporter.

Enable tracing

Configure the worker's OpenTelemetry SDK provider with both Durable Task wrappers. Then pass the provider to the worker and, optionally, to the client:

provider := sdktrace.NewTracerProvider(
	tracing.WithIDGenerator(nil),
	tracing.WithSampler(sdktrace.ParentBased(sdktrace.AlwaysSample())),
	sdktrace.WithBatcher(exporter),
	sdktrace.WithResource(res),
)

worker, err := durabletaskscheduler.NewWorker(options, registry, logger,
	client.WithWorkerTracerProvider(provider))
if err != nil {
	// errors.Is(err, tracing.ErrUnsupportedTracerProvider) reports a provider
	// that is missing a wrapper.
	return err
}
managementClient, err := durabletaskscheduler.NewClient(ctx, options, logger,
	client.WithTracerProvider(provider))
if err != nil {
	return err
}

client.WithTracerProvider accepts any tracer provider, including otel.GetTracerProvider(). client.WithWorkerTracerProvider rejects a provider that doesn't use both wrappers. The error wraps tracing.ErrUnsupportedTracerProvider and names the failed check. The wrappers must be the provider's top-level ID generator and sampler:

  • The ID generator applies persisted span identities when the worker reconstructs spans. Your application spans still get IDs from its base generator.
  • The sampler answers sampling queries without starting live spans.

To customize either one, pass your generator or sampler to the wrapper as its base. Don't replace the wrapper with sdktrace.WithIDGenerator or sdktrace.WithSampler, and don't nest the wrapper inside another sampler.

Your application owns the provider's resource, processors, exporter, flushing, and shutdown. Shut down the worker, close the client, and then shut down the provider. otel.SetTracerProvider(provider) is optional for Durable Task, but it helps instrumentation libraries that use the global provider. For a complete setup, see the distributed tracing sample. It exports to an OTLP/HTTP collector, which can forward the spans to Jaeger, Azure Monitor, or another OTLP backend.

Service-side telemetry and duplicates

Durable Task Scheduler (DTS) persists and forwards trace context, but it doesn't emit durable orchestration, activity, timer, sub-orchestration, or entity spans. It also doesn't export spans to your telemetry backend. To see durable spans in your backend, enable SDK tracing.

SDK spans use the Microsoft.DurableTask instrumentation scope and your provider's resource. If another component, such as a host or a future scheduler-side export, emits durable spans for the same work into the same backend, enable only one source. To keep the SDK silent, omit client.WithWorkerTracerProvider and client.WithTracerProvider.

Logical spans, not execution-turn spans

An orchestrator replays from history on each dispatch. The SDK doesn't emit a span for each dispatch or replay. Instead, it emits one logical orchestration:<name> SERVER span for each execution. Each continue-as-new generation is a separate execution. The span starts at the execution's first traced dispatch and ends when the execution completes, fails, terminates, or continues as new. The worker persists the span's ID and start time with the backend, and reconstructs the span with that identity when the execution finishes.

As a result:

  • A running, suspended, or never-completing orchestration has no exported orchestration span yet. Its exported children can appear under a parent that your backend doesn't show until the orchestration completes. If the orchestration is purged or abandoned first, the parent never appears.
  • If tracing is enabled while an orchestration is already running, its span starts at the first traced dispatch.
  • The JavaScript SDK works differently. It emits one SERVER span per dispatch.

Spans and lifecycle

Task span names use <type>:<name>@(<version>). The @(<version>) suffix is omitted when the task is unversioned. Entity names are lowercase, as in EntityID.String.

Operation Span name Kind and parent
Client schedules orchestration create_orchestration:<name> PRODUCER under caller
Orchestration execution orchestration:<name> SERVER under create span, or under the propagated caller context when client tracing is off; trace root without caller context
Activity scheduling activity:<name> CLIENT under orchestration
Activity execution activity:<name> SERVER under scheduling span; active in ActivityContext.Context()
Sub-orchestration scheduling orchestration:<child> CLIENT under parent orchestration
Sub-orchestration execution orchestration:<child> SERVER under scheduling span
Durable timer orchestration:<name>:timer INTERNAL under orchestration
Client raises event orchestration_event:<event> PRODUCER under caller
Orchestrator sends event orchestration_event:<event> PRODUCER under sending orchestration
Orchestrator signals entity entity:<name>:<operation> PRODUCER under orchestration
Orchestrator calls entity entity:<name>:<operation> CLIENT under orchestration
Entity signal execution entity:<name>:<operation> CONSUMER, independent root
Entity call execution entity:<name>:<operation> SERVER, independent root

When each kind of span is exported:

  • Orchestration spans are exported after the backend accepts the completion of the execution.
  • Activity execution spans are live. HTTP, database, and other application spans that you start from ActivityContext.Context() nest under them. The span starts after the worker's version check, so work that the worker rejects for a version mismatch exports no span. The span ends right after the activity runs and reports the activity's own outcome, even if that outcome doesn't reach the backend.
  • Scheduling, entity-call, and timer spans are reconstructed from history. They're exported when the backend accepts the dispatch that consumes their completion.
  • Event-send and entity-signal spans are exported after the backend accepts their sending dispatch. If a new send's acknowledgement arrives in the same dispatch, the span is exported with that dispatch.
  • Entity execution spans are exported after the backend accepts the batch. They use the operation result's timestamps. EntityContext.Context() carries the operation's span context as a non-recording span, so application spans that you start from it nest under the operation span.

Replayed history emits no new spans. Orchestration spans aren't live inside the orchestrator. An application span that you start from orchestrator code isn't replay-safe.

Attributes include durabletask.type, durabletask.task.name, durabletask.task.version, and durabletask.task.instance_id. Some spans also carry durabletask.task.execution_id, the integer durabletask.task.task_id, durabletask.task.status, or durabletask.fire_at. On activity, timer, sub-orchestration scheduling, and entity caller spans, durabletask.task.instance_id is the calling orchestration's instance ID. On entity execution spans, it's the entity ID. Entity spans follow DurableTask.Core names and kinds:

  • durabletask.task.operation is call_entity or signal_entity.
  • durabletask.entity.operation is the operation name, as in the Python and JavaScript SDKs.

Failures get an error status. Successful spans leave the status unset.

Without caller context, an orchestration becomes the root of a new trace. Its trace ID is derived from the orchestration's persisted identity, not from the base ID generator. With the default parent-based sampler, sampling follows the propagated trace flags and keeps tracestate, so unsampled orchestration trees stay unsampled. Custom base samplers also control child-span decisions; use sdktrace.ParentBased(sdktrace.TraceIDRatioBased(ratio)) for ratio sampling that honors the caller's decision. Root sampling is evaluated again on each dispatch, so use a root sampler whose decision depends only on the trace ID. Continue-as-new and rewind start a new orchestration span identity. A rewind that carries a parent trace context reparents the orchestration under that context.

SDK parity

This table compares tracing in the application process of each Durable Task SDK: durabletask-dotnet (gRPC), durabletask-python, and durabletask-js (@microsoft/durabletask-js). It doesn't cover Azure Functions host telemetry.

Feature Go .NET gRPC Python JavaScript
Enabled by default No. Opt in with an injected provider Yes. ActivitySource is always on; spans are exported when the app adds the source Yes, with the global provider. Opt out with emit_trace_spans=False Yes, with the global @opentelemetry/api provider
Instrumentation scope Microsoft.DurableTask Microsoft.DurableTask durabletask Microsoft.DurableTask
Client create orchestration and raise event PRODUCER PRODUCER PRODUCER PRODUCER
Orchestration span One logical SERVER span per execution, with persisted ID and start time One logical SERVER span per execution, with persisted ID and start time One logical SERVER span per execution, with persisted ID and start time One SERVER span per dispatch that starts at the dispatch, with durabletask.task.replay_span_id and replay_start_time attributes
Orchestration without caller context New root trace No orchestration span New root trace Uses the active context, or a new root trace if there isn't one
Export timing After the backend accepts the completion Before the completion is accepted Before the completion is accepted Before the completion is accepted
Activity and sub-orchestration scheduling and execution CLIENT and SERVER CLIENT and SERVER CLIENT and SERVER CLIENT and SERVER. The CLIENT span doesn't reuse the propagated span ID, so the SERVER span's parent is never exported
Durable timers orchestration:<name>:timer INTERNAL orchestration:<name>:timer INTERNAL orchestration:<name>:timer INTERNAL orchestration:<name>:timer INTERNAL
Orchestrator sends event PRODUCER PRODUCER PRODUCER PRODUCER
Event receipt No CONSUMER span No CONSUMER span No CONSUMER span No CONSUMER span
Orchestrator calls or signals entity entity:<name>:<op> CLIENT or PRODUCER No spans No spans call_entity:<op> CLIENT, or signal_entity:<op> PRODUCER with zero duration
Entity operation execution entity:<name>:<op> SERVER for calls, CONSUMER for signals No spans entity:<name>:<op> SERVER for calls and signals No spans
Client signals entity No span. Caller context, sampled or not, is propagated No span. Caller context is propagated No span signal_entity:<op> PRODUCER
Entity locks No spans No spans No spans entity:lock_request INTERNAL
Success status Unset Unset Unset OK
Span reconstruction Public ID-generator and sampler wrappers Activity reconstruction helpers Deferred spans through OpenTelemetry SDK internals Not applicable, spans are per dispatch

Go's entity span names, kinds, and durabletask.task.operation values follow DurableTask.Core, which also emits the full caller and execution set. Go also adds the durabletask.entity.operation attribute that the Python and JavaScript SDKs use.

Limitations

  • Telemetry is best effort in both directions, not exactly once.
    • Retried or redelivered work can export the same spans again.
    • If the backend accepts a completion but the reply is lost, and the retry reports the work item gone, that completion's spans are lost.
    • Abandoned orchestration dispatches export no orchestration telemetry.
    • Live activity spans describe attempts, even when the result isn't accepted.
  • Events carry no trace context. Receipt emits no CONSUMER span, and a send doesn't reparent or link the receiving orchestration.
  • V2 entity operations carry no parent trace context. Entity execution spans are independent roots that the provider's root sampler samples. They don't form a joined orchestration and entity tree, and the SDK adds no synthetic parents or links.
  • Entity-started work doesn't join the trace on DTS. Signals and orchestration starts from an entity carry the operation's trace context on the action, but DTS doesn't currently forward it.
  • No PRODUCER spans for entity-started work. The SDK doesn't emit DurableTask.Core's entity-to-entity signal or orchestration-start PRODUCER spans (StartActivityForEntityStartingAnOrchestration).
  • Span reconstruction depends on the backend. The backend must return the persisted orchestration trace context on later dispatches.

Documentation

Overview

Package tracing configures opt-in OpenTelemetry spans for Durable Task clients and workers.

The tracing guide at https://github.com/microsoft/durabletask-go/blob/main/tracing/README.md describes the span catalog, logical orchestration spans, service-side telemetry, and parity with the Durable Task .NET, Python, and JavaScript SDKs. The samples/distributedtracing module in the same repository exports these spans to an OTLP collector.

By default clients and workers only propagate W3C trace context and emit no spans. Enable worker spans with github.com/microsoft/durabletask-go/client.WithWorkerTracerProvider and a provider built with WithIDGenerator and WithSampler:

provider := sdktrace.NewTracerProvider(
	tracing.WithIDGenerator(nil),
	tracing.WithSampler(nil),
	sdktrace.WithBatcher(exporter),
)
worker, err := durabletaskscheduler.NewWorker(..., client.WithWorkerTracerProvider(provider))

Enable client spans with github.com/microsoft/durabletask-go/client.WithTracerProvider. Client spans are started live and never reconstructed, so any provider works, including otel.GetTracerProvider(), the global delegating provider. The client and worker can also share one provider configured with WithIDGenerator and WithSampler:

c, err := durabletaskscheduler.NewClient(ctx, options, logger, client.WithTracerProvider(provider))

The client emits a PRODUCER span named "create_orchestration:<name>" (with an "@(<version>)" suffix when versioned) for each ScheduleNewOrchestration call and parents the new orchestration to it, and a PRODUCER span named "orchestration_event:<event>" for each RaiseEvent call. Both are children of the span in the call's context, and failed calls, including invalid options, payload serialization, and payload externalization failures, record an error status.

The application owns the provider's resource, sampling policy, processors, exporter, and shutdown. Spans use the "Microsoft.DurableTask" instrumentation scope, like the Durable Task .NET, JavaScript, and Java SDKs.

Orchestrations replay from history, so the worker never keeps a live orchestration span between dispatches. It persists the span's ID and start time with the backend and reconstructs completed spans with their original identity. Reconstruction needs the provider to honor requested span IDs and to report sampling decisions without starting spans, which is why WithIDGenerator and WithSampler are required; the worker rejects other providers instead of exporting a disconnected span tree. The wrappers must be the provider's top-level ID generator and sampler: to customize them, pass the application's generator or sampler as base rather than wrapping the Durable Task wrapper, for example tracing.WithSampler(sdktrace.ParentBased(...)) rather than sdktrace.WithSampler(sdktrace.ParentBased(tracing.NewSampler(...))). Consequently:

  • The orchestration span is exported once, when the execution completes, fails, terminates, or continues as new.
  • Activity and sub-orchestration scheduling (CLIENT) spans and timer spans are exported when the dispatch that consumes their completion is accepted by the backend. Replayed history exports nothing.
  • Activity executions are live SERVER spans that are active in the activity's context, so application spans nest under them. The span reports the activity's own outcome, whether or not that outcome reaches the backend. Work the worker rejects before running activity code, such as a version mismatch with task.VersionFailureReject, exports no span.
  • Orchestrator SendEvent actions emit "orchestration_event:<event>" PRODUCER spans under the sending orchestration when accepted. Replayed sends and later history acknowledgements emit nothing. A new send whose acknowledgement arrives in the same dispatch is exported with that dispatch.
  • Event receipt does not emit a consumer span. The event protocol carries no trace context, so sends cannot parent or link the receiving orchestration to the sender's event span.
  • Entity spans are named "entity:<name>:<operation>" and carry the DurableTask.Core "durabletask.task.operation" attribute ("call_entity" or "signal_entity") and the "durabletask.entity.operation" attribute (the operation name) used by the Python and JavaScript SDKs. Orchestrator entity signals emit PRODUCER spans under the orchestration when accepted, following the same replay rules as SendEvent. Entity calls emit CLIENT spans when the dispatch that consumes their completion is accepted. Replayed history emits neither.
  • Entity operation executions emit SERVER spans for calls and CONSUMER spans for signals. Each operation's span identity and sampling decision are reserved before the batch runs, and the operation's handler context carries that identity as a non-recording span context, so application spans started from EntityContext.Context() nest under it. Signals and orchestrations started by the operation carry it as their parent trace context. The span itself is reconstructed with the operation's result timestamps and reserved sampling result only after the backend accepts the batch result. Rejected, abandoned, or lost batches export nothing, so application spans may reference a parent that is never exported. Successful operations leave the status unset; failed operations and worker-observed batch failures record an error status and the "durabletask.entity.error_message" attribute. If a backend replaces an accepted batch result, for example when it is too large, the completion response does not return the replacement, so span status reflects the worker's result. Durable Task Scheduler does not currently forward the parent trace context of entity-started signals and orchestrations.
  • V2 entity messages carry no trace context, so entity execution spans are independent trace roots, sampled by the provider's root policy, rather than children of the calling orchestration or client span. Their IDs come from the base generator passed to WithIDGenerator. No synthetic parent or span link is added.
  • Client SignalEntity emits no span. It propagates the caller's trace context on the request, including unsampled contexts. The Python SDK also emits no client span for signals; the JavaScript SDK emits a "signal_entity" PRODUCER span.
  • Entity lock acquisition and release emit no spans, matching DurableTask.Core; entity calls made inside a critical section are traced.
  • Abandoned orchestration dispatches export no orchestration telemetry.
  • Telemetry is best effort, not exactly once, in both directions. A completion the backend retries may export its spans again. A completion the backend accepted but whose reply was lost, so that the retry reports the work item gone, may export none.
  • Orchestration spans join the trace context recorded when the orchestration was scheduled, or the parent trace context recorded when a sub-orchestration was rewound. An orchestration scheduled without trace context becomes the root of a new trace. Its trace ID is derived from the orchestration's instance, execution, and span identity, so it does not come from the base generator passed to WithIDGenerator; for example, an AWS X-Ray format generator does not apply to it. Its sampling decision comes from the sampler passed to WithSampler. It is evaluated once per dispatch and reused for every span that dispatch exports, but it is re-evaluated on later dispatches, so it is stable across dispatches only for samplers that decide deterministically from the trace ID, such as the OpenTelemetry SDK's built-in samplers.
  • Span identity persistence depends on the backend returning the orchestration trace context on later dispatches. Continue-as-new and rewind start a new orchestration span identity.
  • An activity or sub-orchestration scheduled before a rewind stays in the trace that scheduled it, where its execution spans are parented, and its scheduling span links to the rewound orchestration span. A sub-orchestration whose failure caused the rewind already exported its scheduling span with an error, so its recovery is exported as a new CLIENT span in the same trace; the recovered child execution remains parented under the original scheduling span.

Sampling follows the caller's trace flags, including when the caller's context is unsampled: unsampled orchestrations stay unsampled, and tracestate is preserved.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedTracerProvider = dttrace.ErrUnsupportedTracerProvider

ErrUnsupportedTracerProvider is returned when worker tracing is enabled with a provider that does not use both WithIDGenerator and WithSampler. The returned error wraps it and names the unmet requirement; match it with errors.Is.

Functions

func NewIDGenerator

func NewIDGenerator(base sdktrace.IDGenerator) sdktrace.IDGenerator

NewIDGenerator wraps base so Durable Task can reconstruct spans with their persisted IDs. Application spans always receive IDs from base. A nil base uses random IDs, like the OpenTelemetry SDK default. The result must be the provider's top-level ID generator; do not wrap it in another generator. Each reconstruction override is consumed once, before span processors run; spans started by processors from that context receive ordinary IDs.

func NewSampler

func NewSampler(base sdktrace.Sampler) sdktrace.Sampler

NewSampler wraps base so Durable Task can learn sampling decisions for reconstructed root orchestration and entity operation spans without starting spans. Reconstructed root spans reuse their reserved sampling results. Other spans are sampled exactly as base decides. A nil base uses sdktrace.ParentBased(sdktrace.AlwaysSample()), the OpenTelemetry SDK default. The result must be the provider's top-level sampler: pass a composite such as sdktrace.ParentBased as base instead of nesting this sampler inside it.

func WithIDGenerator

func WithIDGenerator(base sdktrace.IDGenerator) sdktrace.TracerProviderOption

WithIDGenerator returns the tracer provider option required by Durable Task tracing. Pass any custom application ID generator as base instead of also using sdktrace.WithIDGenerator, which would replace this one.

func WithSampler

WithSampler returns the tracer provider option required by Durable Task tracing. Pass the application's sampler as base instead of also using sdktrace.WithSampler, which would replace this one.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL