fix(opentelemetry): sync resource name with OTel span name on SetName#4887
fix(opentelemetry): sync resource name with OTel span name on SetName#4887link04 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 4e2bd38 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-06-12 21:20:19 Comparing candidate commit 4e2bd38 in PR branch Found 0 performance improvements and 3 performance regressions! Performance is the same for 294 metrics, 2 unstable metrics, 1 flaky benchmarks without significant changes.
|
|
For maintainers, this same type of issue was discovered in dd-trace-js where the |
| s.attributes[ext.SpanName] = strings.ToLower(name) | ||
| // Keep the resource in sync with the renamed span: Start seeds the resource from the | ||
| // initial name, and the OTLP exporter emits the resource as the span's name field. | ||
| s.attributes[ext.ResourceName] = name |
There was a problem hiding this comment.
Yep this change looks correct. In the linked dd-trace-js PR, we replaced the previous "set the operation name" instruction with this new "set the resource name" instruction. Can we do the same here in dd-trace-go?
zacharycmontoya
left a comment
There was a problem hiding this comment.
LGTM. Let's see if we can replace the previous "operation name" update entirely since operation name is a DD-only concept
f892dc2 to
58392f8
Compare
…name on SetName
tracer.Start seeds the DD resource from the initial OTel span name, but SetName
only updated the operation name — so the resource (and therefore the span name
exported over OTLP) kept the stale value. Instrumentations such as otelhttp
create the span before routing ("GET") and call SetName with the low-cardinality
route afterwards ("GET /users/{id}"); the exported OTLP span name must follow.
SetName now updates the resource name only. The operation name is a Datadog-only
concept derived from the span's semantics, so it is no longer set from the OTel
span name (matching the dd-trace-js change).
Fixes the span name diverging from the pure OpenTelemetry SDK over OTLP.
Independent of DD_TRACE_OTEL_SEMANTICS_ENABLED.
APMAPI-2016
Co-Authored-By: Claude Opus 4.8 <[email protected]>
58392f8 to
4e2bd38
Compare
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenTelemetry bridge span renaming behavior so that calling Span.SetName(...) updates the underlying Datadog resource name (which is what ultimately maps to the OTLP-exported span name), rather than changing the Datadog operation name.
Changes:
- Update
(*span).SetNameto writeext.ResourceName(resource) instead ofext.SpanName(operation). - Adjust existing
TestSpanSetNameexpectations to validate resource rename behavior and unchanged DD-computed operation name. - Add a new regression test covering a common HTTP route-renaming scenario (e.g.,
"GET"→"GET /users/{id}").
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ddtrace/opentelemetry/span.go | Make SetName update Datadog resource name to keep OTLP span name in sync with OTel renames. |
| ddtrace/opentelemetry/span_test.go | Update assertions for the new mapping and add coverage for post-start span renames. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Superseded by #4889. Per the team discussion (and matching the dd-trace-js decision), the |
) ### What does this PR do? Adds an opt-in `DD_TRACE_OTEL_SEMANTICS_ENABLED` that aligns OTLP-exported spans (and the OTel bridge) with the pure OpenTelemetry SDK by suppressing Datadog-specific attributes and stopping DD-convention remaps. Mirrors dd-trace-py #18495 and libdatadog #2091. ### Behavior when `DD_TRACE_OTEL_SEMANTICS_ENABLED=true` - Omit `operation.name`, `resource.name`, `span.type` (DD-only span attributes) - Omit `error.message`/`type`/`stack`/`handling_stack` from the span (they live on the exception span event for Error Tracking) - Omit `span.kind` (already carried by the first-class OTLP `SpanKind` field) - Keep `http.response.status_code` under its OTel key instead of remapping to the legacy `http.status_code` string tag - The OTel bridge no longer interprets Datadog reserved tags (`operation.name`, `analytics.event`, `http.response.status_code`) in `SetAttributes` — they pass through as provided - `SetName` updates the Datadog **resource** (which the OTLP exporter emits as the span name) instead of the DD-only **operation name** Default (flag off) behavior is unchanged. ### Why `SetName` is gated here (moved from #4887) Changing `SetName` to update the resource is the correct OTel-aligned behavior, but doing it unconditionally is a breaking change: it shifts both the operation name **and** resource name, which changes users' RED metrics. Per team discussion (matching the dd-trace-js decision), this belongs behind the semantics flag rather than as a default change in a minor release. This supersedes #4887. ### Performance The flag is read **once** per export batch in `otlpTraceWriter.add()` and resolved **once** at provider creation for the bridge (cached on the `oteltracer`), then threaded as a parameter / read as a field — no per-span/per-attribute global config lookup. ### Testing `TestConvertSpanAttributesOtelSemantics`, `TestRemapStatusCodeOtelSemantics`, `TestToReservedAttributesOtelSemantics`, and `TestSpanSetNameUpdatesResourceOtelSemantics` (flag on) plus the existing `TestSpanSetName` (flag off, legacy operation-name behavior). Full `ddtrace/tracer`, `ddtrace/opentelemetry`, and `internal/config` suites pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: maximo.bautista <[email protected]>
What does this PR do?
Makes the OTel bridge's
SetNamealso update the Datadog resource name (not just the operation name), so the span name exported over OTLP follows a laterSetNamecall.Motivation
tracer.Startseeds the DD resource from the initial OTel span name, butSetNameonly updated the operation name — the resource (and thus the OTLP-exported span name) kept the stale value. Instrumentations likeotelhttpcreate the span before routing ("GET") and callSetNamewith the low-cardinality route afterwards ("GET /users/{id}"); the exported OTLP span name must follow to match the pure OpenTelemetry SDK.Independent of
DD_TRACE_OTEL_SEMANTICS_ENABLED.Testing
Adds
TestSpanSetNameUpdatesResource. Fullddtrace/opentelemetrysuite passes.APMAPI-2016
🤖 Generated with Claude Code