Repository navigation
feat: add stacktrace to panics - #4438
Conversation
📝 WalkthroughWalkthroughThe PR enhances panic recovery in span wrapping by capturing the panic value, recording it with a runtime stacktrace attribute, setting the span status to Error, properly ending the span, and then re-panicking with the original panic value. ChangesPanic Recovery Enhancement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 (2)
pkg/framework/tracex/tracex.go (2)
50-50: ⚡ Quick winSimplify the stacktrace string conversion.
The
fmt.Sprintf("%v", ...)wrapper is redundant here sincedebug.Stack()already returns a[]bytethat you're converting to string. You can passstring(debug.Stack())directly toattribute.String().♻️ Simpler approach
- attribute.String("panic.stacktrace", fmt.Sprintf("%v", string(debug.Stack()))), + attribute.String("panic.stacktrace", string(debug.Stack())),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/framework/tracex/tracex.go` at line 50, Replace the redundant fmt.Sprintf wrapper around the stacktrace conversion in the attribute.String call: directly pass string(debug.Stack()) to attribute.String("panic.stacktrace", ...) instead of using fmt.Sprintf("%v", string(debug.Stack())); locate the attribute.String invocation in tracex.go (the panic stacktrace assignment) and update it accordingly.
48-50: Stack trace capture:WithStackTrace(true)pluspanic.stacktraceis likely redundantIn
pkg/framework/tracex/tracex.go(panic recovery, around lines 48–50),trace.WithStackTrace(true)records the error with the standard OTel exception stacktrace attributes (e.g.,exception.stacktrace), and you also add a custompanic.stacktraceattribute fromdebug.Stack(). If no consumer relies specifically on the custompanic.stacktracekey, you can drop eithertrace.WithStackTrace(true)or the custom attribute to avoid duplicating work/output (or rename the custom attribute to align with the standard semantic convention).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/framework/tracex/tracex.go` around lines 48 - 50, The code currently records both trace.WithStackTrace(true) and a custom attribute via attribute.String("panic.stacktrace", fmt.Sprintf("%v", string(debug.Stack()))), causing duplicate stacktrace output; fix by removing the custom attribute line (attribute.String("panic.stacktrace", ...)) and rely on trace.WithStackTrace(true), or alternatively rename the custom key to the semantic convention "exception.stacktrace" and remove trace.WithStackTrace(true) so only one stacktrace source remains—update the logic around trace.WithStackTrace(true) and attribute.String(...) in the panic recovery code (tracex.go) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/framework/tracex/tracex.go`:
- Line 50: Replace the redundant fmt.Sprintf wrapper around the stacktrace
conversion in the attribute.String call: directly pass string(debug.Stack()) to
attribute.String("panic.stacktrace", ...) instead of using fmt.Sprintf("%v",
string(debug.Stack())); locate the attribute.String invocation in tracex.go (the
panic stacktrace assignment) and update it accordingly.
- Around line 48-50: The code currently records both trace.WithStackTrace(true)
and a custom attribute via attribute.String("panic.stacktrace",
fmt.Sprintf("%v", string(debug.Stack()))), causing duplicate stacktrace output;
fix by removing the custom attribute line (attribute.String("panic.stacktrace",
...)) and rely on trace.WithStackTrace(true), or alternatively rename the custom
key to the semantic convention "exception.stacktrace" and remove
trace.WithStackTrace(true) so only one stacktrace source remains—update the
logic around trace.WithStackTrace(true) and attribute.String(...) in the panic
recovery code (tracex.go) accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 59bc7555-8a33-408d-9e8a-8e1ace1f261e
📒 Files selected for processing (1)
pkg/framework/tracex/tracex.go
Overview
Include stacktrace info if wrapped function panicked.
Summary by CodeRabbit