Use consistent exception logging format#5514
Conversation
Replace `e.message` with `e` (via string interpolation) and
`e.class.name` with `e.class` in all logging contexts across
lib/datadog/.
The `to_s` and `message` methods on Exception have different contracts:
subclasses can override them independently, and `to_s` is the method
Ruby calls during string interpolation. Using `e.message` directly
can produce different output than `#{e}` when a subclass overrides
`to_s` without overriding `message`, or vice versa.
Similarly, `e.class` already returns a displayable class name via
`to_s`, making `.name` redundant in string interpolation contexts.
The codebase convention is `#{e.class}: #{e}`. This commit brings
all logging call sites in line with that convention.
Does not change:
- `e.message` used for constructing new exceptions (raise)
- `e.message` used in data structures or API payloads
- `e.message` in Core::Error.build_from (value object construction)
- `e.message` in conditionals or comparisons
- Test files
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
BenchmarksBenchmark execution time: 2026-04-09 15:36:29 Comparing candidate commit e451652 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.
|
The source code changed from `e.message` / `e.class.name e.message` to `e.class: e` (which produces `ClassName: message`). Test expectations that asserted on the old format now fail because the logged string includes the exception class name with a colon separator. - tags_spec.rb: expected "Oops..." → "StandardError: Oops..." - component_spec.rb: expected /Test failure/ → /RuntimeError: Test failure/ (3 tests: start, stop, update_on_fork) - transport_spec.rb: expected /Timeout::Error Ooops/ → /Timeout::Error: Ooops/ (space → colon+space between class and message) Co-Authored-By: Claude <noreply@anthropic.com>
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: e451652 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
debug() with string interpolation always constructs the string even when
debug logging is off. Block form (debug { }) defers construction.
Also standardize e.message in open_feature/remote.rb which was missed
in the initial pass.
Co-Authored-By: Claude <noreply@anthropic.com>
vpellan
left a comment
There was a problem hiding this comment.
LGTM! Maybe we could create a custom cop to enforce that?
Detects `e.message` and `e.class.name` inside rescue blocks and auto-corrects them to `e` and `e.class` within string interpolation. Follow-up to PR #5514 which standardized the format repo-wide. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Detects `e.message` and `e.class.name` inside rescue blocks and auto-corrects them to `e` and `e.class` within string interpolation. Follow-up to PR #5514 which standardized the format repo-wide. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Detects `e.message` and `e.class.name` inside rescue blocks and auto-corrects them to `e` and `e.class` within string interpolation. Follow-up to PR #5514 which standardized the format repo-wide. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
What does this PR do?
Standardizes exception logging across
lib/datadog/to use the consistent format#{e.class}: #{e}instead of various inconsistent patterns likee.message,e.class.name #{e.message}, ore.class}: #{e.message}.This touches 59 files, but every change follows the same mechanical pattern — no logic changes, just formatting consistency.
Motivation:
Exception#to_sandException#messagehave different contracts in Ruby. Subclasses can override them independently, andto_sis the method Ruby calls during string interpolation ("#{e}"). Usinge.messagedirectly can produce different output than#{e}when a subclass overrides one without the other.Similarly,
e.classalready returns a displayable class name via its ownto_s, making the extra.namecall redundant in string interpolation.The codebase convention is
#{e.class}: #{e}. This PR brings all logging call sites in line with that convention.Log output changes:
This is a formatting change, not a logic change, but the log output customers see does change:
e.message(no class) now include the exception class name (e.g."Test failure"→"RuntimeError: Test failure")e.class.name e.message) now use a colon separator (e.class: e)e.messageis replaced with#{e}(callsto_sinstead ofmessage) — identical for standard exceptions, but could differ for subclasses that override one without the otherWhat was NOT changed (intentionally):
e.messageused for constructing new exceptions (raise SomeError, e.message)e.messageused in data structures or API payloads (e.g.,error_message:fields)e.messageinCore::Error.build_from(value object construction)e.messagein conditionals or comparisonspayload[:exception] = [e.class.name, e.message](Rails convention)Change log entry
None.
Additional Notes:
AI-assisted.
How to test the change?
This is a logging format change only. Existing tests should continue to pass. The change can be verified by:
e.messageremains in logger calls underlib/datadog/