Skip to content

Wire per-component cardinality limits from Config - #11732

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 13 commits into
masterfrom
dougqh/cardinality-limits-config
Jul 14, 2026
Merged

Wire per-component cardinality limits from Config#11732
gh-worker-dd-mergequeue-cf854d[bot] merged 13 commits into
masterfrom
dougqh/cardinality-limits-config

Conversation

@dougqh

@dougqhdougqh commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Wires per-component cardinality limits from Config into the client-side stats handlers, aligning with the Cardinality Limits RFC and the .NET implementation.

Motivation

Follows #11387, which shipped the handler infrastructure. This PR connects the config layer so operators can tune limits and the sentinel substitution is active by default.

Limit surface

Configurable limits (env var exposed)

FieldEnv varDefault
Aggregate table (total distinct rows)DD_TRACE_STATS_CARDINALITY_LIMIT2048
resource.nameDD_TRACE_STATS_RESOURCE_CARDINALITY_LIMIT1024
http.endpointDD_TRACE_STATS_HTTP_ENDPOINT_CARDINALITY_LIMIT512
Per peer-tag valueDD_TRACE_STATS_PEER_TAGS_CARDINALITY_LIMIT512

DD_TRACE_STATS_CARDINALITY_LIMIT is the new canonical name for the table cap; DD_TRACE_TRACER_METRICS_MAX_AGGREGATES is preserved as a backwards-compatible alias.

Fixed limits (hardcoded, no env var)

Fields with inherently low natural cardinality are enforced at their MetricCardinalityLimits defaults but are not user-configurable. The table cap above is the backstop for any unexpected growth.

FieldDefault
service32
operation.name64
span.type16
span.kind8
http.method16
grpc.status_code24
_dd.base_service16

Implementation notes

  • Single parameterized Config.getTraceStatsCardinalityLimit(tagName, defaultLimit) method; configurable fields also have explicit string constants in GeneralConfig for the config registry validator
  • All PropertyCardinalityHandler instances use useBlockedSentinel=true (the default 2-arg constructor); sentinel substitution is active
  • Configurable limit defaults and .NET defaults are aligned

Stacked on #11387 (merged).

Test plan

  • Existing CardinalityHandlerTest and AggregateEntryTest cover sentinel substitution behavior
  • Verify default limits match MetricCardinalityLimits constants
  • Confirm DD_TRACE_STATS_RESOURCE_CARDINALITY_LIMIT etc. are picked up at startup via Config

tag: no release note
tag: ai generated

🤖 Generated with Claude Code

@dougqh
dougqh requested review from a team as code ownersJune 24, 2026 17:03
@dougqh
dougqh requested review from AlexeyKuznetsov-DD and ygree and removed request for a teamJune 24, 2026 17:03
@dd-octo-stsdd-octo-stsBot added the tag: ai generated Largely based on code generated by an AI or LLM label Jun 24, 2026

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:75f72165fd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +3853 to +3854
return configProvider.getInteger(
"trace.stats." + tagName + ".cardinality.limit", defaultLimit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate stats cardinality limits before returning them

When any of the new DD_TRACE_STATS_*_CARDINALITY_LIMIT values is set to 0, a negative number, or a value above 2^29, this method returns it unchanged; the callers added in AggregateEntry and PeerTagSchema pass it directly into PropertyCardinalityHandler/TagCardinalityHandler, whose constructors throw for those ranges. In that misconfigured environment the stats classes fail initialization instead of falling back to the default/logging, so the accessor should reject invalid limits before handing them to the handlers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In my ideal world, config would probably handle this and report a warning immediately at start-up.
Unfortunately, there's no precedence for that in config today.
I'm in full agreement with the sentiment, but I think that's better left to another PR.

"DD_TRACE_STATS_RESOURCE_CARDINALITY_LIMIT": [
{
"version": "A",
"type": "integer",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use int for the new config metadata type

The supported-configurations metadata uses type: "int" for the existing integral settings (including the tracer metrics limits), while these ten new cardinality entries are the only ones using "integer". The local supported-configurations validation/publishing jobs consume this file, so the new configs can be rejected or omitted by downstream metadata consumers even though the agent code reads integers; please use int consistently for these entries.

Useful? React with 👍 / 👎.

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.

Yup, int is used instead of integer in the file.

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.

@mhlidd WDYT to add a test that will check types and failed if there someone made a typo?
OR probably we can support some sort of aliases like int, integer should be treated as the same type...
But I like the test better.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

No need for aliasing, I'll just fix it. I'm curious why Claude decided to use the wrong value though.

@AlexeyKuznetsov-DDAlexeyKuznetsov-DDJul 1, 2026

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.

Yep, Just thinking how to prevent issues in future.
Fir example if there will be a test - Claude with high probability will run it, test will fail, Claude will fix it.

I'm curious why Claude decided to use the wrong value though.

I think it is a nature of LLMs, somehow integer has a bigger weight in model that int and LLM produced wrong output.

@dd-octo-sts

dd-octo-stsBot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

SuiteStatus
Startup🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
ScenarioCandidatemasterΔ (95% CI of mean)
startup:insecure-bank:iast:Agent13.94 s13.98 s[-1.1%; +0.5%] (no difference)
startup:insecure-bank:tracing:Agent12.86 s13.00 s[-1.7%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent17.39 s17.19 s[+0.1%; +2.2%] (maybe worse)
startup:petclinic:iast:Agent17.26 s17.00 s[-2.8%; +5.8%] (no difference)
startup:petclinic:profiling:Agent17.04 s17.36 s[-3.1%; -0.5%] (maybe better)
startup:petclinic:sca:Agent17.42 s16.67 s[+0.2%; +8.8%] (maybe worse)
startup:petclinic:tracing:Agent16.53 s16.74 s[-2.3%; -0.3%] (maybe better)

Commit:238144a8 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@AlexeyKuznetsov-DDAlexeyKuznetsov-DD 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.

LGTM, but:

  1. Code like:
Config.get()
.getTraceStatsCardinalityLimit(
"peer_tag", MetricCardinalityLimits.PEER_TAG_VALUE))

looks a bit noisy, probably can be improved if refactored to enum?
2. JSON descriptor should be fixed integer -> int.

Comment on lines +38 to +39
"resource",
Config.get().getTraceStatsCardinalityLimit("resource", MetricCardinalityLimits.RESOURCE));

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.

QQ: just curious if this MetricCardinalityLimits can be an enum and no need to pass string and int const. Just enum and get the rest from it where needed.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, we might be able to do that. The only complication is that we might have to move the enum next to Config.

@dougqh
dougqhforce-pushed the dougqh/cardinality-limits-config branch 2 times, most recently from 1741d4f to b23f870CompareJuly 1, 2026 01:58
@datadog-prod-us1-3

This comment has been minimized.

@dougqh
dougqhforce-pushed the dougqh/cardinality-limits-config branch from b23f870 to 2418d84CompareJuly 1, 2026 02:31
Base automatically changed from dougqh/control-tag-cardinality to masterJuly 1, 2026 05:12
dougqhand others added 3 commits July 1, 2026 08:46
…its RFC
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dougqh
dougqhforce-pushed the dougqh/cardinality-limits-config branch from 2418d84 to 5b550ddCompareJuly 1, 2026 12:48
@dd-octo-sts

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@dougqhdougqh added comp: core Tracer core type: feature Enhancements and improvements labels Jul 1, 2026
dougqhand others added 2 commits July 1, 2026 13:08
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…y limits
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dougqhand others added 5 commits July 7, 2026 15:09
…oint, add table alias
- Rename DD_TRACE_STATS_PEER_TAG_CARDINALITY_LIMIT -> DD_TRACE_STATS_PEER_TAGS_CARDINALITY_LIMIT
to match .NET naming (plural)
- Raise DD_TRACE_STATS_HTTP_ENDPOINT_CARDINALITY_LIMIT default 64 -> 512 to match .NET
- Add DD_TRACE_STATS_CARDINALITY_LIMIT as the canonical name for the aggregate table cap,
aliasing the older DD_TRACE_TRACER_METRICS_MAX_AGGREGATES
- Add explicit string constants for all 10 per-field cardinality limit keys in GeneralConfig
so the config registry validator can find them
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SERVICE, OPERATION, SERVICE_SOURCE, TYPE, SPAN_KIND, HTTP_METHOD, and
GRPC_STATUS_CODE have naturally low cardinality -- the aggregate table cap
(DD_TRACE_STATS_CARDINALITY_LIMIT) is sufficient backstop. Aligns the
public config surface with .NET (resource, http_endpoint, peer_tags, table cap).
Hardcoded defaults in MetricCardinalityLimits remain; config knobs can be added
later if a customer needs to tune them.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…config key detection
Fields with hardcoded limits (service, operation, type, span_kind, http_method,
grpc_status_code, service_source) now pass their MetricCardinalityLimits constant
directly to PropertyCardinalityHandler instead of going through
Config.getTraceStatsCardinalityLimit. This prevents the test harness from flagging
DD_TRACE_STATS_SERVICE_CARDINALITY_LIMIT etc. as unsupported config keys.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The central registry has no alias for this key; the local entry must match.
The code-level alias (Config.java reads DD_TRACE_TRACER_METRICS_MAX_AGGREGATES
as a fallback) is unaffected.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dougqhand others added 3 commits July 13, 2026 14:27
Version A must match the central registry exactly (no aliases). The
DD_TRACE_TRACER_METRICS_MAX_AGGREGATES alias is Java-specific, so it
belongs in version B — matching the same pattern as
DD_TRACE_STATS_COMPUTATION_ENABLED aliasing DD_TRACE_TRACER_METRICS_ENABLED.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dougqh
dougqh added this pull request to the merge queueJul 14, 2026
@dd-octo-sts

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351Bot commented Jul 14, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-14 11:51:44 UTC ℹ️ Start processing command /merge


2026-07-14 11:51:48 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 2h (p90).


2026-07-14 12:56:09 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Jul 14, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854dBot merged commit 41fffe8 into masterJul 14, 2026
586 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854dBot deleted the dougqh/cardinality-limits-config branch July 14, 2026 12:56
@github-actionsgithub-actionsBot added this to the 1.65.0 milestone Jul 14, 2026
dougqh added a commit that referenced this pull request Jul 14, 2026
Resolved conflicts from #11732 merging while this branch was in flight:
- MetricCardinalityLimits: take HTTP_ENDPOINT=512 from master, keep ADDITIONAL_TAG_VALUE=512
- PropertyHandlers: apply configurable/fixed handler split (resource, http_endpoint configurable;
service, operation, type, span_kind, http_method, grpc_status_code, service_source hardcoded)
- PeerTagSchema: take configurable peer_tags limit from master; keep resetHandlers with HealthMetrics
- PropertyCardinalityHandler / TagCardinalityHandler: take "collapsed:" StatsD prefix and
tracerBlockedValue() naming from master; keep warnedThisCycle field from #11402
- supported-configurations.json: take master's clean int-typed entries, keep ADDITIONAL_TAGS key
- Config.java: import both TRACE_STATS_ADDITIONAL_TAGS and TRACE_STATS_CARDINALITY_LIMIT
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: coreTracer coretag: ai generatedLargely based on code generated by an AI or LLMtype: featureEnhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dougqh@bric3@mhlidd@AlexeyKuznetsov-DD