Fix NoMethodError in extract_trace_id! caused by extract_tags returning true#5499
Conversation
|
👋 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 |
…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
133a1a1 to
a1c5b5d
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 67ade00 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
BenchmarksBenchmark execution time: 2026-03-25 17:18:02 Comparing candidate commit 67ade00 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 unstable metrics.
|
Description
Fixes #5479
The rescue blocks in
Datadog::Tracing::Distributed::Datadog#extract_tagsand#inject_tags!implicitly returntrue(the return value ofLogger#warn) instead ofnil.For
extract_tags, thistrueis passed toextract_trace_id!, which calls.deleteon it, raising:Root cause
In
lib/datadog/tracing/distributed/datadog.rblines 166-171, the rescue block's last expression is::Datadog.logger.warn(...), which returnstruein Ruby. This becomes the method's implicit return value.The caller chain:
#extract(line 69):trace_distributed_tags = extract_tags(fetcher)→ getstrue#extract(line 73):extract_trace_id!(trace_id, trace_distributed_tags)→ passestrue#extract_trace_id!(line 117):tags.delete(...)→NoMethodErrorontrueWhy existing tests didn't catch this
The spec for "with invalid tags" mocks
Datadog.loggerwithexpect(...).to receive(:warn), which returnsnilfrom the mock instead oftruefrom the real logger, masking the bug.Changes
nilafterlogger.warnin rescue blocks of bothextract_tagsandinject_tags!#extractwith invalid tags without mocking the loggerImpact
In our production environment, this generates ~30,000+ error logs per day. Any application receiving requests with malformed
x-datadog-tagsheaders hits this.Change log entry
....