Skip to content

feat(trace-stats): add span-derived primary tags to SpanConcentrator#1858

Closed
lucaspimentel wants to merge 3 commits intomainfrom
lpimentel/span-derived-primary-tags
Closed

feat(trace-stats): add span-derived primary tags to SpanConcentrator#1858
lucaspimentel wants to merge 3 commits intomainfrom
lpimentel/span-derived-primary-tags

Conversation

@lucaspimentel
Copy link
Copy Markdown
Member

@lucaspimentel lucaspimentel commented Apr 8, 2026

What does this PR do?

Adds span_derived_primary_tags as a new aggregation dimension in SpanConcentrator.

User-configured tag keys (e.g. aws.s3.bucket, datacenter, customer_tier) are extracted from spans and included in APM stats, enabling serverless customers who can't rely on container tags to use primary tags.

This follows the existing peer tags pattern, but without span.kind gating. Span-derived primary tags apply to all eligible spans (not just client/producer/consumer).

Stats computation scenarios

There are 3 scenarios where APM stats are computed or forwarded. This PR (plus the existing proto field) covers all of them:

Scenario How it works Status
Tracers computing client-side stats (CSS) from_span() extracts tags, encode_grouped_stats() serializes to proto ✅ This PR
Agent (bottlecap) receiving CSS from tracers CSS payloads arrive at /v0.6/stats and are forwarded as-is -- they never touch SpanConcentrator. The span_derived_primary_tags field passes through on the proto untouched. ✅ Already works (proto field exists)
Agent (bottlecap) computing stats from raw spans Same from_span() / add_span() path as scenario 1 ✅ This PR*

*Scenario 3 requires a follow-up bottlecap PR to parse DD_APM_SPAN_DERIVED_PRIMARY_TAGS and call set_span_derived_primary_tag_keys() -- without that, the keys default to empty and no tags get extracted.

Changes

libdd-trace-stats/src/span_concentrator/aggregation.rs

  • Added span_derived_primary_tags field to BorrowedAggregationKey and OwnedAggregationKey
  • Updated Equivalent impl, From conversions, and hash/equality to include the new field
  • Updated from_span() to accept span_derived_primary_tag_keys and extract tags unconditionally from span meta
  • Updated encode_grouped_stats() to serialize tags as "key:value" strings (replacing the vec![] // Todo stub)
  • Updated From<pb::ClientGroupedStats> to deserialize the field for re-aggregation
  • Added unit tests for hash/equality consistency with span-derived primary tags

libdd-trace-stats/src/span_concentrator/mod.rs

  • Added span_derived_primary_tag_keys: Vec<String> field to SpanConcentrator
  • Added set_span_derived_primary_tag_keys() setter (no constructor change)
  • Pass keys to BorrowedAggregationKey::from_span() in add_span()
  • Updated doc comments

libdd-trace-stats/src/span_concentrator/tests.rs

  • Added test_span_derived_primary_tags_aggregation integration test covering:
    • Tags applied to all span kinds (root, server, client)
    • Different tag values create separate aggregation buckets
    • Coexistence with peer tags on client spans
    • Concentrator without configured keys aggregates normally

Motivation

Support for SVLS-8627. The agent-side implementation landed in DataDog/datadog-agent#42996. The proto field span_derived_primary_tags (tag 22 on ClientGroupedStats) already exists -- this PR wires it up in the stats computation layer.

Additional Notes

  • The SpanConcentrator::new() signature is unchanged -- keys are set via a setter, consistent with the existing set_peer_tags() / set_span_kinds() pattern.
  • A follow-up bottlecap PR will parse DD_APM_SPAN_DERIVED_PRIMARY_TAGS and call the new setter.

How to test the change?

cargo nextest run -p libdd-trace-stats

All 14 tests pass, including the new test_span_derived_primary_tags_aggregation.

🤖 Generated with Claude Code

…ntrator

Add span_derived_primary_tags as a new aggregation dimension, allowing
user-configured tag keys to be extracted from spans and used for stats
aggregation. Unlike peer tags, these apply to all eligible spans
regardless of span.kind.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

📚 Documentation Check Results

⚠️ 569 documentation warning(s) found

📦 libdd-trace-stats - 569 warning(s)


Updated: 2026-04-09 21:07:06 UTC | Commit: c391039 | missing-docs job results

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/lpimentel/span-derived-primary-tags

Summary by Rule

Rule Base Branch PR Branch Change

Annotation Counts by File

File Base Branch PR Branch Change

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 21 21 No change (0%)
datadog-live-debugger 6 6 No change (0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-remote-config 3 3 No change (0%)
datadog-sidecar 55 55 No change (0%)
libdd-common 10 10 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 5 5 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-telemetry 19 19 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 8 8 No change (0%)
libdd-trace-utils 15 15 No change (0%)
Total 196 196 No change (0%)

About This Report

This 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.

@lucaspimentel lucaspimentel changed the title feat(trace-stats): add span-derived primary tags to SpanConcentrator feat(trace-stats): add span-derived primary tags to SpanConcentrator Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🔒 Cargo Deny Results

No issues found!

📦 libdd-trace-stats - ✅ No issues


Updated: 2026-04-09 21:10:22 UTC | Commit: c391039 | dependency-check job results

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.81%. Comparing base (33896de) to head (11117e5).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1858      +/-   ##
==========================================
+ Coverage   71.69%   71.81%   +0.12%     
==========================================
  Files         429      429              
  Lines       67886    68163     +277     
==========================================
+ Hits        48672    48954     +282     
+ Misses      19214    19209       -5     
Components Coverage Δ
libdd-crashtracker 66.05% <ø> (+0.05%) ⬆️
libdd-crashtracker-ffi 34.47% <ø> (+0.38%) ⬆️
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 86.27% <ø> (-0.03%) ⬇️
libdd-data-pipeline-ffi 73.17% <ø> (-0.12%) ⬇️
libdd-common 79.16% <ø> (ø)
libdd-common-ffi 73.87% <ø> (ø)
libdd-telemetry 65.98% <ø> (ø)
libdd-telemetry-ffi 16.75% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 73.10% <ø> (ø)
libdd-profiling 82.13% <ø> (+<0.01%) ⬆️
libdd-profiling-ffi 64.94% <ø> (ø)
datadog-sidecar 30.83% <ø> (+0.36%) ⬆️
datdog-sidecar-ffi 10.19% <ø> (+1.72%) ⬆️
spawn-worker 54.69% <ø> (ø)
libdd-tinybytes 93.16% <ø> (ø)
libdd-trace-normalization 81.71% <ø> (ø)
libdd-trace-obfuscation 87.24% <ø> (ø)
libdd-trace-protobuf 68.25% <ø> (ø)
libdd-trace-utils 88.72% <ø> (ø)
datadog-tracer-flare 86.88% <ø> (ø)
libdd-log 74.69% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-prod-us1-3

This comment has been minimized.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts bot commented Apr 8, 2026

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.63 MB 7.63 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 83.34 MB 83.39 MB +.05% (+44.45 KB) 🔍
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 99.40 MB 99.42 MB +.01% (+17.75 KB) 🔍
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.17 MB 10.17 MB +.01% (+1.21 KB) 🔍
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 25.16 MB 25.17 MB +.04% (+11.50 KB) 🔍
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 78.21 KB 78.21 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 184.19 MB 184.30 MB +.05% (+104.00 KB) 🔍
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 917.34 MB 917.54 MB +.02% (+206.75 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 7.88 MB 7.88 MB +.02% (+2.00 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 78.21 KB 78.21 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 23.64 MB 23.64 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 46.13 MB 46.14 MB +.02% (+11.71 KB) 🔍
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 21.63 MB 21.64 MB +.04% (+10.50 KB) 🔍
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 79.42 KB 79.42 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.30 MB 188.40 MB +.05% (+104.00 KB) 🔍
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 902.08 MB 902.28 MB +.02% (+203.05 KB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.12 MB 6.12 MB +.03% (+2.00 KB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 79.42 KB 79.42 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 25.31 MB 25.33 MB +.06% (+16.00 KB) 🔍
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 43.61 MB 43.62 MB +.02% (+12.99 KB) 🔍
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 74.47 MB 74.51 MB +.04% (+33.78 KB) 🔍
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.52 MB 8.53 MB +.04% (+4.00 KB) 🔍
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 91.77 MB 91.78 MB +.01% (+12.75 KB) 🔍
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.20 MB 10.20 MB +0% (+952 B) 👌

@lucaspimentel lucaspimentel added the AI Generated PR largely written by AI tools label Apr 8, 2026
- Update from_span() doc to mention span_derived_primary_tag_keys
- Replace em-dashes with colons in code comments
- Add clarifying comment for missing "version" key on client span

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
lucaspimentel added a commit to DataDog/datadog-lambda-extension that referenced this pull request Apr 9, 2026
Parse the env var and wire it through Config for use as
additional APM stats aggregation dimensions. The actual
SpanConcentrator call is gated on DataDog/libdatadog#1858.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
lucaspimentel added a commit to DataDog/datadog-lambda-extension that referenced this pull request Apr 9, 2026
Parse the env var and wire it through Config for use as
additional APM stats aggregation dimensions. The actual
SpanConcentrator call is gated on DataDog/libdatadog#1858.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
@lucaspimentel
Copy link
Copy Markdown
Member Author

This was just a test. We already have #1815. Closing.

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

Labels

AI Generated PR largely written by AI tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants