Skip to content
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

"onerror" global handler doesn't set event.level = 'error' #4400

Closed
4 of 9 tasks
nag5000 opened this issue Jan 13, 2022 · 2 comments · Fixed by #4460
Closed
4 of 9 tasks

"onerror" global handler doesn't set event.level = 'error' #4400

nag5000 opened this issue Jan 13, 2022 · 2 comments · Fixed by #4460
Labels
Package: browser Issues related to the Sentry Browser SDK

Comments

@nag5000
Copy link

nag5000 commented Jan 13, 2022

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

6.16.1

Description

  1. GlobalHandlers integration is enabled (by default).

  2. const script = document.createElement('script');
    script.text = 'throw new Error("oops");';
    document.body.appendChild(script);
  3. event.level is undefined in beforeSend hook and /store POST payload also doesn't have this property.

Unlike onerror, unhandledrejection handler sets event.level = 'error':

@AbhiPrasad
Copy link
Member

This is the case because Relay, Sentry's event ingestion system, defaults the level to be error. https://github.com/getsentry/relay/blob/5f6f8012639f5d8385b9943e46ddad9d8925c949/relay-general/src/store/normalize.rs#L495-L498 - so we don't need to set it explicitly in the SDK.

We can change this though, for what purpose were you trying to grab event.level?

@AbhiPrasad AbhiPrasad added Package: browser Issues related to the Sentry Browser SDK Status: Needs Discussion labels Jan 14, 2022
@nag5000
Copy link
Author

nag5000 commented Jan 14, 2022

I rely on event.level in beforeSend hook to filter out some events. Smth like that:

if (event.level === 'error') {
  const error = hint.originalException;
  if (someFn(error)) {
    return null;
  } 
}

defaults the level to be error

Ah, ok then, it's simply const level = event.level ?? 'error'?. But it would be nice to cover this in the documentation.

Also I can use duck typing if (hint.originalException), but I don't really like this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants