Skip to content

Fix: Update Opentelemety Active Functionality#7319

Merged
bojbrook merged 3 commits intomasterfrom
bojbrook/otel-context_manager
Feb 2, 2026
Merged

Fix: Update Opentelemety Active Functionality#7319
bojbrook merged 3 commits intomasterfrom
bojbrook/otel-context_manager

Conversation

@bojbrook
Copy link
Copy Markdown
Contributor

What does this PR do?

This PR refactors the context manager’s active() method to improve context handling between Datadog and OpenTelemetry and to fix edge cases when converting between Datadog and OpenTelemetry spans.

Motivation

This issue was reported in APMS-18328 and can be reproduced with the code below. The core problem is that retrieving and setting the active span works as expected when using the Datadog API, but fails silently when performed through the OpenTelemetry API.

function enrichSpan() {
    const ddSpan = ddTrace.scope().active();
    const otelSpan = trace.getActiveSpan();
    // 1. OTel Attempt: SILENT FAILURE
    otelSpan?.setAttribute('my.otel.attr', 'failed');

    // 2. Datadog Attempt: SUCCESS
    ddSpan?.addTags({ 'my.dd.attr': 'success' });
}

function main() {
    otelTracer.startActiveSpan('otel-span', async (span) => {
        enrichSpan();
        await sleep(1000);
        span.end();
    });

    console.log('Ending main function');
}

main();

Expected result: For this scenario we would expect both tags(attributes) to be present on the same span.

Plugin Checklist

Additional Notes

@bojbrook bojbrook requested a review from a team as a code owner January 22, 2026 20:41
@bojbrook bojbrook requested review from khanayan123 and removed request for a team January 22, 2026 20:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 22, 2026

Overall package size

Self size: 4.5 MB
Deduped: 5.33 MB
No deduping: 5.33 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.3 | 76.87 kB | 808.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (4a8a494) to head (8b9d3f9).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...ages/dd-trace/src/opentelemetry/context_manager.js 94.44% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7319      +/-   ##
==========================================
- Coverage   85.86%   85.84%   -0.02%     
==========================================
  Files         518      518              
  Lines       22375    22387      +12     
==========================================
+ Hits        19212    19219       +7     
- Misses       3163     3168       +5     
Flag Coverage Δ
aiguard-macos 99.09% <ø> (ø)
aiguard-ubuntu 99.09% <ø> (ø)
aiguard-windows 99.09% <ø> (ø)
apm-capabilities-tracing-macos 57.66% <94.44%> (+<0.01%) ⬆️
apm-capabilities-tracing-ubuntu 57.66% <94.44%> (+<0.01%) ⬆️
apm-capabilities-tracing-windows 57.28% <94.44%> (+0.01%) ⬆️
apm-integrations-child-process 99.19% <ø> (ø)
apm-integrations-couchbase-18 100.00% <ø> (ø)
apm-integrations-couchbase-eol 100.00% <ø> (ø)
appsec-express 62.54% <ø> (ø)
appsec-fastify 58.55% <ø> (ø)
appsec-graphql 53.40% <ø> (ø)
appsec-kafka 43.98% <ø> (ø)
appsec-ldapjs 46.04% <ø> (ø)
appsec-lodash 47.29% <ø> (ø)
appsec-macos 93.76% <ø> (ø)
appsec-mongodb-core 51.82% <ø> (ø)
appsec-mongoose 50.73% <ø> (ø)
appsec-mysql 54.16% <ø> (ø)
appsec-node-serialize 43.92% <ø> (ø)
appsec-passport 48.07% <ø> (ø)
appsec-postgres 54.51% <ø> (ø)
appsec-sourcing 33.80% <ø> (ø)
appsec-template 43.92% <ø> (ø)
appsec-ubuntu 93.76% <ø> (ø)
appsec-windows 93.76% <ø> (ø)
llmobs-ai 52.09% <ø> (ø)
llmobs-anthropic 42.73% <ø> (ø)
llmobs-bedrock 40.06% <ø> (ø)
llmobs-google-genai 45.89% <ø> (ø)
llmobs-langchain 50.15% <ø> (ø)
llmobs-openai 55.62% <ø> (ø)
llmobs-vertex-ai 44.48% <ø> (ø)
platform-core 87.23% <ø> (ø)
platform-instrumentations-misc 89.16% <ø> (ø)
platform-shimmer 98.80% <ø> (ø)
platform-unit-guardrails 89.47% <ø> (ø)
profiling-macos 70.74% <ø> (ø)
profiling-ubuntu 70.74% <ø> (ø)
profiling-windows 74.23% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bojbrook bojbrook force-pushed the bojbrook/otel-context_manager branch from d90db71 to 48c1ecd Compare January 23, 2026 16:12
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Jan 23, 2026

Benchmarks

Benchmark execution time: 2026-02-01 17:46:04

Comparing candidate commit 8b9d3f9 in PR branch bojbrook/otel-context_manager with baseline commit 4a8a494 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 233 metrics, 27 unstable metrics.

return propagation.setBaggage(store, otelBaggages)
}
return context
return store
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.

Isn't active supposed to always return a context? Or is a context also a plain object similar to a store so a store can be used in-place?

Copy link
Copy Markdown
Member

@rochdev rochdev left a comment

Choose a reason for hiding this comment

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

Just a non-blocking question but otherwise LGTM.

@bojbrook bojbrook force-pushed the bojbrook/otel-context_manager branch from 48c1ecd to ffe4213 Compare January 28, 2026 17:06
@datadog-official

This comment has been minimized.

@bojbrook
Copy link
Copy Markdown
Contributor Author

bojbrook commented Feb 2, 2026

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 bot commented Feb 2, 2026

View all feedbacks in Devflow UI.

2026-02-02 16:15:26 UTC ℹ️ Start processing command /merge


2026-02-02 16:15:32 UTC ℹ️ MergeQueue: queue is disabled

Added to the queue but the mergequeue is not enabled for now.


2026-02-02 16:18:10 UTC ⚠️ MergeQueue: This merge request was unqueued

[email protected] unqueued this merge request

@bojbrook
Copy link
Copy Markdown
Contributor Author

bojbrook commented Feb 2, 2026

/remove

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 bot commented Feb 2, 2026

View all feedbacks in Devflow UI.

2026-02-02 16:17:53 UTC ℹ️ Start processing command /remove


2026-02-02 16:17:57 UTC ℹ️ Devflow: /remove

@bojbrook bojbrook merged commit 60565f1 into master Feb 2, 2026
791 of 792 checks passed
@bojbrook bojbrook deleted the bojbrook/otel-context_manager branch February 2, 2026 16:18
dd-octo-sts bot pushed a commit that referenced this pull request Feb 3, 2026
* update active function

* comments

---------

Co-authored-by: Thomas Watson <[email protected]>
@dd-octo-sts dd-octo-sts bot mentioned this pull request Feb 3, 2026
BridgeAR pushed a commit that referenced this pull request Feb 5, 2026
* update active function

* comments

---------

Co-authored-by: Thomas Watson <[email protected]>
bm1549 pushed a commit that referenced this pull request Feb 10, 2026
* update active function

* comments

---------

Co-authored-by: Thomas Watson <[email protected]>
BridgeAR pushed a commit that referenced this pull request Feb 22, 2026
* update active function

* comments

---------

Co-authored-by: Thomas Watson <[email protected]>
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