Repository navigation
Add replay-aware entity tracing - #192
Conversation
ec9f60e to
32eeb80
Compare
9d730dd to
85cb1d9
Compare
85cb1d9 to
18730c9
Compare
18730c9 to
941820f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Tracer.emit reruns the base sampler instead of preserving the reserved sampling decision, which can drop an accepted operation’s parent span or alter propagated tracestate.
1 open issue
What changed in this PR
Extends the opt-in OpenTelemetry tracing introduced in #189 to entities, supporting application-owned tracing for the broader lifecycle visibility goal in #175.
Changes:
- Adds entity execution spans exported after batch acceptance, with reserved span identities available to handlers and entity-started actions.
- Adds replay-aware orchestration spans for entity calls and signals; lock operations remain untraced.
- Adds tracing tests and documents sampling, propagation, and protocol limitations.
| File | Description |
|---|---|
tracing/tracing.go |
Documents entity tracing behavior and limitations. |
task/orchestrator.go |
Records entity signals and confirms acknowledgements. |
task/executor.go |
Attaches reserved operation span contexts to handlers. |
task/entity.go |
Propagates operation trace context to entity-started work. |
internal/dttrace/entity.go |
Implements entity execution, call, and signal tracing. |
internal/dttrace/dttrace.go |
Integrates entity history tracking and span emission. |
client/grpc_worker_tracing_test.go |
Tests replay, sampling, failures, and handler trace context. |
client/grpc_worker_processor.go |
Reserves operation identities and emits spans after acceptance. |
client/client_grpc_tracing_test.go |
Tests unchanged client signal propagation without spans. |
CHANGELOG.md |
Announces opt-in entity tracing. |
Review effort: Balanced
941820f to
78815ab
Compare
78815ab to
2906ce7
Compare
2906ce7 to
42156f7
Compare
Entity spans are named "entity:<name>:<operation>" and carry the DurableTask.Core "durabletask.task.operation" attribute (call_entity or signal_entity) plus "durabletask.entity.operation" (the operation name) used by the Python and JavaScript SDKs. Orchestrations emit CLIENT spans for entity calls when a new completion is consumed and PRODUCER spans for entity signals when accepted, using the same replay and acknowledgement rules as SendEvent. Calls and signals store only minimal state until a span is queued, and replayed signals whose acknowledgement is already in the request are not recorded. Lock operations emit no spans. Entity operation executions emit SERVER (call) and CONSUMER (signal) spans. Each operation's root span identity and sampling decision are reserved before the batch runs; the handler context carries that identity as a non-recording span context, and signals and orchestrations started by the operation carry it as their parent trace context. The span is reconstructed with operation-result timestamps only after the backend accepts the batch completion, so rejected, abandoned, or lost batches export nothing. Success leaves the status unset; failures set an error status and "durabletask.entity.error_message". V2 entity messages carry no trace context, so execution spans are independent roots. Client SignalEntity emits no span and propagates only a sampled caller context, matching the .NET gRPC client. This squashes the original entity tracing series onto the reworked orchestration event layer. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
42156f7 to
c744bfc
Compare
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
Post-merge review: Reserving the span identity and sampling decision before the handler, then exporting only after acknowledgement, handles replay without changing the API or wire schema. Two in-memory reproductions revealed behavior changes when tracing is enabled: context-based HTTP instrumentation can stop recording, and propagation can push a completion over the size limit.
| if spanContext.IsValid() { | ||
| // The operation span is reconstructed after the batch is accepted; | ||
| // handlers see its reserved, non-recording identity. | ||
| ctx = trace.ContextWithSpanContext(ctx, spanContext) |
There was a problem hiding this comment.
trace.ContextWithSpanContext installs a valid parent whose TracerProvider() is a no-op. I reproduced this with the sample's otelhttp: the default transport made the request but emitted no CLIENT span; setting otelhttp.WithTracerProvider(provider) produced a child of the accepted entity span. Could the reserved non-recording span expose the worker provider without recording before acknowledgement? Please also test instrumentation that discovers its provider from the handler context, since the current test passes the provider explicitly.
| Input: rawInput, | ||
| RequestTime: timestampOrNil(ctx.currentTime), | ||
| ScheduledTime: timestampOrNil(scheduledTime), | ||
| ParentTraceContext: helpers.TraceContextFromSpanContext(ctx.spanContext), |
There was a problem hiding this comment.
Propagation adds bytes to each outbound entity action. In durabletasktest, a call returning (4 << 20) - 5000 bytes and enqueueing 64 small signals succeeded with tracing off but returned EntityResultTooLarge with tracing on; the backend discarded the outbound actions too. Please add a near-limit regression and consider omitting optional propagation metadata if it alone exceeds a known completion budget. If that cannot be mitigated, document the tradeoff. This was reproduced in memory, not on live DTS.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
78815aba6e3c14e2ec8c8b83c7a5cc48d835a335↑ Build, vet, full repository tests, the full race suite with the pinned DTS emulator, and pinned lint pass.
↓ Azurite-dependent tests and the optional batching experiment were not exercised.
Adds opt-in entity tracing through the application-owned OpenTelemetry providers, extending the tracing lifecycle in #189. Spans use the
Microsoft.DurableTaskinstrumentation scope.entity:<name>:<operation>. Calls are SERVER spans and signals are CONSUMER spans. Before the batch runs, the worker reserves each operation's root span ID, trace ID, and sampling result. The operation's handler context (EntityContext.Context()) carries that identity as a non-recording span context, so application spans started there nest under the operation span. The span itself is reconstructed with the reserved IDs, sampling decision, tracestate, sampler attributes, and operation-result timestamps only afterCompleteEntityTaskis accepted. Abandoned, rejected, or lost batches export no entity spans. Dropped operations record nothing; RecordOnly operations remain unsampled and are delivered to span processors without resampling.SendSignalandStartNewOrchestrationoperation actions produced by an operation carry the operation's span context asParentTraceContext(traceparent and tracestate, with the sampling flag kept even when unsampled). Durable Task Scheduler does not currently forward this field, so entity-started signals and orchestrations do not yet join the operation's trace there. The field is part of the protocol and is ignored by backends that don't use it.durabletask.entity.error_message.SendEventin Trace orchestration event sends (replay-aware PRODUCER spans) #189. A signal whose acknowledgement is already in the request (including beyond the turn's event budget) is not re-emitted. Replayed calls and signals keep only minimal state until a span is needed. A call whose recorded target is not a valid entity ID completes normally and emits no span.SignalEntity: emits no span and propagates the caller's trace context, including unsampled contexts and tracestate. The Python SDK also emits no client span for signals; the JavaScript SDK emits asignal_entityPRODUCER span.Attributes:
durabletask.type=entity,durabletask.task.operation=call_entity|signal_entity(DurableTask.Core),durabletask.entity.operation=<operation name>(Python and JavaScript),durabletask.event.target_instance_id,durabletask.task.instance_id, and integerdurabletask.task.task_id(caller side),durabletask.task.instance_idanddurabletask.task.name(execution side),durabletask.task.scheduled_timefor scheduled requests, anddurabletask.entity.error_messageon failed executions. Entity names in span names are lowercased, matchingEntityID.String().Parity basis. Span names, kinds, and operation values follow DurableTask.Core's caller helper and execution helper. This is the Core dispatcher path; the durabletask-dotnet gRPC worker processes entity batches separately (batch processing, entity shim), and this change does not claim parity with that path. durabletask-python's worker emits similarly named execution spans with entity name and instance ID, but uses SERVER for both calls and signals; this change follows Core's CONSUMER kind for signals.
Limitations:
EntityResultTooLargeto a caller while the entity span still describes the successful handler result. No backend size limit is guessed and completion behavior is unchanged.Relates to #175.