Skip to content

Limit x-datadog-tags size by total bytes#5687

Merged
marcotc merged 6 commits into
masterfrom
x-datadog-tags
May 6, 2026
Merged

Limit x-datadog-tags size by total bytes#5687
marcotc merged 6 commits into
masterfrom
x-datadog-tags

Conversation

@marcotc

@marcotc marcotc commented May 5, 2026

Copy link
Copy Markdown
Member

What does this PR do?
Enforce x-datadog-tags max length checks by String#bytesize instead of character size, during both propagation injection and extraction.

Motivation:
We were checking by character size before this change.

Change log entry

Yes. Enforce x-datadog-tags propagation header size limits by byte size.

Additional Notes:

How to test the change?

bundle exec rspec spec/datadog/tracing/distributed/datadog_spec.rb spec/datadog/tracing/contrib/http/distributed/propagation_spec.rb spec/datadog/tracing/contrib/grpc/distributed/propagation_spec.rb

@marcotc
marcotc requested review from a team as code owners May 5, 2026 23:06
@marcotc
marcotc requested review from mabdinur and removed request for a team May 5, 2026 23:06
@dd-octo-sts dd-octo-sts Bot added the tracing label May 5, 2026

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 LGTM

Comment thread lib/datadog/tracing/distributed/datadog.rb Outdated
@p-datadog

Copy link
Copy Markdown
Member

suggestion (non-blocking): make the byte unit visible in the warning and docstring

The bytesize fix is exactly the right call, and the tests are well-chosen — 'é' * 300 at bytesize 600 / size 300, and 'é' * 252 plus prefix at bytesize 514 / size 262. Both straddle 512 such that the new check rejects them and the old .size check would have accepted them, so the tests actively demonstrate the bug being fixed, not just exercise the new path.

A small observation while reading tags_too_large? — at lib/datadog/tracing/distributed/datadog.rb:192 the warning reports size:#{size} >= limit:#{...} with no unit, and the setting docstring at lib/datadog/tracing/configuration/settings.rb:515 ("Maximum size for the x-datadog-tags...") also doesn't say "bytes". A customer setting DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH=512 could keep reasoning in characters even after this lands.

The warning could name the unit:

::Datadog.logger.warn(
  "Failed to #{scenario} x-datadog-tags: tags are too large for configured byte-size limit (size:#{size} >= " \
    "limit:#{::Datadog.configuration.tracing.x_datadog_tags_max_length}). This limit can be configured " \
    'through the DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH environment variable.'
)

Existing /size:600/ and /size:514/ regex assertions still match. The docstring at settings.rb:515 ("Maximum byte size for...") closes the loop end-to-end.

The core fix is correct as-is.

@marcotc
marcotc requested a review from a team as a code owner May 6, 2026 20:22
@pr-commenter

pr-commenter Bot commented May 6, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-06 21:44:26

Comparing candidate commit 296b5af in PR branch x-datadog-tags with baseline commit afff006 in branch fix-tracestate.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@marcotc

marcotc commented May 6, 2026

Copy link
Copy Markdown
Member Author

"Maximum size for the x-datadog-tags...") also doesn't say "bytes". A customer setting DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH=512 could keep reasoning in characters even after this lands.

@p-datadog I added the wording around "byte" to the message. Thank you!

@marcotc marcotc self-assigned this May 6, 2026
Base automatically changed from fix-tracestate to master May 6, 2026 22:01
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 97.24% (+0.05%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 44f99c8 | Docs | Datadog PR Page | Give us feedback!

@marcotc
marcotc merged commit ea9c451 into master May 6, 2026
416 checks passed
@marcotc
marcotc deleted the x-datadog-tags branch May 6, 2026 22:26
@dd-octo-sts dd-octo-sts Bot added this to the 2.32.0 milestone May 6, 2026
@marcotc marcotc mentioned this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants