feat(otel): Enable improved OTel trace compatibility via opt-in configuration#18495
feat(otel): Enable improved OTel trace compatibility via opt-in configuration#18495zacharycmontoya wants to merge 26 commits into
Conversation
…LED.
When enabled, the tracer will not attempt to remap known OpenTelemetry attributes when handling OTEL spans and instead preserve them. A unit test has been added to assert that `otelspan.set_attribute("http.response.status_code", 200)` maintains both the original attribute key AND value (an integer)
…. Requires an updated libdatadog dependency as this is configured via a new interop call in the TraceExporterBuilder
…ontoya/otlp-compatibility-mode to consume the new native changes
…export Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ER=otlp Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ve span events Adds the _trace_native_span_events private field to the type stub for AgentConfig and adds a test case documenting that multi-exporter OTEL_TRACES_EXPORTER strings (e.g. "otlp,zipkin") intentionally do NOT trigger auto-enable, only the exact value "otlp" does. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…TRACES_EXPORTER=otlp
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… behaviors: - Do not set error tracking tags on the main span (they exist on the span event) - Add the attribute 'exception.stacktrace' to the exception span event
…here builtins is not included in the module name Note: This could be considered a breaking change as the signature of the error will be updated.
|
Codeowners resolved as |
BenchmarksBenchmark execution time: 2026-06-12 01:52:04 Comparing candidate commit c68a85b in PR branch Found 0 performance improvements and 4 performance regressions! Performance is the same for 613 metrics, 10 unstable metrics. scenario:httppropagationinject-ids_only
scenario:iastaspects-swapcase_aspect
scenario:iastaspectsospath-ospathbasename_aspect
scenario:span-start
|
| # We will not set the exception.stacktrace attribute, this will reduce the size of the span event | ||
| # https://github.com/open-telemetry/opentelemetry-python/blob/v1.25.0/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L1018 | ||
| module = type(exception).__module__ | ||
| qualname = type(exception).__qualname__ |
There was a problem hiding this comment.
Using __qualname__ is a semantic change from using __name__.
I think that __qualname__ is more accurate: it captures nested exception class names, but a change nevertheless.
I think we'd need someone with more Python experience to know the write answer here.
But leaving it as __name__ is always an option, to avoid changing behaviour.
There was a problem hiding this comment.
There was a problem hiding this comment.
I'm happy to keep the name update behind a feature flag, but I think we should update our tracer to write the fully qualified type name
…fix and the updated compatibility mode
| def enable_otel_trace_compatibility(self) -> TraceExporterBuilder: | ||
| """ | ||
| Enable OTel trace compatibility mode: omit DD-specific per-span attributes | ||
| (service.name, operation.name, resource.name, span.type) from the OTLP payload. |
There was a problem hiding this comment.
Is this an exhaustive list? I expect we'll add more values as we align more with otel sematnics.
| (service.name, operation.name, resource.name, span.type) from the OTLP payload. | |
| (ex: service.name, operation.name, resource.name, span.type) from the OTLP payload. |
There was a problem hiding this comment.
This should almost be exhaustive. In my testing at https://github.com/DataDog/evalya/pull/767 this almost fully aligns FastAPI spans when using the OTel instrumentation, so if there are any further attributes that need to be modified then I expect they will be small in number
| @@ -0,0 +1,71 @@ | |||
| # Design: Suppress DD error tags in `record_exception` when OTel compatibility mode is enabled | |||
There was a problem hiding this comment.
Are these doc changes intentional?
There was a problem hiding this comment.
No, I'll remove the docs file changes
…ed on the OTel span kind
a6560fb to
a2d179a
Compare
10a9453 to
3869cc9
Compare
Description
This PR adds a configuration to process spans as closely as possible to the OTel SDK. The result is that using OpenTelemetry Tracing instrumentations allows DD SDKs to produce OTLP spans with nearly identical span fields.
When enabled, this updates the dd-trace-py behavior in the following ways:
enable_otel_trace_semantics()(see the related libdatadog PR for specific attribute changes)OtelSpan.set_attributeno longer remaps span tags such ashttp.response.status_codeorservice.nameso they will maintain their intended key and value typeOtelSpan.record_exceptionno longer sets span attributeserror.message,error.type, orerror.stack. These exist on theexceptionspan event and will be recognized by Error TrackingOtelSpan.record_exceptionsets the attributeexception.stacktraceon theexceptionspan event to align with OpenTelemetryspan.kindThis PR also enables native span events when OTLP traces export is enabled via
OTEL_TRACES_EXPORTER=otlpbecause OTLP spans have a first-classeventsfield.Relies on DataDog/libdatadog#2091 to implement the OTLP trace exporter changes
// TODO: Fix the exception.type change so it only applies when the OTel compatibility mode is enabled
Testing
Unit tests are included for the updated OTel test span behavior and the native span events configuration
Risks
Besides the native span events change, the remaining changes are opt-in so the risk is low.
Additional Notes
Currently the libdatadog dependency is set to a development branch which contains the updated
TraceExporterBuilder::enable_otel_trace_semantics()API