Skip to content

Add replay-aware entity tracing - #192

Merged
Tomer Rosenthal (torosent) merged 4 commits into
mainfrom
andystaples-tracing-entity-spans
Dec 1, 2026
Merged

Tomer Rosenthal (torosent) merged 4 commits into
mainfrom
andystaples-tracing-entity-spans

Conversation

@andystaples

@andystaples andystaples commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 78815aba6e3c14e2ec8c8b83c7a5cc48d835a335

Dimension Assessment Rationale
Change confidence 9/10 ↑ Regression tests cover replay, reserved sampling results, processor-ID isolation, and backend-rewritten results.
↑ 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.DurableTask instrumentation scope.

  • Entity execution (worker): each operation in a V2 batch gets one span, 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 after CompleteEntityTask is 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.
  • Trace context on entity-started work: SendSignal and StartNewOrchestration operation actions produced by an operation carry the operation's span context as ParentTraceContext (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.
  • Status: successful operations leave the span status unset, like the other Go worker spans. Failed operations and worker-observed batch failures (including payload hydration and externalization errors) set an error status with the failure message and add durabletask.entity.error_message.
  • Orchestration-initiated calls and signals: calls emit CLIENT spans when a new completion or failure is consumed, including completions consumed beyond a turn's event budget or while suspended, each exported once. Signals emit PRODUCER spans with the accepted response that first carries them, following the same replay and acknowledgement rules as SendEvent in 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.
  • Entity locks: lock acquisition and release emit no spans, matching DurableTask.Core. Calls made inside a critical section are traced normally.
  • Client 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 a signal_entity PRODUCER 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 integer durabletask.task.task_id (caller side), durabletask.task.instance_id and durabletask.task.name (execution side), durabletask.task.scheduled_time for scheduled requests, and durabletask.entity.error_message on failed executions. Entity names in span names are lowercased, matching EntityID.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:

  • The V2 entity messages in this protocol version carry no trace context. Entity execution spans are therefore independent roots sampled by the provider's root policy, not children of, or linked to, the orchestration or client spans that sent them. Their IDs come from the base ID generator. No protocol fields are added.
  • The operation span is not live while the handler runs. Handlers see its reserved identity, but it is exported only after the batch completion is accepted, so application spans from a batch that is later rejected or abandoned can reference a parent that is never exported.
  • Entity span status describes the worker-observed result. If the backend replaces an acknowledged batch result, the empty completion response does not expose that replacement. For example, the in-memory backend can report EntityResultTooLarge to a caller while the entity span still describes the successful handler result. No backend size limit is guessed and completion behavior is unchanged.
  • Tracing remains disabled by default; with it disabled, entity contexts and operation actions are unchanged. Replay suppression is best effort rather than exactly-once telemetry.

Relates to #175.

@andystaples
andystaples force-pushed the andystaples-tracing-entity-spans branch from ec9f60e to 32eeb80 Compare November 20, 2026 19:11
@andystaples andystaples changed the title Add replay-aware entity spans with DurableTask.Core semantics Add replay-aware entity tracing for executions, orchestration calls/signals, and client signals Nov 20, 2026
@andystaples andystaples changed the title Add replay-aware entity tracing for executions, orchestration calls/signals, and client signals Add replay-aware entity tracing Nov 20, 2026
@andystaples
andystaples force-pushed the andystaples-tracing-entity-spans branch from 9d730dd to 85cb1d9 Compare November 20, 2026 20:15
@andystaples
andystaples added this pull request to stack #194 November 23, 2026 17:09
@andystaples
andystaples force-pushed the andystaples-tracing-entity-spans branch from 85cb1d9 to 18730c9 Compare November 23, 2026 19:43
@andystaples
andystaples force-pushed the andystaples-tracing-entity-spans branch from 18730c9 to 941820f Compare November 30, 2026 20:10
@andystaples
andystaples marked this pull request as ready for review November 30, 2026 20:20
Copilot AI balanced review requested due to automatic review settings November 30, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread internal/dttrace/entity.go Resolved
@andystaples
andystaples force-pushed the andystaples-tracing-entity-spans branch from 941820f to 78815ab Compare November 30, 2026 23:38
Copilot AI balanced review requested due to automatic review settings November 30, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The opt-in entity tracing changes have no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:12
@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-entity-spans branch from 78815ab to 2906ce7 Compare December 1, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the opt-in entity tracing changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the opt-in entity tracing changes.

No open issues 🎉

Review effort: Balanced

@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-entity-spans branch from 2906ce7 to 42156f7 Compare December 1, 2026 04:05
Base automatically changed from andystaples-tracing-orchestration-events to main December 1, 2026 04:25
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]>
@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-entity-spans branch from 42156f7 to c744bfc Compare December 1, 2026 04:25
@torosent
Tomer Rosenthal (torosent) merged commit f5eb5bb into main Dec 1, 2026
9 of 10 checks passed

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread task/executor.go
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread task/entity.go
Input: rawInput,
RequestTime: timestampOrNil(ctx.currentTime),
ScheduledTime: timestampOrNil(scheduledTime),
ParentTraceContext: helpers.TraceContextFromSpanContext(ctx.spanContext),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants