fix(opentelemetry): apply global/resource tags to OTel-bridged spans#9229
Conversation
OTEL_RESOURCE_ATTRIBUTES and DD_TAGS are parsed into config.tags but were only applied to spans created via the native tracer (opentracing/tracer.js). Spans created through the OTel API bridge were built directly with only service/resource/span.kind, so global/resource tags never reached them — documented opt-outs like OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false had no effect on OTel-bridged spans. Seed the bridge span's tags with config.tags as defaults, keeping explicit service/resource/span.kind and user-set attributes as overrides, matching the native path's precedence.
Overall package sizeSelf size: 6.56 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.0 | 117.14 kB | 432.47 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 2315268 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-07 00:46:34 Comparing candidate commit 2315268 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2257 metrics, 29 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9229 +/- ##
==========================================
+ Coverage 93.56% 93.61% +0.05%
==========================================
Files 900 900
Lines 52690 52690
Branches 12411 12411
==========================================
+ Hits 49299 49328 +29
+ Misses 3391 3362 -29 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ZStriker19
left a comment
There was a problem hiding this comment.
This looks good to me as a way to meet the need of supporting OTEL_RESOURCE_ATTRIBUTES without overriding the bridge's reserved values. Nice job!
…9229) OTEL_RESOURCE_ATTRIBUTES and DD_TAGS are parsed into config.tags but were only applied to spans created via the native tracer (opentracing/tracer.js). Spans created through the OTel API bridge were built directly with only service/resource/span.kind, so global/resource tags never reached them — documented opt-outs like OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false had no effect on OTel-bridged spans. Seed the bridge span's tags with config.tags as defaults, keeping explicit service/resource/span.kind and user-set attributes as overrides, matching the native path's precedence.
…9229) OTEL_RESOURCE_ATTRIBUTES and DD_TAGS are parsed into config.tags but were only applied to spans created via the native tracer (opentracing/tracer.js). Spans created through the OTel API bridge were built directly with only service/resource/span.kind, so global/resource tags never reached them — documented opt-outs like OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false had no effect on OTel-bridged spans. Seed the bridge span's tags with config.tags as defaults, keeping explicit service/resource/span.kind and user-set attributes as overrides, matching the native path's precedence.
BridgeAR
left a comment
There was a problem hiding this comment.
The fix itself will work, I just think we should do it in a way where we do not have to copy these on each span, since that adds a lot of CPU overhead :) I will open a follow-up for that
…9229) OTEL_RESOURCE_ATTRIBUTES and DD_TAGS are parsed into config.tags but were only applied to spans created via the native tracer (opentracing/tracer.js). Spans created through the OTel API bridge were built directly with only service/resource/span.kind, so global/resource tags never reached them — documented opt-outs like OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false had no effect on OTel-bridged spans. Seed the bridge span's tags with config.tags as defaults, keeping explicit service/resource/span.kind and user-set attributes as overrides, matching the native path's precedence.
…9229) OTEL_RESOURCE_ATTRIBUTES and DD_TAGS are parsed into config.tags but were only applied to spans created via the native tracer (opentracing/tracer.js). Spans created through the OTel API bridge were built directly with only service/resource/span.kind, so global/resource tags never reached them — documented opt-outs like OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false had no effect on OTel-bridged spans. Seed the bridge span's tags with config.tags as defaults, keeping explicit service/resource/span.kind and user-set attributes as overrides, matching the native path's precedence.
What does this PR do?
Applies global/resource tags (
DD_TAGS,OTEL_RESOURCE_ATTRIBUTES) to spans created through the OpenTelemetry API bridge (DD_TRACE_OTEL_ENABLED=true).Motivation
OTEL_RESOURCE_ATTRIBUTESandDD_TAGSare parsed intoconfig.tags, but they were only applied to spans created via the native tracer (opentracing/tracer.js→span.addTags(this._config.tags)). Spans created through the OTel API bridge (opentelemetry/span.js) were constructed directly with onlyservice/resource/span.kind, so global/resource tags never reached them.As a result, documented opt-outs that rely on a resource attribute reaching the span — e.g.
OTEL_RESOURCE_ATTRIBUTES=dd_llmobs_enabled=false— had no effect on OTel-bridged spans, even though the value was correctly present in the tracer config.Change
Seed the bridge span's tags with
config.tagsas defaults, keeping the explicitservice/resource/span.kindand any user-set OTel attributes as overrides — matching the precedence of the native path.Testing
Added unit tests in
packages/dd-trace/test/opentelemetry/span.spec.js:DD_TAGS/OTEL_RESOURCE_ATTRIBUTES) are applied to bridged spans (fails without this change)service.name/resource.name/span.kindwin over colliding config tags (fails if the spread order is reversed)The full
packages/dd-trace/test/opentelemetry/suite passes.Internal reference: MLOB-7714
🤖 Generated with Claude Code