Skip to content

Trace orchestration event sends (replay-aware PRODUCER spans) - #189

Merged
Tomer Rosenthal (torosent) merged 5 commits into
mainfrom
andystaples-tracing-orchestration-events
Dec 1, 2026
Merged

Tomer Rosenthal (torosent) merged 5 commits into
mainfrom
andystaples-tracing-orchestration-events

Conversation

@andystaples

@andystaples andystaples commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 1efe9b9d411c492ce3593c879ef8895dea5e57c7

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Tests cover replay, deferred acknowledgements, suspended buffering, and response acceptance; full tests, vet and pinned lint pass after rebase.
↑ CI-pinned DTS emulator tests pass; prior event-budget experiment delivered one event and exported one event span without reissuing the send.
↓ Hosted DTS behavior remains unverified.

Part of #175. Stacked on #186.

Summary

When opt-in tracing is enabled, OrchestrationContext.SendEvent now produces an orchestration_event:<event name> PRODUCER span under the sending orchestration's span, matching the event spans emitted by durabletask-python (emit_event_raised_span) and durabletask-dotnet.

Attributes: durabletask.type=event, durabletask.task.name, durabletask.task.instance_id, durabletask.task.execution_id (when known) and durabletask.event.target_instance_id.

Replay semantics

  • Spans are exported only with an accepted orchestrator response; abandoned or discarded dispatches export nothing.
  • Sends replayed from history, and later EventSent acknowledgements of sends from earlier dispatches, emit nothing.
  • A new send whose EventSent history is matched in the same dispatch is exported with that dispatch.
  • Suspended-event buffering and per-turn event budgets are respected because spans follow the actions actually produced and processed by the replay engine.
  • Orchestrations scheduled without trace context root a new trace, and their event spans nest under that root. Behavior is unchanged when tracing is disabled or the orchestration is unsampled.

Limitations

  • Export is best effort, not exactly once: a completion the backend retries may export its event spans again.
  • No CONSUMER span is emitted on event receipt. EventRaised/EventSent carry no trace context in the protocol, so a send cannot parent or link the receiving orchestration to the sender's event span.

Tests

client/grpc_worker_tracing_test.go covers normal send, replay/redelivery, same-batch history matches, suspended buffering with turn budgets, disabled tracing, unsampled and missing context, continue-as-new in the same turn, and discarded or rejected dispatches.

@andystaples
andystaples force-pushed the andystaples-tracing-orchestration-events branch from 0ca9657 to cc5edf3 Compare November 20, 2026 18:52
@andystaples
andystaples added this pull request to stack #194 November 23, 2026 17:09
@andystaples
andystaples force-pushed the andystaples-tracing-orchestration-events branch from 8af3ddf to 6506b55 Compare November 23, 2026 19:22
@andystaples
andystaples force-pushed the andystaples-tracing-orchestration-events branch from 6506b55 to b9203dc Compare November 30, 2026 20:04
@andystaples
andystaples marked this pull request as ready for review November 30, 2026 20:19
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.

🔵 Needs a closer look

Replay suppression relies on DTS deduplicating reissued SendEvent actions when turn limits leave acknowledgements unconsumed, but the fake backend assumes this behavior and service-level validation is still needed.

No open issues 🎉

What changed in this PR

Extends opt-in worker tracing with replay-aware OrchestrationContext.SendEvent PRODUCER spans, building on client tracing toward broader orchestration lifecycle visibility.

Changes:

  • Adds event-send spans under the sending orchestration, exported after response acceptance with replay and acknowledgement suppression.
  • Adds tests for span parentage, replay, turn budgets, suspension, sampling, continue-as-new, and rejected or discarded sends.
  • Documents best-effort export and the protocol limitation that prevents correlated event-receipt spans.
File Description
tracing/​tracing.go Documents event-send span semantics and receipt limitations.
task/​orchestrator.go Records sends and confirms validated history acknowledgements.
internal/​dttrace/​dttrace.go Tracks send spans and exports them with accepted responses.
client/​grpc_worker_tracing_test.go Adds event-tracing coverage across replay and completion scenarios.
client/​grpc_worker_test.go Allows the fake scheduler to reject orchestration completions.
CHANGELOG.md Announces opt-in orchestration event-send tracing.

Review effort: Balanced

@andystaples
andystaples force-pushed the andystaples-tracing-orchestration-events branch from b9203dc to f1b0b8c Compare November 30, 2026 22:52
Copilot AI balanced review requested due to automatic review settings November 30, 2026 22:52
@andystaples

Copy link
Copy Markdown
Contributor Author

On the review overview's point about reissued SendEvent actions when the turn budget leaves acknowledgements unconsumed: no backend deduplication is assumed.

The Durable Task Scheduler commits EventSent to history in the same completion that accepts the send. Later work items receive it as a past event, and replay does not count against MaxEventsPerTurn, so the acknowledgement is never deferred and the send is not reissued. On the CI-pinned DTS emulator, a sender with MaxEventsPerTurn=1 and several queued unrelated events always had EventSent in past events. Its responses never repeated the send, the target received one event, and one orchestration_event span was exported. This has not been checked against the hosted service.

The acknowledgement-based suppression is defensive. It covers backends that deliver EventSent as a new event, which is what the fake-backend regression test models. The comments now say this rather than claiming the backend deduplicates.

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 replay-aware orchestration event-send tracing changes.

No open issues 🎉

Review effort: Balanced

@andystaples
andystaples force-pushed the andystaples-tracing-orchestration-events branch from f1b0b8c to 1efe9b9 Compare November 30, 2026 23:32
Copilot AI balanced review requested due to automatic review settings November 30, 2026 23:32

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 orchestration event-send tracing change.

No open issues 🎉

Review effort: Balanced

@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-orchestration-events branch from 1efe9b9 to efff3ea Compare December 1, 2026 00:12
Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:12

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 event-send tracing change.

No open issues 🎉

Review effort: Balanced

Base automatically changed from andystaples-tracing-client-spans to main December 1, 2026 04:05
andystaples and others added 4 commits November 30, 2026 20:05
Document the send span decision table, stamp fallback send spans when the response is prepared, make repeated Emit and late RecordSendEvent calls safe, cover rejected completions and same-turn continue-as-new, and add a changelog entry.

Co-authored-by: Copilot App <[email protected]>
@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-orchestration-events branch from efff3ea to d51cdfc Compare December 1, 2026 04:05
@torosent
Tomer Rosenthal (torosent) merged commit 62578c0 into main Dec 1, 2026
14 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: The normal DTS path emits the producer span after the response is accepted and leaves the wire format unchanged. Two follow-ups: bound the per-dispatch history index, and cover a first send released by resume when its acknowledgement is in the same dispatch.

if event.GetEventSent() != nil {
if o.acceptedSends == nil {
o.acceptedSends = make(map[int32]struct{})
}

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.

This rebuilds a map from all historical EventSent IDs on every traced dispatch, even if the response carries no send or the parent is unsampled. In an isolated StartOrchestration benchmark with 10,000 events, send history took about 0.88 ms and 305 KB/op, versus 0.05 ms and 944 B/op for equally long non-send history. Can we build the lookup only when the response has unmatched send candidates, while still checking deferred and suspended acknowledgements?

}
sent := action.GetSendEvent()
o.newSends[action.Id] = o.eventSpan(sent.GetName(), sent.GetInstance().GetInstanceId(), time.Now())
}

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.

A fake-backend regression test found a gap: buffer a trigger while suspended, then deliver ExecutionResumed and a matching new EventSent in one request. The buffered trigger still has IsReplaying=true, so its first send is not recorded here; the acknowledgement then removes it from the final action list, leaving no producer span. This was not reproduced on DTS. If same-dispatch acknowledgement is supported, distinguish first execution after resume from replay and add this case; otherwise narrow the documented guarantee.

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