bugsnag / bugsnag-go

Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
https://docs.bugsnag.com/platforms/go
MIT License
204 stars 69 forks source link

Start showing inlined functions in stack trace #208

Closed DariaKunoichi closed 8 months ago

DariaKunoichi commented 8 months ago

Goal

Customers requested for inline functions to be visible in the stacktrace in bugsnag UI. Issue: https://github.com/bugsnag/bugsnag-go/issues/183

Design

In golang it's recommended to process stacktraces using runtime.CallersFrames. But unfortunately for inlined functions the frame.Func field is going to be nil. In this situation we can extract inlined function data from underlying low level data using FuncForPC.

func runtime.FuncForPC(pc uintptr) runtime.Func FuncForPC returns a Func describing the function that contains the given program counter address, or else nil. If pc represents multiple functions because of inlining, it returns the *Func describing the innermost function, but with an entry of the outermost function.

Changeset

For inline functions extract stack data from PC. Processing frames from stack now does not exclude newest item on this line. Tests for notifier do not match one expected line multiple times on this line

For the example in linked issue the Bugsnag UI reported this:

Screenshot 2024-02-14 at 16 15 54

and after this change it now looks like this:

Screenshot 2024-02-14 at 16 15 25

Testing

Changed unit tests that required us to ignore inlined functions - they are now not ignored.

dingyaguang117 commented 7 months ago

Great Job! Thanks