feat(tracing): skip OTLP error recording for selected errors#1317
feat(tracing): skip OTLP error recording for selected errors#1317
Conversation
Add TraceOption with SkipErrorRecordingIf and WithSpanStartOptions so Trace and TraceWithMetric can omit otlp.RecordError for expected cases (e.g. not found on ReadLogWithIdempotencyKey). Migrate ImportLog span options to WithSpanStartOptions. Inline the InsertTransaction metric finalizer into the traced callback because TraceWithMetric now takes trace options as its trailing variadic. Made-with: Cursor Signed-off-by: Sylvain Rabot <sylvain@formance.com>
WalkthroughThis PR refactors the tracing infrastructure to use a configurable Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/tracing/tracing.go (1)
127-163: Well-designed TraceOption API with clean extensibility.The functional options pattern is idiomatic Go, the OR semantics for multiple predicates is clearly documented, and the implementation correctly returns errors to callers unchanged while only affecting OTLP recording.
One optional defensive improvement: consider guarding against nil predicates to prevent a panic if a caller accidentally passes
nil.🛡️ Optional: guard against nil predicate
func SkipErrorRecordingIf(predicate func(error) bool) TraceOption { + if predicate == nil { + return traceOptionFunc(func(*traceSettings) {}) // no-op + } return traceOptionFunc(func(s *traceSettings) { s.skipRecordErrorIfs = append(s.skipRecordErrorIfs, predicate) }) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/tracing/tracing.go` around lines 127 - 163, Guard against nil predicates to avoid panics: in SkipErrorRecordingIf, ignore any nil predicate arguments instead of appending them to traceSettings.skipRecordErrorIfs; additionally make shouldSkipErrorRecording resilient by checking for nil before calling predicate (i.e., skip nil entries). Update references in SkipErrorRecordingIf and traceSettings.shouldSkipErrorRecording to perform these nil checks so a mistakenly passed nil predicate won’t cause a runtime panic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/tracing/tracing.go`:
- Around line 127-163: Guard against nil predicates to avoid panics: in
SkipErrorRecordingIf, ignore any nil predicate arguments instead of appending
them to traceSettings.skipRecordErrorIfs; additionally make
shouldSkipErrorRecording resilient by checking for nil before calling predicate
(i.e., skip nil entries). Update references in SkipErrorRecordingIf and
traceSettings.shouldSkipErrorRecording to perform these nil checks so a
mistakenly passed nil predicate won’t cause a runtime panic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ed6a493d-1ea4-451e-90d6-2e2a61ba2042
📒 Files selected for processing (4)
internal/controller/ledger/controller_default.gointernal/storage/ledger/logs.gointernal/storage/ledger/transactions.gointernal/tracing/tracing.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1317 +/- ##
==========================================
- Coverage 81.00% 80.21% -0.80%
==========================================
Files 205 205
Lines 11074 11103 +29
==========================================
- Hits 8971 8906 -65
- Misses 1558 1577 +19
- Partials 545 620 +75 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add TraceOption with SkipErrorRecordingIf and WithSpanStartOptions so Trace and TraceWithMetric can omit otlp.RecordError for expected cases (e.g. "not found" on ReadLogWithIdempotencyKey).
Migrate ImportLog span options to WithSpanStartOptions. Inline the InsertTransaction metric finalizer into the traced callback because TraceWithMetric now takes trace options as its trailing variadic.
Made-with: Cursor