Skip to content

Add opt-in client spans for scheduling orchestrations and raising events - #186

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

Tomer Rosenthal (torosent) merged 5 commits into
mainfrom
andystaples-tracing-client-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: f13bbbab9b2180b30376531205f3f86875c4ad30

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Tests cover client propagation, option failures, worker parentage, and single-use reconstructed span IDs.
↑ Disabled-tracing docs now match the unsampled propagation test.
↓ Current-head DTS emulator and race CI are queued.

Relates to #175. Stacked on #184.

Summary

Adds opt-in client-side OpenTelemetry spans that match durabletask-python and durabletask-dotnet:

Call Span name Kind Attributes
ScheduleNewOrchestration create_orchestration:<name> or create_orchestration:<name>@(<version>) PRODUCER durabletask.type=orchestration, durabletask.task.name, durabletask.task.instance_id, durabletask.task.version (when set), durabletask.task.execution_id (when known; not set by the current public scheduling options)
RaiseEvent orchestration_event:<event> PRODUCER durabletask.type=event, durabletask.task.name, durabletask.event.target_instance_id
  • Spans are children of the span in the call's context and use the shared Microsoft.DurableTask instrumentation scope.
  • When tracing is enabled, ScheduleNewOrchestration sends the PRODUCER span as the orchestration's parent trace context, so the worker's orchestration span (Add opt-in replay-aware OpenTelemetry spans (orchestration, activity, timer) #184) nests under it. Without a caller span, the PRODUCER span becomes the root of the trace. That context is sent even when the span is unsampled, which keeps the sampling decision and tracestate for downstream spans, like the other SDKs.
  • Failed calls, including request option validation, payload serialization, and payload externalization failures, record the error and set an error status.

API

  • client.WithTracerProvider(trace.TracerProvider) enables client spans. Any provider works, including otel.GetTracerProvider(); tracing.WithIDGenerator and tracing.WithSampler are needed only for worker tracing because client spans are live and never reconstructed. A provider configured for the worker can be shared with the client. A nil provider disables tracing.
  • durabletaskscheduler.NewClient now takes optional trailing client.TaskHubGrpcClientOption values for settings Options does not cover, such as client.WithTracerProvider. Data conversion, large payloads, and the default version should still be configured through Options; ScheduledTasks() always encodes with Options.DataConverter.
  • Without the option, no client spans are emitted; valid caller context, sampled or unsampled, is propagated when scheduling an orchestration.

The application keeps ownership of the provider (resource, sampler, processors, exporter, shutdown).

Not in this PR

Orchestration-side event send/receive spans and entity spans are planned for later layers of the stack.

@andystaples
andystaples force-pushed the andystaples-tracing-client-spans branch from dd1cc49 to f93799d Compare November 20, 2026 18:46
@andystaples
andystaples added this pull request to stack #194 November 23, 2026 17:09
@andystaples
andystaples force-pushed the andystaples-tracing-client-spans branch from f93799d to 33af269 Compare November 23, 2026 19:05
@andystaples
andystaples force-pushed the andystaples-tracing-client-spans branch from 33af269 to 6d87985 Compare November 30, 2026 19:52
@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.

🟡 Changes recommended

Scheduling validation and serialization failures, along with RaiseEvent payload serialization failures, return before tracing starts, leaving failed calls without error spans and requiring regression coverage.

2 open issues
What changed in this PR

Adds opt-in client-side OpenTelemetry tracing, extending the worker tracing from #184 toward the end-to-end visibility requested in #175.

Changes:

  • Adds PRODUCER spans for scheduling orchestrations and raising events, including propagation of unsampled orchestration parent contexts.
  • Exposes tracer configuration through trailing options on durabletaskscheduler.NewClient, while preserving default propagation-only behavior.
  • Adds tracing tests, API documentation, and a changelog entry.
File Description
tracing/​tracing.go Documents client tracing configuration and span behavior.
internal/​dttrace/​client.go Implements client span creation, attributes, and error recording.
durabletaskscheduler/​client.go Accepts trailing client options for tracing configuration.
durabletaskscheduler/​client_tracing_test.go Tests tracing options alongside scheduler version settings.
client/​client_grpc.go Instruments scheduling and event calls and propagates producer context.
client/​client_grpc_tracing_test.go Tests span metadata, failures, sampling, worker parentage, and disabled behavior.
CHANGELOG.md Announces client tracing and constructor options.

Review effort: Balanced

Comment thread client/client_grpc.go Resolved
Comment thread client/client_grpc.go Resolved
@andystaples
andystaples force-pushed the andystaples-tracing-client-spans branch from 6d87985 to 095de1f Compare November 30, 2026 22:45
Copilot AI balanced review requested due to automatic review settings November 30, 2026 22:45

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

The disabled-mode propagation description incorrectly omits valid unsampled contexts and tracestate, which the implementation preserves and the test explicitly verifies.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread client/client_grpc.go Resolved
@andystaples
andystaples force-pushed the andystaples-tracing-client-spans branch from 095de1f to cafe15f Compare November 30, 2026 23:25
Copilot AI balanced review requested due to automatic review settings November 30, 2026 23:25

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

There are no active review issues blocking approval of the opt-in client-side tracing changes.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 30, 2026 23:28

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 are reported for the opt-in OpenTelemetry client tracing changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Base automatically changed from andystaples-tracing-core-lifecycle to main December 1, 2026 00:12
andystaples and others added 5 commits November 30, 2026 16:12
Clarify that durabletaskscheduler.NewClient client options are for settings Options does not cover, document global and shared providers for client spans, cover payload externalization failures and constructor option forwarding, and add a changelog entry for client PRODUCER spans.

Co-authored-by: Copilot App <[email protected]>
Start the create-orchestration and raise-event PRODUCER spans before
applying request options so serialization and validation failures,
such as an unserializable payload or a reserved instance ID, are recorded
as span errors.

Co-authored-by: Copilot App <[email protected]>
Preserve unsampled caller propagation and verify it with standard and worker-compatible tracer providers. Cover request metadata on option failures.

Co-authored-by: Copilot App <[email protected]>
@torosent
Tomer Rosenthal (torosent) force-pushed the andystaples-tracing-client-spans branch from f13bbba to ec0f8b1 Compare December 1, 2026 00:12
@torosent
Tomer Rosenthal (torosent) requested a balanced review from Copilot December 1, 2026 00:46

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 review identifies no active issues in the opt-in client tracing changes.

No open issues 🎉

Review effort: Balanced

@torosent
Tomer Rosenthal (torosent) merged commit 3374f88 into main Dec 1, 2026
9 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 opt-in producer spans and disabled-mode propagation are in place. The main follow-ups are the constructor signature and keeping payload conversion consistent between direct and scheduled operations.

ctx context.Context,
options *Options,
logger api.Logger,
clientOptions ...durabletaskclient.TaskHubGrpcClientOption,

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.

Existing three-argument calls still compile, but callers that assign NewClient to a factory typed func(context.Context, *Options, api.Logger) (*Client, error) now fail to compile. Could we keep that signature and expose the tracer through a separate constructor or DTS options? If the signature change is intentional, please call out the source break in the release notes.

clientOptions = append(clientOptions, durabletaskclient.WithDefaultVersion(prepared.Versioning.DefaultVersion))
configuredOptions = append(configuredOptions, durabletaskclient.WithDefaultVersion(prepared.Versioning.DefaultVersion))
}
configuredOptions = append(configuredOptions, clientOptions...)

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.

Appending these options last lets client.WithDataConverter(B) override Options.DataConverter = A for direct operations, while ScheduledTasks() still encodes using A. One client can silently write two payload formats. Please use one effective converter for both paths, or keep the DTS-owned settings authoritative and reject conflicting options.

Comment thread client/client_grpc.go
var err error
var span trace.Span
if c.tracer != nil {
ctx, span = c.tracer.StartCreateOrchestration(ctx, req.Name, req.Version.GetValue(),

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 span starts after WithInput has already serialized the payload, unlike RaiseEvent. A slow converter can dominate the call without showing up in the scheduling span duration. Capture the start timestamp before applying options when tracing is enabled, then supply it once the final span name and attributes are known.

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