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-03-26 20:32:55 Comparing candidate commit 5201f49 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 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: a8cb256 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
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.What 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 — internal cleanup, no customer-visible behavior change.
Additional Notes:
AI-assisted. All changes reviewed for correctness. Each change site was individually evaluated to confirm it's a logging context (not exception construction, data payload, or conditional logic).
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/