sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Improve `in_app` detection

Open sentrivana opened this issue 1 year ago • 1 comments

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:

  1. On the Sentry side, remove the redundant checks that set a frame as not in-app if the package is in site-packages or dist-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 their in_app_include to include the module). Tracked in https://github.com/getsentry/sentry/issues/79482
  2. On the SDK side, look into frames with unexpected in_app values and fix the underlying issues. (Tracked by this issue.)

Supersedes https://github.com/getsentry/sentry-python/issues/3671

sentrivana avatar Oct 22 '24 12:10 sentrivana

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__.py frame?
  • 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
              }
            }
          ]
        }
      }
    ]
  }
}

sentrivana avatar Oct 22 '24 13:10 sentrivana

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?)

lobsterkatie avatar Oct 24 '24 13:10 lobsterkatie

Superseded by https://github.com/getsentry/sentry/issues/83603

lobsterkatie avatar Jan 16 '25 20:01 lobsterkatie