-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CaptureContext in captureMessage disallows the level to be set. #2819
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
From global singleton: Sentry.captureMessage('wat', {
tags: {
some: 'value'
},
level: Sentry.Severity.Warning
}); From the hub: const hub = Sentry.getCurrentHub();
hub.captureMessage('wat', Sentry.Severity.Warning, {
captureContext: {
tags: {
wat: 1337
},
}
});
// or
hub.captureMessage('wat', null, {
captureContext: {
level: Sentry.Severity.Warning,
tags: {
wat: 1337
},
}
}); From the client: same as with hub, but it also accepts const client = Sentry.getCurrentHub().getClient();
const scope = new Sentry.Scope();
scope.setTag('wat', 1337);
client.captureMessage('wat', Sentry.Severity.Warning, {}, scope); This API change was added after the major version release as the part of ongoing change, that's why it's not unified across all the layers. It's one of the things that we'll fix in the upcoming major v6 version - #2817 Cheers! |
Thanks for showing the various ways to send the event. The first way is the way I was using and I think is where there is a bug. :) Rather than using
And it resulted in the error I linked at the top of the report. I have it working now with The majority of the error report described what I thought was causing it. |
The issue that you linked (which cased a parsing error on the server-side) is using SDK version |
I don't track your change log closely enough to know the version the bug was introduced. I only pointed out where I think the commit was that introduced the bug. But, I can observe the bug on the latest version. Feel free to try for yourself or leave it as is if you wish. I have a workaround, but it looks like there's a bug in there as I described. :) Have a good one, |
What I meant is that the issue you linked used the SDK version where this API didn't even exist, so it's given that it'll produce an error. I just tried the code from my initial answer using the lastest version: Sentry.captureMessage('wat', {
tags: {
some: 'value'
},
level: Sentry.Severity.Warning
}); And it produces no error. Am I missing something? |
🤦 The confusion here is my fault. I didn't realize I linked the top level issue rather than the specific event. Let's start over. :) This is the specific event that exhibits the error. The error is not returned in code from the SDK. What I meant is that I see an error in the sentry console itself for the event. Here's a picture of exactly what I mean: I was doing this to capture that message: Sentry.captureMessage(msg, {
tags: { ...tags, logMsg: true },
extra: { ...extra, msg },
level
})
Using similar code as above for Using this code for Sentry.withScope(scope => {
scope.setTags({ ...tags, logMsg: true })
scope.setExtra({ ...extra, msg })
// eslint-disable-next-line no-undef
Sentry.captureMessage(msg, level)
}) All the analysis from my initial message was about why this might be (i.e., that The 5.15.5 report in the sentry UI is due to a pinned version from another dependency we have ( For reference, we're using React with gatsby as our stack. |
Thanks for pointing out the 5.15.5 version. The issue was a library version conflict. 5.15.5 was being referenced through a dependency from Thanks for your help. |
Great to hear that! I was wondering if I'm missing something or I cannot understand a basic question anymore 😅 |
Unrelated to the initial bug, but that issue still shows 5.15.5 for new events even with our library updated. Perhaps the version is determined by the first event or is related to the merging of events into a related issue? E.g., this guy was logged today and definitely is from the 5.21.1 version of the SDK: https://sentry.io/organizations/goodpath/issues/1839387297/events/ec82147e1e92486697c21b9d43eab2c1/?project=1812305&statsPeriod=7d |
@stuckj the event that you linked, points to deploy preview Maybe some stale cache? on netlify? |
Ah, it was an event from a deploy preview instead of production. I see the latest events in that issue now are properly showing |
No worries, cheers! :) |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
This issue here describes the bug I'm going to explain below.
The change in
captureMessage
in the node SDK introduced in #2627 changedcaptureMessage
to be able to accept a context to apply to the message. This is handy. However, you can't specify both a context and a severity. I tried to do so by simply specifying thelevel
in the context, but I'm seeing the error in the linked issue above that indicates that the value for level was discarded because it was invalid. I believe it was telling me it was blank (though that wasn't super clear in the error).I traced through the code a bit and it appears this is because the generated JS parses out EITHER the level or the context and passes them on to your hub function. This is what I see in the generated JS (from your TS) off npm:
When you pass a context to
captureMessage
, thecallOnHub
will get anundefined
level and the context. Then in your hub handler (see generated JS below):It just passes the level on through to the client. The code's internal at that point, but I'm guessing you're just basically passing that on to your server with the separate level and context and your server is using the passed level and ignoring the level in the context.
I think you can fix this either in the server code (to use the context if the passed level is undefined) or in the node code by populating the level from the context if there is a level in the context (e.g, either in your hub method or the API method).
I can work around it for now by just wrapping the call with a
withScope
, it'd be nice to fix though since that was kinda the point of #2627. :)The text was updated successfully, but these errors were encountered: