Skip to content

feat: propagate caller trace context when scheduling workflows#1783

Open
javier-aliaga wants to merge 2 commits into
dapr:masterfrom
javier-aliaga:fix/tracing-propagation-workflow-client
Open

feat: propagate caller trace context when scheduling workflows#1783
javier-aliaga wants to merge 2 commits into
dapr:masterfrom
javier-aliaga:fix/tracing-propagation-workflow-client

Conversation

@javier-aliaga

Copy link
Copy Markdown
Contributor

Upstream half of workflow trace propagation (follow-up to #1619).

DaprWorkflowClient gains a DaprWorkflowClient(Properties, Tracer) constructor that passes the tracer to the internal DurableTaskGrpcClientBuilder. DurableTaskGrpcClient now uses the configured tracer when scheduling: it emits a create_orchestration CLIENT span as a child of the caller's current OpenTelemetry context and stamps its W3C trace context into
CreateInstanceRequest.parentTraceContext, so the workflow execution nests under the caller's trace instead of starting a separate one.

Tracing stays opt-in: without a tracer the request is unchanged and no spans are emitted. The unused GlobalOpenTelemetry fallback is removed so the global instance is never pulled implicitly.

Description

Please explain the changes you've made

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Upstream half of workflow trace propagation (follow-up to dapr#1619).

DaprWorkflowClient gains a DaprWorkflowClient(Properties, Tracer)
constructor that passes the tracer to the internal
DurableTaskGrpcClientBuilder. DurableTaskGrpcClient now uses the
configured tracer when scheduling: it emits a create_orchestration
CLIENT span as a child of the caller's current OpenTelemetry context
and stamps its W3C trace context into
CreateInstanceRequest.parentTraceContext, so the workflow execution
nests under the caller's trace instead of starting a separate one.

Tracing stays opt-in: without a tracer the request is unchanged and no
spans are emitted. The unused GlobalOpenTelemetry fallback is removed
so the global instance is never pulled implicitly.

Signed-off-by: Javier Aliaga <javier@diagrid.io>

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.

Pull request overview

This PR adds opt-in OpenTelemetry trace propagation when scheduling workflows so that workflow executions can be nested under the caller’s active trace context (instead of starting a separate trace), while preserving legacy behavior when no tracer is configured.

Changes:

  • Add a new DaprWorkflowClient(Properties, Tracer) constructor and pass the tracer into the underlying DurableTaskGrpcClientBuilder.
  • Update DurableTaskGrpcClient scheduling to emit a create_orchestration CLIENT span and populate CreateInstanceRequest.parentTraceContext with W3C trace context (when a tracer is configured).
  • Add tests covering tracer propagation behavior (including no-op tracer) and update module dependencies accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk-workflows/src/test/java/io/dapr/workflows/client/DaprWorkflowClientTest.java Adds unit tests verifying tracer forwarding to DurableTaskGrpcClientBuilder and null-tracer behavior.
sdk-workflows/src/main/java/io/dapr/workflows/client/DaprWorkflowClient.java Introduces Properties, Tracer constructor and threads tracer into durable task client construction.
sdk-workflows/pom.xml Adds opentelemetry-api dependency needed for the public Tracer type.
durabletask-client/src/test/java/io/dapr/durabletask/DurableTaskGrpcClientTracingTest.java Adds in-process gRPC test validating parentTraceContext propagation and no-op tracer behavior.
durabletask-client/src/main/java/io/dapr/durabletask/DurableTaskGrpcClient.java Implements span creation + W3C trace context injection into scheduling request; removes implicit GlobalOpenTelemetry fallback.
durabletask-client/pom.xml Adds opentelemetry-sdk test dependency to support tracer provider usage in tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread durabletask-client/src/main/java/io/dapr/durabletask/DurableTaskGrpcClient.java Outdated
…eptions

Addresses review feedback: the create_orchestration span is now current
while the sidecar call runs, so nested instrumentation attaches to it,
and failures record the exception on the span in addition to the error
status.

Signed-off-by: Javier Aliaga <javier@diagrid.io>

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@javier-aliaga javier-aliaga marked this pull request as ready for review July 7, 2026 08:52
@javier-aliaga javier-aliaga requested review from a team as code owners July 7, 2026 08:52
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.90%. Comparing base (79d9812) to head (614728a).

Files with missing lines Patch % Lines
...a/io/dapr/workflows/client/DaprWorkflowClient.java 90.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1783      +/-   ##
============================================
+ Coverage     76.89%   76.90%   +0.01%     
- Complexity     2307     2309       +2     
============================================
  Files           244      244              
  Lines          7163     7167       +4     
  Branches        753      754       +1     
============================================
+ Hits           5508     5512       +4     
  Misses         1288     1288              
  Partials        367      367              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if (this.tracer != null) {
span = this.tracer.spanBuilder("create_orchestration:" + orchestratorName)
.setSpanKind(SpanKind.CLIENT)
.setAttribute("durabletask.type", "orchestration")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@javier-aliaga this is confusing already.. why DurableTask here? can you not make it "workflow."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we still have durabletask.* all around the place

Comment thread durabletask-client/pom.xml
Comment thread sdk-workflows/pom.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants