Skip to content

fix: activate activity trace context - #381

Merged
wangbill (YunchuWang) merged 1 commit into
mainfrom
yunchuwang-activate-activity-trace-context
Oct 7, 2026
Merged

wangbill (YunchuWang) merged 1 commit into
mainfrom
yunchuwang-activate-activity-trace-context

Conversation

@YunchuWang

@YunchuWang wangbill (YunchuWang) commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

What changed?

  • Run registered activity code with the Durable Task activity execution span as the active OpenTelemetry context.
  • Add worker-level coverage for child spans across awaits, concurrent activity isolation, success/error context restoration, failure status, and tracing-unavailable execution.
  • Add an Upcoming changelog entry.

Why is this change needed?

  • startSpanForTaskExecution() created the server span but did not make it active, so spans created by user activity code could become roots or inherit an unrelated ambient span.
  • This aligns JavaScript with the current .NET worker, which keeps its server activity current while awaiting user code, and with the .NET tracing tests that require user activity spans to be children of that server span:

Before: the Durable Task server span was emitted but not active during ActivityExecutor.execute().

After: only the awaited activity execution is scoped under that span. Existing parent extraction, span status/error handling, version-mismatch behavior, response delivery, tracing-unavailable behavior, and the single finally span end remain unchanged. There are no public API, protocol, backend, dependency, or orchestration execution changes.

Before / after trace

Both captures use the same activity workload and fixed synthetic IDs. startSpan() alone does not activate context; this PR scopes only ActivityExecutor.execute() under the Durable Task activity server span.

Before (PR base)

The user spans created before and after the async boundary are separate roots (parentSpanId: null) instead of children of the Durable Task activity server span 2222222222222222.

Before: user activity spans are roots rather than children of the Durable Task activity server span

After (PR head)

The same user spans both inherit parentSpanId: 2222222222222222 and remain on the Durable Task trace across the async boundary.

After: user activity spans are children of the Durable Task activity server span

Issues / work items

  • Resolves N/A
  • Related N/A

Project checklist

  • Release notes are not required for the next release
    • Otherwise: Notes added to CHANGELOG.md
  • Backport is not required
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • All required tests have been added/updated (unit tests, E2E tests)
  • Breaking change?
    • If yes:
      • Impact: N/A
      • Migration guidance: N/A

AI-assisted code disclosure (required)

Was an AI tool used? (select one)

  • No
  • Yes, AI helped write parts of this PR (e.g., GitHub Copilot)
  • Yes, an AI agent generated most of this PR

If AI was used:

  • Tool(s): GitHub Copilot coding agent
  • AI-assisted areas/files: Worker trace-context activation, tests, changelog, and PR description.
  • What you changed after AI output: The final diff was narrowed to the activity execution scope and unrelated formatting churn was removed.

AI verification (required if AI was used):

  • I understand the code and can explain it
  • I verified referenced APIs/types exist and are correct
  • I reviewed edge cases/failure paths (timeouts, retries, cancellation, exceptions)
  • I reviewed concurrency/async behavior
  • I checked for unintended breaking or behavior changes

Testing

Automated tests

  • Result: Passed locally on Windows with Node.js v24.14.0.
  • npm test -w @microsoft/durabletask-js -- --runTestsByPath test/tracing.spec.ts test/worker-tracing.spec.ts test/activity_executor.spec.ts test/worker-activity-response.spec.ts test/versioned-dispatch-grpc.spec.ts — 5 suites, 137 tests passed.
  • npm run build:core — passed.
  • npx eslint packages\durabletask-js\src\worker\task-hub-grpc-worker.ts packages\durabletask-js\test\worker-tracing.spec.ts — passed.
  • npx prettier --check CHANGELOG.md — passed.
  • npx prettier --check packages\durabletask-js\src\worker\task-hub-grpc-worker.ts --range-start 51884 --range-end 52371 — passed.
  • npx prettier --check packages\durabletask-js\test\worker-tracing.spec.ts --range-start 2027 --range-end 4207 — passed.
  • npx prettier --check packages\durabletask-js\test\worker-tracing.spec.ts --range-start 18630 --range-end 25026 — passed.
  • git diff --check — passed.
  • Hosted CI had not completed when this PR was opened.

Manual validation (only if runtime/behavior changed)

  • Environment (OS, Node.js version, components): Not run against a live sidecar. Automated tests use the real OpenTelemetry API, an async-local context manager, and the in-memory span exporter.
  • Steps + observed results:
    1. N/A
    2. N/A
  • Evidence (optional): TDD RED failed the three active-context assertions before the production change; the same focused file then passed 14/14 tests.

Notes for reviewers

  • Scope is intentionally limited to the gRPC worker activity executor call. No orchestration context behavior is changed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e0af01a5-0dfa-4e71-a660-c4186e65d7e0
Copilot AI balanced review requested due to automatic review settings October 6, 2026 15:53

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.

Copilot review overview

🟢 Approval recommended

The focused implementation correctly preserves activity trace context and is covered across key execution paths.

Review effort: Balanced
Findings: None

What changed in this PR

Activates the OpenTelemetry activity execution span while registered activity code runs.

Changes:

  • Scopes activity execution under its server span.
  • Adds async, concurrency, failure, restoration, and tracing-unavailable tests.
  • Documents the fix in the changelog.
File Description
task-hub-grpc-worker.ts Activates the activity span around user code.
worker-tracing.spec.ts Adds worker-level tracing coverage.
CHANGELOG.md Records the activity tracing fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/durabletask-js/src/worker/task-hub-grpc-worker.ts
@YunchuWang
wangbill (YunchuWang) merged commit d179585 into main Oct 7, 2026
31 checks passed
@YunchuWang
wangbill (YunchuWang) deleted the yunchuwang-activate-activity-trace-context branch October 7, 2026 16:41
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