Skip to content

Fix NoMethodError in extract_trace_id! caused by extract_tags returning true#5499

Merged
mabdinur merged 2 commits into
masterfrom
munir/fix-extract-tags-rescue-return-value
Mar 25, 2026
Merged

Fix NoMethodError in extract_trace_id! caused by extract_tags returning true#5499
mabdinur merged 2 commits into
masterfrom
munir/fix-extract-tags-rescue-return-value

Conversation

@mabdinur

@mabdinur mabdinur commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #5479

The rescue blocks in Datadog::Tracing::Distributed::Datadog#extract_tags and #inject_tags! implicitly return true (the return value of Logger#warn) instead of nil.

For extract_tags, this true is passed to extract_trace_id!, which calls .delete on it, raising:

NoMethodError: undefined method 'delete' for true

Root cause

In lib/datadog/tracing/distributed/datadog.rb lines 166-171, the rescue block's last expression is ::Datadog.logger.warn(...), which returns true in Ruby. This becomes the method's implicit return value.

The caller chain:

  1. #extract (line 69): trace_distributed_tags = extract_tags(fetcher) → gets true
  2. #extract (line 73): extract_trace_id!(trace_id, trace_distributed_tags) → passes true
  3. #extract_trace_id! (line 117): tags.delete(...)NoMethodError on true

Why existing tests didn't catch this

The spec for "with invalid tags" mocks Datadog.logger with expect(...).to receive(:warn), which returns nil from the mock instead of true from the real logger, masking the bug.

Changes

  • Add explicit nil after logger.warn in rescue blocks of both extract_tags and inject_tags!
  • Add regression test that exercises #extract with invalid tags without mocking the logger

Impact

In our production environment, this generates ~30,000+ error logs per day. Any application receiving requests with malformed x-datadog-tags headers hits this.

Change log entry
....

@github-actions

github-actions Bot commented Mar 24, 2026

Copy link
Copy Markdown

👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description.

If changes need to be present in CHANGELOG.md you can state it this way

**Change log entry**

Yes. A brief summary to be placed into the CHANGELOG.md

(possible answers Yes/Yep/Yeah)

Or you can opt out like that

**Change log entry**

None.

(possible answers No/Nope/None)

Visited at: 2026-03-24 19:08:47 UTC

@mabdinur mabdinur changed the title Fix extract_tags and inject_tags! rescue blocks returning true instea… Fix extract_tags and inject_tags! rescue blocks returning true instead Mar 24, 2026
@mabdinur mabdinur changed the title Fix extract_tags and inject_tags! rescue blocks returning true instead Fix NoMethodError in extract_trace_id! caused by extract_tags returning true Mar 24, 2026
…d of nil

The rescue blocks in extract_tags and inject_tags! call Logger#warn as
their last expression. In Ruby, Logger#warn returns true, which becomes
the method's implicit return value. For extract_tags, this true is then
passed to extract_trace_id!, which calls .delete on it, raising:

  NoMethodError: undefined method 'delete' for true

Add explicit nil after logger.warn in both rescue blocks to ensure the
correct return value. Add regression test that exercises the real return
value path without mocking the logger.

Fixes #5479
@mabdinur
mabdinur force-pushed the munir/fix-extract-tags-rescue-return-value branch from 133a1a1 to a1c5b5d Compare March 24, 2026 19:17
@datadog-official

datadog-official Bot commented Mar 24, 2026

Copy link
Copy Markdown

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 95.16% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 67ade00 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@mabdinur
mabdinur marked this pull request as ready for review March 24, 2026 19:40
@mabdinur
mabdinur requested review from a team as code owners March 24, 2026 19:40
@mabdinur
mabdinur requested a review from vpellan March 24, 2026 19:41
@pr-commenter

pr-commenter Bot commented Mar 25, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-03-25 17:18:02

Comparing candidate commit 67ade00 in PR branch munir/fix-extract-tags-rescue-return-value with baseline commit d06ba9f in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 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 ----------------------------------'

@mabdinur
mabdinur merged commit 5889737 into master Mar 25, 2026
629 of 630 checks passed
@mabdinur
mabdinur deleted the munir/fix-extract-tags-rescue-return-value branch March 25, 2026 18:21
@github-actions github-actions Bot added this to the 2.31.0 milestone Mar 25, 2026
@y9v y9v mentioned this pull request Apr 16, 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.

[BUG]: NoMethodError in extract_trace_id! when extract_tags rescue returns Logger#warn result (true)

3 participants