Setting sentry's context
So I recently upgraded to the latest snapshot, and I'm trying to migrate this:
First thing I tried was to replace
captureException
with captureThrowable
.
This sentry
instance is coming from EventContext
in a custom KordEx
event.Solution:Jump to solution
See the announcement I just made - I've added two parameters to the capture functions, which should be sufficient
34 Replies
Using captureThrowable is correct, yes
I don't think you need to add the guild context? I'm pretty sure we do that for you
ah, no, that's just for things you don't catch
anyway, I think probably adding contexts to the sentry context might be an approach? I'm not sure tbh
the sentry context objects are meant to be transactional, in that they're tied to the execution of an event handler, command, component, etc
so it's more intended for you to add breadcrumbs than directly add context
but I should be able to expose that
ok, I've extended the API a bit
will build and release
Solution
See the announcement I just made - I've added two parameters to the capture functions, which should be sufficient
Perfect! Thank you!
I don't think you need to add the guild context? I'm pretty sure we do that for youEither way it is not an event that has a specific guild attached to it, but rather, it finds the relevant guilds where it has to announce something. In this context, I want to log reasons for why an announcement could not be made to a guild. Any way, I guess it is better to set the guild's object in the lambda for that instead 🤔
huh?
There's no guild propery in that builder
There is,
SentryCapture.guild
oh yeah, you're right
I forgot about that
wait but then the API change I made doesn't make sense
what is character in this case?
the RPG character from before?
Yes
because it feels to me like it doesn't make sense to only add this context to the Sentry context when an exception happens
like it'd make much more sense to have a generic breadcrumb that's like "Loaded character" with the data earlier on
beginning to remember why I implemented it the way I did now
I should leave more notes in my code
yeah, so you'd just do like
To be honest, I'm not exactly sure how breadcrums display in sentry or work.
In another component of my project that uses sentry directly, I'm also using context on exceptions, so I can see them attached to the issue like:
I see
well, breadcrumb data generally just displays as an object, so maybe being able to add to the primary context makes sense
but
I don't think it makes sense to only do that at submission time
that results in a lot of duplicated code
instead, I think it might be better to either use a breadcrumb, or swap to an API that allows you to store extra context at the SentryContext level, and then have that submitted whenever anything is captured
that makes the most sense to me, at least
this is largely because kordex itself will submit things to sentry
like if you run a command and there's an uncaptured exception
you probably still want the context on sentry
this needs a fair bit more engineering than what I pushed this morning, but does it seem like a better approach to you?
in that sense it'd be
sentry.context("character", whatever)
and then just don't catch the exception
(or rethrow it, or handle it yourself and just call the capture function)That reminds me I did have a command error, but the issue raised on issue had no info about the command that was used. i don't know if it was lost due to the exception happening inside a component's callback 🤔
that's what happened, yeah
But that was a separate issue, and that was still on 1.6.0, hence why I'm upgrading, so I can test that again and not report an unsupported version 😅
I couldn't figure out how to handle an optional command/eventhandler coupling with component builders without rewriting half the library so I didn't
I have a lot of those 🙃 , usually confirmation messages for important actions
the API is too generic to be tied to the parent builders
but anyway that's a different problem
what do you think of my proposal above
Yeah, I was checking sentry docs to see how that would look and it looks good to me:
How do capturing event and messages work? Specially with free tier quotas? 🤔
Not sure on the quotas
I think the correct attitude to developing with the Sentry extension is probably worth documenting when I eventually get to that
I've only had experience with Sentry on python before but using it on python is like cheating, way too much info available without doing much, it just shows you all the values of variables in the scope right there:
Also not much documentation for kotlin, specially coroutines
Sentry doesn't actually support Kotlin
It's just the Java library
I think the JVM is capable of collecting some of that kind of info, but it would be slow probably
There is a Kotlin extension, I was actually having some trouble due to my context being mixed due in coroutines (in another module without kordex), like it would contain the context of a different part of the code.
So I had to do some changes for that. Maybe it would be worth looking into it for kordex too:
https://docs.sentry.io/platforms/java/enriching-events/scopes/#kotlin-coroutines
Scopes and Hubs
SDKs will typically automatically manage the scopes for you in the framework integrations. Learn what a scope is and how you can use it to your advantage.
This doesn't look useful for kordex
Actual Sentry scopes don't get created until just before they're submitted
The global API is avoided entirely
Sentry's global API is a horrible anti-pattern
Then maybe I should look into that lol, in my other modules, because what I have on these other modules doesn't seem very good lol
Anyway, thanks for the help!
No worries, I am going to change this API again though so don't get too comfortable
I'll do a version bump tho
Yeah, I'm going to stick with breadcrums instead like you suggested, sorry for the confusion
Alright, no worries
Don't want to open yet another thread on sentry, but I found a small issue on the recent changes to contexts. Seems like contexts have to be objects (or maps):
Got this on Sentry:
https://github.com/Kord-Extensions/kord-extensions/commit/a0445169c9bcc01d432a18bca420f6bcba171eb9
Because you are setting
extension
to be just a string.Oh, huh, it needs to be an object?
yes
Thanks for the heads up, I'll look at it tomorrow
Just a bit of a shameless "bump", but I opened a PR related to this a couple of weeks ago:
https://github.com/Kord-Extensions/kord-extensions/pull/295
GitHub
Change extension name sentry context to a mapping by Galarzaa90 · P...
We discussed this briefly on Discord: https://canary.discord.com/channels/1121419906995458098/1210756178515206164
But basically, Sentry is expecting an object, not a single value, so it shows this ...