feat(sidecar): export session traces over OTLP via TraceExporter#2101
Draft
bm1549 wants to merge 2 commits into
Draft
feat(sidecar): export session traces over OTLP via TraceExporter#2101bm1549 wants to merge 2 commits into
bm1549 wants to merge 2 commits into
Conversation
Wire the sidecar trace path to libdatadog's OTLP HTTP/JSON TraceExporter so a session's traces can be exported to an OTLP endpoint instead of the agent msgpack /v0.4/traces path. Purely additive: sessions without an OTLP traces endpoint keep the existing agent path unchanged. - tracer::Config: add otlp_traces_endpoint/headers/timeout_ms and a set_otlp_traces_endpoint setter that stores the endpoint URL as-is (unlike set_endpoint, which rewrites the path for the agent). - SidecarInterface: new additive set_otlp_traces_config IPC method (session_id, Option<Endpoint>, headers, timeout). A None endpoint clears the config and restores the agent path. - sidecar_server: in send_trace_v04_bytes/_shm, route to OTLP when the session has an OTLP traces endpoint; otherwise keep the agent path. The OTLP TraceExporter is built lazily and cached per session (keyed by a config fingerprint) so the background /info worker is spawned once and reused, and rebuilt when the config changes. send() decodes v0.4, drops unsampled (p0) chunks, maps to OTLP using the session resource metadata, and POSTs. - SidecarSender/blocking: plumb the new IPC method. - New additive FFI ddog_sidecar_session_set_otlp_traces_endpoint(transport, session_id, *const Endpoint, headers, timeout_ms); does not change ddog_sidecar_session_set_config. Tests: tracer config setter and FFI header parser unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The sidecar OTLP traces path (`send_trace_otlp`) built the TraceExporter without env/app_version because the sidecar has no reliable session-level source for them — env/version arrive per-runtime via `set_universal_service_tags` and are dynamic per-trace. As a result the OTLP resource omitted `deployment.environment.name` and `service.version`. Derive these in the OTLP encoder as a fallback: when the exporter-level env/app_version are empty, recover them from the `env`/`version` meta tags carried on the exported trace's spans, preferring the chunk-root span. This is per-trace correct for the multi-service sidecar and purely additive — callers that set env/app_version at the exporter level (dd-trace-rs, dd-trace-py) are unaffected. Adds unit tests asserting the resource attributes appear from span meta, that exporter-level values take precedence, that the chunk root is preferred, and that the attributes stay omitted when neither source has a value. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 10, 2026
Contributor
📚 Documentation Check Results📦
|
Contributor
🔒 Cargo Deny Results📦
|
Contributor
Clippy Allow Annotation ReportComparing clippy allow annotations between branches:
Summary by Rule
Annotation Counts by File
Annotation Stats by Crate
About This ReportThis report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality. |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 53ed2e4 | Docs | Datadog PR Page | Give us feedback! |
Contributor
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a sidecar OTLP traces export path. Today the sidecar flushes traces as MessagePack v0.4 to the Datadog agent; libdatadog's OTLP
TraceExporterexisted but wasn't reachable from the sidecar. This PR (purely additive):otlp_traces_endpoint(+ headers/timeout) to the sidecar's per-session traceConfig;ddog_sidecar_session_set_otlp_traces_endpoint(...)(the existingddog_sidecar_session_set_configis unchanged);send_trace_v04_bytes/_shmto a per-session cached OTLPTraceExporterwhen an OTLP endpoint is set (itdrop_chunks()unsampled spans and encodes via the existingotlp_encoder), otherwise keeps the agent msgpack path byte-for-byte unchanged;otlp_encoderfill empty exporter-levelenv/app_versionresource attributes (deployment.environment.name/service.version) from the trace's span meta (chunk-root preferred), so the sidecar — which has no single session-level service — emits them correctly. This only triggers when exporter-level values are empty, so direct embedders (dd-trace-py / dd-trace-rs) are unaffected.Motivation
Enables OTLP trace export for sidecar-based SDKs (dd-trace-php) as part of the cross-language OTLP Traces Export effort (RFC "OTLP Traces Export 2026Q1", Phase 1). The OTLP
TraceExporteralready exists; this wires the sidecar's trace flush to use it.Additional Notes
Additive and gated: the default (no OTLP endpoint) path is unchanged. New unit tests cover the tracer config setter, the FFI header parser, and the encoder env/version fallback (precedence, root-span preference, omit-when-absent).
cargo check/cargo fmtclean on the changed crates; full workspace build/FFI tests run in CI.How to test the change?
Unit tests in
datadog-sidecar/datadog-sidecar-ffi/libdd-trace-utils. Integration is exercised by dd-trace-php (which bumps its submodule to this branch) and the system-testsTest_Otel_Tracing_OTLPPHP run.Related PRs (cross-language OTLP traces export — this PR is the merge-order gate for dd-trace-php):
Merge order: libdatadog #2101 → dd-trace-php #3971 (re-bump the submodule to the released libdatadog commit). system-tests #7121 validates rust/ruby/php once the tracer branches are available.
🤖 Generated with Claude Code