-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
How to pass extra data via captureException/captureMessage in latest sdk #1607
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
Comments
Same problem here, and it's quite a bad news, because we're loosing all the information about current errors And we can't go back to previous Raven version due to CDN issues ... |
Chaps, I've been running into the same issues. Check out this. Sentry.configureScope(scope => {
scope.setExtra('battery', 0.7);
scope.setTag('user_mode', 'admin');
scope.setUser({ id: '4711' });
// scope.clear();
}); Doesn't feel as nice as the Raven setup. I suggest wrapping Sentry in a client so you can set tags, userContext etc as you send the error. |
Yeah, I've sound the same solution, but indeed, it's less sexy
|
setExtra might be the workaround, but you need to clear extra, that is annoying. |
@Nabellaleen what issues exactly? Docs on scopes: https://docs.sentry.io/learn/scopes/?platform=browser
You don't need if you use
You can still achieve this with mentioned There're a lot of reasons why we changed API. But it basically allows us to use event processors and handle states more efficiently in complex apps. |
@kamilogorek thanks, I will try with |
I believe main issue was resolved. Feel free to let me know if it should be reopened. |
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 |
You can if you use promises the client directly, as we return async function from capture calls internally – #1449
We've been there already and it was very hard to maintain and extend.
|
Hello in 2019. It's SO ANNOYING that I can't just pass context as the second parameter in If anyone came up with an elegant workaround/wrapping method please post! |
😐😐😐😐😐😐😐 |
@emmya that's way more code than you need :) export const reportToSentry = ([error, context = {}]) => Sentry.withScope(scope => {
scope.setTags(context.tags);
scope.setExtras(context.extra);
Sentry.captureException(error);
}) We handle string errors just fine unless you specifically want "message" level on purpose. You can also pass a whole object to |
I don't understand why there can't be an overload for Now I have this in all my projects: export function sentryMessage(message: string, extra?: object, skipLogging: boolean = false) {
Sentry.withScope(scope => {
if (extra) {
for (const key in extra) {
scope.setExtra(key, extra[key])
}
}
scope.setLevel(Sentry.Severity.Info)
Sentry.captureMessage(message)
if (!skipLogging && (!env.SENTRY_URL || env.NODE_ENV === env.Environments.Test)) {
logger.warn(message, extra)
}
})
}
export function sentryException(err: Error, extra?: object, skipLogging: boolean = false) {
Sentry.withScope(scope => {
if (extra) {
for (const key in extra) {
scope.setExtra(key, extra[key])
}
}
scope.setLevel(Sentry.Severity.Error)
Sentry.captureException(err)
if (!skipLogging && (!env.SENTRY_URL || env.NODE_ENV === env.Environments.Test)) {
logger.error(err.message, extra)
}
})
} 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. |
@Christilut we already discussed it plenty of times, externally and internally. And the majority conclusion was that it's much more flexible and easier to maintain this way. Without it, some integrations would simply not be possible. Not to mention that adding it now, would mean that we'd have to synchronize event data, scope data and additionally passed data. It'd just be too fragile. The way it's written is, yes, very verbose, I agree with that, but it's also easier to track where the ata comes from when necessary. FWIW you don't have to iterate over keys yourself, as well as you don't have to set the levels, as those are defaults. This effectively makes your code way too longer than it should be. Here's a shorter, yet functionally equivalent snippet: export function sentryMessage(message: string, extra?: object, skipLogging: boolean = false) {
Sentry.withScope(scope => {
scope.setExtras(extra)
Sentry.captureMessage(message)
if (!skipLogging && (!env.SENTRY_URL || env.NODE_ENV === env.Environments.Test)) {
logger.warn(message, extra)
}
})
}
export function sentryException(err: Error, extra?: object, skipLogging: boolean = false) {
Sentry.withScope(scope => {
scope.setExtras(extra)
Sentry.captureException(err)
if (!skipLogging && (!env.SENTRY_URL || env.NODE_ENV === env.Environments.Test)) {
logger.error(err.message, extra)
}
}) |
Thanks. I guess it's a necessary evil then, too bad but sometimes you don't have a choice :/ |
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, ....}); ? |
Hey guys, this does look ridiculous. Did you see competitors' API?
|
That's exactly what I'm looking for - Won't be hard to code, wont't it ;) |
We will add something like this, thanks all for the feedback! |
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 Sentry.captureException(new Error("something went wrong"), {
tags: {
section: "articles",
}
}); |
Hey @jpbow , I just used the link you shared and its broken, maybe you wanted to refer to this link? https://docs.sentry.io/platforms/javascript/enriching-error-data/additional-data/manage-context/ |
Thanks! Have updated my comment too |
In those doc links:
But then up the page a bit from that:
So what is the recommended approach? |
@vincerubinetti using |
I literally just want to add a simple string message alongside the error, is that even doable ? |
For a simple text message together with function captureError(err, msg, data) {
Sentry.captureException(err, scope => {
if (msg)
scope.addBreadcrumb({
type: "error", // predefined types
category: "error",
level: Sentry.Severity.Error,
message: msg
});
if (data)
scope.setContext("extra-data", data);
});
} |
Only about extra data I usage sentry 6.16.1
https://docs.sentry.io/platforms/javascript/guides/electron/enriching-events/context/ |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
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 ?
The text was updated successfully, but these errors were encountered: