Improve `in_app` detection
When viewing a stacktrace in Sentry, frames are marked as either in_app or not in_app. Non-in-app frames are collapsed by default. The original in_app decision comes from the SDK; however, at the moment Sentry can't rely on the in_app decision from the SDK and has rules for overriding it.
Two things we can do about this:
- On the Sentry side, remove the redundant checks that set a frame as not in-app if the package is in
site-packagesordist-packages. We already check this on the SDK side. Having this rule on the server side means that it sometimes overrides a higher prio decision (e.g., the user explicitly set theirin_app_includeto include the module). Tracked in https://github.com/getsentry/sentry/issues/79482 - On the SDK side, look into frames with unexpected
in_appvalues and fix the underlying issues. (Tracked by this issue.)
Supersedes https://github.com/getsentry/sentry-python/issues/3671
Example: in_app_include contains ['mypackage'] in this scenario:
- Why does the SDK not mark as in-app the
/app/.heroku/python/lib/python3.11/site-packages/mypackage/__main__.pyframe? - Should the SDK mark
/app/<frozen runpy>as not in-app?
{
"exception": {
"values": [
{
"stacktrace": {
"frames": [
{
"abs_path": "/app/<frozen runpy>",
"in_app": true # why?
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/mypackage/__main__.py",
"in_app": false # why?
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/click/core.py",
"in_app": false
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/click/decorators.py",
"in_app": false
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/mypackage/__main__.py",
"in_app": false # why?
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/mypackage/dir/some_python_file.py",
"in_app": false,
"data": {
"orig_in_app": 1
}
},
{
"abs_path": "/app/.heroku/python/lib/python3.11/site-packages/mypackage/another_dir/another_python_file.py",
"in_app": false,
"data": {
"orig_in_app": 1
}
}
]
}
}
]
}
}
Left a comment on https://github.com/getsentry/sentry-python/issues/3671, but TL;DR I think this logic should live server-side (which doesn't mean that if we're making wrong decisions there we shouldn't perform this same investigation, of course!).
Meta: Right now, we're having this conversation in four places: here, in https://github.com/getsentry/sentry/issues/79482, in https://github.com/getsentry/sentry-python/issues/3671, and in https://github.com/getsentry/sentry-python/pull/3672. Can we centralize to one spot as we continue to discuss this? (And/or just hop on a call with you, me, @armenzg , and anyone else who's interested, and just hash it out?)
Superseded by https://github.com/getsentry/sentry/issues/83603