Skip to content

fix(pipeline): set OTLP instrumentation scope#173

Open
bengl wants to merge 4 commits into
mainfrom
bengl/otlp-scope-metadata-main
Open

fix(pipeline): set OTLP instrumentation scope#173
bengl wants to merge 4 commits into
mainfrom
bengl/otlp-scope-metadata-main

Conversation

@bengl

@bengl bengl commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

What

Sets the native OTLP instrumentation scope for pipeline trace exports.

The pipeline builder now passes dd-trace-js and the tracer version into libdatadog’s OTLP scope metadata. The OTLP HTTP test asserts the emitted JSON payload contains both scope.name and scope.version.

This also updates the temporary libdatadog git dependency to the amended DataDog/libdatadog#2235 head (8cd68ab922fb7aade0f089ccfc91291d874673af) and adapts the WASM stats wrapper to libdd-trace-stats 6.0.0’s FlushResult API.

The stats flush wrapper now returns { sent, collapsedSpans }, carrying FlushResult.collapsed_spans through the WASM boundary so downstream JS can emit the same collapsed-span health metric as libdd-trace-stats’ native exporter.

Why

dd-trace-js Platform OTLP trace coverage expects traces to carry the tracer instrumentation scope. With @datadog/libdatadog@0.16.0, native OTLP trace export sends scope: {}, so the downstream integration test fails before validating spans.

Notes

This branch pins exact libdatadog commit 8cd68ab922fb7aade0f089ccfc91291d874673af, which is the head of DataDog/libdatadog#2235 (bengl/otlp-scope-metadata-v37). That upstream PR has been ported onto current libdatadog main and is mergeable. Once libdatadog publishes an official release/tag containing the fix, this dependency should be replaced with that release/tag before making this PR ready.

The collapsed-stats regression uses 15,000 spans to stay comfortably above libdd-trace-stats’ 7,000-entry per-bucket cardinality cap. A smaller 7,100-span margin passed locally and on CentOS Node 20 but failed on CentOS Node 24 with collapsedSpans === 0.

Verification

Upstream libdatadog#2235:

  • cargo +nightly-2026-02-08 fmt --all -- --check
  • cargo test -p libdd-trace-utils otlp_encoder::mapper --lib (26 pass)
  • cargo test -p libdd-data-pipeline trace_exporter::builder::tests::test_new --lib (1 pass)
  • cargo test -p libdd-data-pipeline-ffi config_otlp_instrumentation_scope_test --lib (2 pass)
  • cargo check -p libdd-trace-utils
  • cargo check -p libdd-data-pipeline
  • cargo check -p libdd-data-pipeline-ffi
  • cargo test -p libdd-data-pipeline-ffi trace_exporter --lib (28 pass)
  • Reviewer: LibdatadogReviewFeedbackFix approved with no findings

This PR:

  • cargo build -p pipeline --target wasm32-unknown-unknown
  • node scripts/build-wasm.js pipeline
  • cargo fmt --check -p pipeline
  • npm exec -- eslint test/pipeline.js
  • node --test test/pipeline.js (51 pass, 0 fail)
  • node --test test/pipeline.js --test-name-pattern 'exports via OTLP HTTP after setOtlpEndpoint' (50 pass, 0 fail)
  • node --test test/pipeline.js --test-name-pattern 'returns collapsed span count' (51 pass, 0 fail)
  • Reviewer: NodeRepinReview approved with no findings
  • Reviewer: PrePushReview returned no blockers; only noted acceptable rustfmt reflow in crates/pipeline/src/lib.rs
  • Reviewer: OverflowMarginReview returned SAFE TO PUSH for the 15,000-span CI fix
  • Downstream scope-only GREEN with local package: node /tmp/ddjs-otlp-scope-check.js emitted {"name":"dd-trace-js","version":"7.0.0-pre"} and exited 0

@bengl bengl force-pushed the bengl/otlp-scope-metadata-main branch from 46ff7f9 to 3d3b848 Compare July 14, 2026 00:52
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Overall package size

Self size: 30.15 MB
Deduped: 30.15 MB
No deduping: 30.15 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------|

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

Update the temporary libdatadog dependency to the PR head ported onto main. Current libdatadog also changed the stats concentrator API, so adapt the WASM stats wrapper to pass the new cardinality limit argument and encode unobfuscated buckets from FlushResult.
@bengl bengl force-pushed the bengl/otlp-scope-metadata-main branch from 5cf72da to 61a7628 Compare July 14, 2026 17:37
@bengl bengl marked this pull request as ready for review July 14, 2026 18:09
@bengl bengl requested review from a team as code owners July 14, 2026 18:09
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/libdatadog that referenced this pull request Jul 14, 2026
# What does this PR do?

Adds OTLP instrumentation scope metadata to the current trace exporter path.

The trace mapper now copies `instrumentation_scope_name` and `instrumentation_scope_version` from `OtlpResourceInfo` into `ScopeSpans.scope`. `TraceExporterBuilder` gets a setter for OTLP trace scope metadata, stores those values in `OtlpTraceConfig`, and the exporter copies them into each OTLP trace `OtlpResourceInfo` before mapping.

The C FFI exporter config also exposes the same scope setter so non-Rust tracer callers can configure the scope when they enable OTLP export.

# Motivation

`dd-trace-js` native OTLP trace export emitted `scope: {}` through `@DataDog/libdatadog@0.16.0`. Its Platform OTLP integration test expects the Datadog tracer scope (`name: dd-trace-js`) and a tracer version.

# Additional Notes

This branch was ported from the old v37-based patch onto current `main`; it is one commit ahead of `main` and no longer carries the release-line diff that made the earlier draft conflicting.

DataDog/libdatadog-nodejs#173 currently pins this PR head (`8cd68ab922fb7aade0f089ccfc91291d874673af`) only as a temporary unreleased dependency. Once libdatadog publishes an official release/tag containing this change, libdatadog-nodejs should move to that release/tag.

# How to test the change?

- `cargo +nightly-2026-02-08 fmt --all -- --check`
- `cargo test -p libdd-trace-utils otlp_encoder::mapper --lib` (26 pass)
- `cargo test -p libdd-data-pipeline trace_exporter::builder::tests::test_new --lib` (1 pass)
- `cargo test -p libdd-data-pipeline-ffi config_otlp_instrumentation_scope_test --lib` (2 pass)
- `cargo check -p libdd-trace-utils`
- `cargo check -p libdd-data-pipeline`
- `cargo check -p libdd-data-pipeline-ffi`
- `cargo test -p libdd-data-pipeline-ffi trace_exporter --lib` (28 pass)
- Reviewer: `LibdatadogReviewFeedbackFix` approved with no findings


Co-authored-by: bryan.english <bryan.english@datadoghq.com>
let buckets = self.concentrator.flush(now(), force);
if buckets.is_empty() {
let mut flush = self.concentrator.flush(now(), force);
if !flush.obfuscated_buckets.is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will eventually cause issues when we do turn obfuscation on. Perhaps add a TODO comment along the lines of "stats-obfuscation is currently disabled. Obfuscated stats require the datadog-obfuscation-version header, which prepare_request doesn't emit yet. Implement that before enabling the feature"

Comment thread crates/pipeline/src/stats.rs Outdated
@@ -86,12 +87,19 @@ impl StatsCollector {
/// release the collector *before* the async send — leaving it available for
/// `add_spans` while the stats request is in flight.
pub fn prepare_request(&mut self, force: bool) -> Result<Option<http::Request<Bytes>>, String> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't this also emit collapsed_spans when > 0?

ekump
ekump previously approved these changes Jul 14, 2026

@ekump ekump left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

approving for the OTLP instrumentation scope part. But I don't think we're correctly handling cardinality limits yet. We'll need to sort that out before deploying to customers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants