Skip to content

Ensure usage of captureException() / captureMessage() with non-Error has correct top frame #8396

Description

@mydea

As brought up in #8296, currently the top frame points to internal code when using e.g.:

Sentry.captureException(pojo);
Sentry.captureMessage(pojo);

This should point to the place where this was actually called.

We use a synthetic exception here, which has the stack from exactly where it was called - which is in the Sentry internals. So we need a way to remove this again somehow.

Sadly, this is different in different browsers, and made harder by minifaction. Some examples, non exhaustive but giving a good overview:

Chrome

Unminified:

Error: Sentry syntheticException
    at Hub.captureException (hub.ts:200:1)
    at Module.captureException (exports.ts:39:1)
    at updateCount (HelloWorld.vue:16:12)
    at callWithErrorHandling (runtime-core.esm-bundler.js:157:22)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:21)
    at HTMLButtonElement.invoker (runtime-dom.esm-bundler.js:345:9)
    at HTMLButtonElement.sentryWrapped (helpers.ts:98:1)

Minified:

Error: Sentry syntheticException
    at Dl.captureException (hub.js:123:32)
    at Is (exports.js:20:26)
    at n (HelloWorld.vue:16:5)
    at Ce (runtime-core.esm-bundler.js:157:22)
    at qt (runtime-core.esm-bundler.js:166:21)
    at HTMLButtonElement.n (runtime-dom.esm-bundler.js:345:9)
    at HTMLButtonElement.r (helpers.js:90:17)

Safari

Unminified:

captureException@http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/core/build/esm/hub.js?t=1687528488715:123:41
updateCount@http://localhost:5173/src/components/HelloWorld.vue?t=1687528678533:22:28
callWithErrorHandling@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:1378:20
callWithAsyncErrorHandling@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:1386:38
invoker@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:7574:31
sentryWrapped@http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/browser/build/npm/esm/helpers.js?t=1687528678440:90:22

Minified:

captureException@http://localhost:4173/assets/index.8e4e6fdb.js:7:10497
n@http://localhost:4173/assets/index.8e4e6fdb.js:37:3522
Ce@http://localhost:4173/assets/index.8e4e6fdb.js:1:12584
qt@http://localhost:4173/assets/index.8e4e6fdb.js:1:12663
n@http://localhost:4173/assets/index.8e4e6fdb.js:1:51488
r@http://localhost:4173/assets/index.8e4e6fdb.js:19:1496

Firefox

Unminified:

captureException@http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/core/build/esm/hub.js?t=1687528488715:123:32
captureException@http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/core/build/esm/exports.js?t=1687528488715:20:26
updateCount@http://localhost:5173/src/components/HelloWorld.vue?t=1687528678533:22:12
callWithErrorHandling@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:1378:18
callWithAsyncErrorHandling@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:1386:38
invoker@http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7:7574:31
sentryWrapped@http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/browser/build/npm/esm/helpers.js?t=1687528678440:90:17

Minified:

captureException@http://localhost:4173/assets/index.8e4e6fdb.js:7:10488
Is@http://localhost:4173/assets/index.8e4e6fdb.js:11:906
n@http://localhost:4173/assets/index.8e4e6fdb.js:37:3520
Ce@http://localhost:4173/assets/index.8e4e6fdb.js:1:12583
qt@http://localhost:4173/assets/index.8e4e6fdb.js:1:12663
n@http://localhost:4173/assets/index.8e4e6fdb.js:1:51488
r@http://localhost:4173/assets/index.8e4e6fdb.js:19:1491
EventListener.handleEvent*lm/</<@http://localhost:4173/assets/index.8e4e6fdb.js:19:15731
Gh/</</<@http://localhost:4173/assets/index.8e4e6fdb.js:5:3547
Vf@http://localhost:4173/assets/index.8e4e6fdb.js:1:50852
Xf@http://localhost:4173/assets/index.8e4e6fdb.js:1:51058
rh@http://localhost:4173/assets/index.8e4e6fdb.js:1:51826
H@http://localhost:4173/assets/index.8e4e6fdb.js:1:34294
A@http://localhost:4173/assets/index.8e4e6fdb.js:1:33991
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33421
R@http://localhost:4173/assets/index.8e4e6fdb.js:1:34890
H@http://localhost:4173/assets/index.8e4e6fdb.js:1:34172
A@http://localhost:4173/assets/index.8e4e6fdb.js:1:33991
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33421
R@http://localhost:4173/assets/index.8e4e6fdb.js:1:34890
nt@http://localhost:4173/assets/index.8e4e6fdb.js:1:36286
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33383
w@http://localhost:4173/assets/index.8e4e6fdb.js:1:37616
run@http://localhost:4173/assets/index.8e4e6fdb.js:1:4686
tt/f.update@http://localhost:4173/assets/index.8e4e6fdb.js:1:37884
tt@http://localhost:4173/assets/index.8e4e6fdb.js:1:37910
V@http://localhost:4173/assets/index.8e4e6fdb.js:1:36747
I@http://localhost:4173/assets/index.8e4e6fdb.js:1:36540
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33446
R@http://localhost:4173/assets/index.8e4e6fdb.js:1:34890
nt@http://localhost:4173/assets/index.8e4e6fdb.js:1:36286
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33383
w@http://localhost:4173/assets/index.8e4e6fdb.js:1:37616
run@http://localhost:4173/assets/index.8e4e6fdb.js:1:4686
tt/f.update@http://localhost:4173/assets/index.8e4e6fdb.js:1:37884
tt@http://localhost:4173/assets/index.8e4e6fdb.js:1:37910
V@http://localhost:4173/assets/index.8e4e6fdb.js:1:36747
I@http://localhost:4173/assets/index.8e4e6fdb.js:1:36540
T@http://localhost:4173/assets/index.8e4e6fdb.js:1:33446
Mt@http://localhost:4173/assets/index.8e4e6fdb.js:1:41571
mount@http://localhost:4173/assets/index.8e4e6fdb.js:1:31962
ch/e.mount@http://localhost:4173/assets/index.8e4e6fdb.js:1:52858

Current output frames (e.g. Chrome)

[
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "HTMLButtonElement.invoker",
    "in_app": true,
    "lineno": 7574,
    "colno": 5
  },
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "callWithAsyncErrorHandling",
    "in_app": true,
    "lineno": 1386,
    "colno": 17
  },
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "callWithErrorHandling",
    "in_app": true,
    "lineno": 1378,
    "colno": 18
  },
  {
    "filename": "http://localhost:5173/src/components/HelloWorld.vue?t=1687529456042",
    "function": "updateCount",
    "in_app": true,
    "lineno": 22,
    "colno": 12
  },
  {
    "filename": "http://localhost:5173/@fs/Users/francesco/git/sentry-javascript/packages/core/build/esm/exports.js",
    "function": "Module.captureException",
    "in_app": true,
    "lineno": 20,
    "colno": 26
  }
]

Note that Safari seems to have a correct frames output, but FF & Chrome do not.

Expected output frames

[
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "HTMLButtonElement.invoker",
    "in_app": true,
    "lineno": 7574,
    "colno": 5
  },
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "callWithAsyncErrorHandling",
    "in_app": true,
    "lineno": 1386,
    "colno": 17
  },
  {
    "filename": "http://localhost:5173/node_modules/.vite/deps/vue.js?v=9b021ca7",
    "function": "callWithErrorHandling",
    "in_app": true,
    "lineno": 1378,
    "colno": 18
  },
  {
    "filename": "http://localhost:5173/src/components/HelloWorld.vue",
    "function": "updateCount",
    "in_app": true,
    "lineno": 22,
    "colno": 12
  }
]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions