sentry-javascript: How to pass extra data via captureException/captureMessage in latest sdk
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
Package + Version
-
@sentry/browser -
@sentry/node -
raven-js -
raven-node(raven for node) - other:
Version:
4.0.6
Description
We can put a extra data in captureException / captureMessage when we use raven-js.
Raven.captureException(err, extra)
How is that supported in latest sdk ?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 48
- Comments: 28 (8 by maintainers)
Hey guys, this does look ridiculous. Did you see competitors’ API?
Yeah, I’ve sound the same solution, but indeed, it’s less sexy
Hello in 2019. It’s SO ANNOYING that I can’t just pass context as the second parameter in
captureException. Please consider changing this.If anyone came up with an elegant workaround/wrapping method please post!
For those looking from Google -> https://docs.sentry.io/platforms/javascript/enriching-error-data/additional-data/manage-context/#passing-context-directly
Looks like you can pass context keys like
tags, extra, contexts, user, level, fingerprint, for example:@emmya that’s way more code than you need 😃
We handle string errors just fine unless you specifically want “message” level on purpose. You can also pass a whole object to
setTags/setExtrasand we’ll handle malformed/undefined input for you as well.Only about extra data
I usage sentry 6.16.1
captureException(new Error('test 10'), { extra: { test: 1 } });https://docs.sentry.io/platforms/javascript/guides/electron/enriching-events/context/
I think the new withScope is kind of pointless since you can’t use async functions with it, apparently. You pretty much have to have the withScope and captureException very close to each other and you know what would solve that? If captureException accepted a scope parameter! @kamilogorek
😐😐😐😐😐😐😐
docs
For a simple text message together with
captureExceptionuseaddBreadcrumb, for additional data usesetContext(or breadcrumbdataproperty):I don’t understand why there can’t be an overload for
Sentry.captureMessagethat also accepts an object forextra?Now I have this in all my projects:
But this is a helper method that should be integrated into Sentry… I understand there are technical problems but surely you’ve noticed that this is the most asked question about Sentry.
This is bad for users that are upgrading and it’s bad for users that are new to Sentry. It’s good for developers of Sentry. I’m a developer so I get it, but I feel like Sentry may have lost sight of what is important on this specific issue.
We will add something like this, thanks all for the feedback! Will update the issue here again with the solution.
Ok, new to sentry - And the first think I learned is, that I can’t use Sentry for sending simple messages with an object as payload. That’s a pity since it’s a common usecase - What a about a extra function like "Sentry.captureMessage(‘crash-report’, { id : 2, …}); ?
@vincerubinetti using
contextgives you a better UI, as everykeyhas its own section on the event page.extrais still supported for legacy reasons, so we still don’t deprecate it in this major version. It most likely will be the case for the next one though.I literally just want to add a simple string message alongside the error, is that even doable ? like this (mentioned in the comment above)
Rollbar.error("Something went wrong", e, {postId: 123});In those doc links:
We allow the following context keys to be passed: tags, extra, contexts, user, level, fingerprint.But then up the page a bit from that:
If you come across any usages of "extra" (setExtra in code) or "Additional Data" (in the UI), just mentally substitute it for context. Extra is deprecated in favor of context.So what is the recommended approach?
Thanks! Have updated my comment too