Skip to content

feat: implement additional metric tags for trace stats#140

Open
duncanpharvey wants to merge 7 commits into
mainfrom
duncan-harvey/trace-stats-additional-metric-tags
Open

feat: implement additional metric tags for trace stats#140
duncanpharvey wants to merge 7 commits into
mainfrom
duncan-harvey/trace-stats-additional-metric-tags

Conversation

@duncanpharvey

@duncanpharvey duncanpharvey commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

  • Add DD_TRACE_STATS_ADDITIONAL_TAGS setting for adding additional tags to trace stats.
  • Add DD_TRACE_STATS_ADDITIONAL_TAGS_CARDINALITY_LIMIT to limit number of distinct stats entries (default of 100 in libdd-trace-stats if no value is passed).
  • Add DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED to gate the behavior behind DD_TRACE_STATS_ADDITIONAL_TAGS and DD_TRACE_STATS_ADDITIONAL_TAGS_CARDINALITY_LIMIT.

Motivation

Allow Serverless Compatibility Layer to send additional metric tags on trace stats. See RFC.

https://datadoghq.atlassian.net/browse/SVLS-8787

Additional Notes

Dependent on these changes in libdatadog: DataDog/libdatadog#2170

Describe how to test/QA your changes

  • Unit tests for regressions and new functionality added by DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED
  • Deploy to Azure Functions with the following environment variables and validate that additional tags appear on trace metrics
    • DD_TAGS: custom.primary:val,workload:azure_functions
    • DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED: true
    • DD_TRACE_STATS_ADDITIONAL_TAGS: custom.primary,workload
Screenshot 2026-07-06 at 3 39 47 PM

@duncanpharvey
duncanpharvey force-pushed the duncan-harvey/trace-stats-additional-metric-tags branch from 6fae257 to e38ada5 Compare June 29, 2026 14:11
@datadog-datadog-prod-us1-2

This comment has been minimized.

@duncanpharvey duncanpharvey changed the title feat: implement implement additional metric tags for trace stats feat: implement additional metric tags for trace stats Jun 29, 2026
@duncanpharvey
duncanpharvey force-pushed the duncan-harvey/trace-stats-additional-metric-tags branch from e38ada5 to ec966d8 Compare June 29, 2026 16:05
@duncanpharvey
duncanpharvey force-pushed the duncan-harvey/trace-stats-additional-metric-tags branch from ec966d8 to 9ed7705 Compare July 6, 2026 17:02
@duncanpharvey
duncanpharvey marked this pull request as ready for review July 6, 2026 20:08
@duncanpharvey
duncanpharvey requested a review from a team as a code owner July 6, 2026 20:08
Copilot AI review requested due to automatic review settings July 6, 2026 20:08
@duncanpharvey
duncanpharvey requested a review from a team as a code owner July 6, 2026 20:08
@duncanpharvey
duncanpharvey requested review from Lewis-E and jchrostek-dd and removed request for a team July 6, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Implements support for sending additional metric tags on trace stats by introducing new configuration settings (gated behind an experimental flag) and wiring them into the trace stats concentrator, along with updating the libdatadog dependency revision required for the feature.

Changes:

  • Add DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED, DD_TRACE_STATS_ADDITIONAL_TAGS, and DD_TRACE_STATS_ADDITIONAL_TAGS_CARDINALITY_LIMIT parsing to trace-agent config (with unit tests for gating).
  • Update stats concentrator creation to pass additional metric tags + optional cardinality limit, and introduce a hashable key wrapper for TracerMetadata.
  • Bump libdatadog git revs across crates and update lockfile / third-party license list accordingly.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
LICENSE-3rdparty.csv Adds newly introduced transitive dependencies to the third-party license inventory.
crates/datadog-trace-agent/src/trace_processor.rs Updates tests/struct construction to include newly added config fields and payload field.
crates/datadog-trace-agent/src/stats_concentrator_service.rs Passes additional metric tags + cardinality limit into SpanConcentrator and updates metadata keying.
crates/datadog-trace-agent/src/config.rs Adds experimental flag + additional tag settings, with unit tests for gating behavior.
crates/datadog-trace-agent/Cargo.toml Bumps libdatadog git revision to pick up required upstream changes.
crates/datadog-serverless-compat/Cargo.toml Bumps libdatadog git revision for trace utils.
crates/datadog-metrics-collector/Cargo.toml Bumps libdatadog git revision for common utilities.
crates/datadog-agent-config/Cargo.toml Bumps libdatadog git revision for trace utils/obfuscation.
Cargo.lock Locks new upstream libdatadog revisions and new transitive crates introduced by the update.

Comment thread crates/datadog-trace-agent/src/config.rs
Comment thread crates/datadog-trace-agent/src/config.rs Outdated
Comment thread LICENSE-3rdparty.csv
Comment thread crates/datadog-trace-agent/src/stats_concentrator_service.rs Outdated
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/libdatadog that referenced this pull request Jul 21, 2026
…2170)

# What does this PR do?

- Add additional metric tags to the stats aggregation key. For each configured key, the matching span meta tag is included in the key and populates `ClientGroupedStats.additional_metric_tags`.
- Limit the number of keys for `additional_metric_tags` to 4, not configurable.
- Limit the maximum length of individual additional_metric_tags values to 200 characters, not configurable. Values exceeding this are replaced with `tracer_blocked_value`.

# Motivation

- Allow Serverless Compatibility Layer to send additional metric tags on trace stats. See [RFC](https://datadoghq.atlassian.net/wiki/spaces/APM/pages/6482919540/PENDING+Span-Derived+Primary+Tags+-+V1).
- DataDog/serverless-components#140 to follow.
- https://datadoghq.atlassian.net/browse/SVLS-8787

# Additional Notes

Additional metric tags still need to be implemented in libdd-data-pipeline. Omitted from this PR since the goal of this PR is to support additional metric tags tags for Serverless without affecting other teams.

https://github.com/DataDog/libdatadog/blob/42e3296aa3fa76749caf5d96b5bbf1ff2b1913b6/libdd-data-pipeline/src/trace_exporter/stats.rs#L146


Per-field cardinality limit for additional metric tags will be implemented in a following PR, #2211.
- Limit the number of distinct aggregation entries per bucket that carry additional metric tags to 100 by default, configurable via `additional_metric_tags_max_entries`. Once exceeded, new entries have their tag values masked to `tracer_blocked_value`.

---

Implementing additional metric tags instead of span derived primary tags. See previous PR for span derived primary tags - #1815.

# How to test the change?

- Unit tests
- Deploy to Azure Functions with the following environment variables and validate that additional tags appear on trace metrics
  * `DD_TAGS: custom.primary:val,workload:azure_functions`
  * `DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED: true`
  * `DD_TRACE_STATS_ADDITIONAL_TAGS: custom.primary,workload`

<img width="685" height="411" alt="Screenshot 2026-07-06 at 3 39 47 PM" src="https://github.com/user-attachments/assets/b91495b6-11aa-4051-922f-63655666c4e5" />


Co-authored-by: duncan.harvey <duncan.harvey@datadoghq.com>
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.

3 participants