-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix InApp detection for stack traces #378
Comments
Hey @rhcarvalho (I'm tagging you because we interacted earlier, hope it's ok), could you take a quick look at this? :) I can prepare a PR to fix this, I just want a confirmation before "wasting my time" :) Thanks! |
Using
It's possible to get the module path using debug.ReadBuildInfo, but I haven't checked if there's any complications when not using |
I'm also not seeing my code being marked as in-app using |
A quick fix in this library would be to change the check here Line 336 in 8f8897d
to change
to
|
Summary
All frames in my stack traces look like they are "in app", no matter where they are from. Currently, the detection is done by this function:
There are two issues:
build.Default.GOROOT
seems to be a bad choice there, because at least on my system it has a value of/usr/local/go
(or justgo
with-trimpath
), which will never match the path of any files since all src/modules are under (in my case)/home/grongor/projects/go
(contains subfolderssrc
,pkg
, ...). This path can be found inbuild.Default.GOPATH
. That would fix "outside of app" detection for not vendored dependencies.vendor
andthird_party
(I think this one is weird/makes no sense, I would remove it) are based onframe.Module
, which is filled fromruntime.Frame.Function
and it will never contain (at least in all kinds of experiments I tried, please correct me if I'm wrong) these two keywords.vendor
is present in the pathruntime.Frame.File
, but to just usestrings.Contains
on the whole path isn't, in my opinion, a good way to detect if a frame is "in app". To safely detect that the frame is truly in thevendor
directory, we would need to know the path to the application (main module), and checkrunetime.Frame.File
for prefix of of that path +/vendor/
Detecting this correctly when using
-trimpath
is quite simple, we just need to retrieve the modules' information and checkruntime.Frame.File
for the prefix of the main module. Without-trimpath
it's more complicated, but I think I've found a reliable way to detect the main module path usingruntime.Stack(buf, true)
, where thetrue
flag is the key. It will fill the buffer with all Goroutines. We could then search this buffer, either forgoroutine 1
(which should always be main), or/and formain.main()
and extract the path from there.We could make these two variables public so that the user has an option to specify them manually (and then skip the detection) but, to be honest, I don't think that it's necessary. If path detection doesn't work for some "obscure" projects, I'd just recommend them to use
-trimpath
.Also, if we manage to do this, we could easily trim the paths in the frames to make them relative to the project, eg.:
Project paths would be relative, paths from modules would still be absolute (no chance for conflicts/ambiguous stack traces).
I managed to write an extension for sentry-go to do exactly this (see here https://github.com/grongor/go-bootstrap/blob/master/sentry.go#L78 ), but I think this is something that should be present in this library.
If you wish I can send a pull request with these changes, just let me know.
Environment
SDK
sentry-go
version: latest (0.11.0)Sentry
The text was updated successfully, but these errors were encountered: