-
Notifications
You must be signed in to change notification settings - Fork 63
Capturing Issue Description in Sentry #1707
Conversation
src/stores/media/index.ts
Outdated
@@ -385,6 +387,11 @@ export const useMediaStore = defineStore('media', { | |||
error.response?.status ?? 'unknown' | |||
}` | |||
} else { | |||
/*Capture the error and all of its details using $sentry */ | |||
Sentry.captureEvent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside of Pinia stores you can access the pre-configured Sentry instance via this.$nuxt.$sentry
. In this case I think it'd make sense to use captureException
explicitly when an error is caught. For the case where we set the message to "Oops! Something went wrong", if we could capture the event with something more specific that would be great. Maybe captureMessage
is better in that case. I'm not totally sure of the difference. Do you happen to know?
@obulat and @dhruvkb do y'all know when that "Oops! Something went wrong" clause happens and what it's meant to handle?
BTW, to test this, I threw an arbitrary error in fetchSingleMediaType before setMedia
is called and then a breakpoint in my browser debugger on this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside of Pinia stores you can access the pre-configured Sentry instance via
this.$nuxt.$sentry
.
I tried accesing it this way before but it keeps failing when i run pnpm test with the error "Cannot read properties of undefined (reading 'captureException')"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! You've got to mock out context variables in tests. You can add $nuxt and the $sentry mock to this Pinia test utility we use:
openverse-frontend/test/unit/test-utils/pinia.js
Lines 4 to 9 in b863e3e
export const createPinia = () => | |
pinia.createPinia().use(() => ({ | |
$nuxt: { | |
$openverseApiToken: '', | |
}, | |
})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we could capture the event with something more specific that would be great. Maybe captureMessage is better in that case. I'm not totally sure of the difference.
According to sentry docs, we can pass a non-error object to captureException tho it will lack the context. You can pass an Error object to captureException() to get it captured as event. It's also possible to pass non-Error objects and strings, but be aware that the resulting events in Sentry may be missing a stacktrace.
Capture event triggers a manual event, that means we recieve all the breadcumbs that were collected until that moment. We can also include a dump of the application if we are sure we won't surpass the event payload max size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I think better not to dump the application. If we need it to debug a particular error that sounds like a great feature though, thanks for sharing it.
Do whatever you think is best vis a vis which Sentry function to use 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then i believe capture event is the best option, as we can enrich the event data as we see fit
I'm not sure what the scope of this PR is, @ramadanomar, but it would be nice to re-write the Please, feel free to leave this PR as is, and we can develop more in future PRs, too. For instances of Axios errors:In case the error has a
|
Hey! Thanks for the feedback. My scope was to provide more context to audio errors. I am pushing an updated handleMediaError function right now. As of toJSON, i am not sure when this error is called to determine how much info we need. The new handleMediaError function should allow for easy changes in case we need to edit the level of detail we require. |
Co-authored-by: Olga Bulat <obulat@gmail.com>
Co-authored-by: Olga Bulat <obulat@gmail.com>
@obulat From my perspective all failed requests that we don't know how to explicitly handle should be captured in Sentry so that we can be aware of them and either (a) handle those explicitly or (b) explicitly ignore them as non-issues or unsolveable. Does that seem like a reasonable standard? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change will definitely help us fix more errors! I've left a couple of nit-picky formatting comments, other that that it's good to go 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Haven't run it locally yet but I anticipate it being fine. My only request is to expand the unit tests to cover the two new branches and to confirm that captureEvent
is called as we expect.
Co-authored-by: Olga Bulat <obulat@gmail.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Any idea on how i could mock the sentry capture event without importing jest.mock('axios', () => ({
...jest.requireActual('axios'),
isAxiosError: jest.fn((obj) => 'response' in obj),
})) but couldn't seem to be able to deconstruct the event properly. Any pointers on how i could approach this? Thanks! |
@ramadanomar, to mock Sentry centrally, you can add this snippet to
You can also add any other functions that need to be mocked. |
Then, for example, on line 385 in
Please note that you would also need to add |
@ramadanomar, I've opened a PR in your fork with some more tests for different branches of error handling. I would really be happy to approve after those tests are added. |
Add more tests for Axios and non-Axios errors
I've merged your pr @obulat. Thanks for the help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all your work on this PR, @ramadanomar ! It will be really valuable in triaging Sentry issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Related to
Related to #1604 by @sarayourfriend
Description
Not sure on when how to reproduce this issue, but this should return the whole exception to provide more context.