Open christianvuerings opened 2 days ago
error.__sentry_captured__ = false;
before the useEffect
, but that doesn't seem optimalSentry Logger [log]: Not capturing exception because it's already been captured.
- even for the first time Sentry tries to log the exceptionerror.__sentry_captured__
in app/error.tsx
it's always true
, so something is already capturing the event beforehand but I'm not sure whereautoInstrumentAppDirectory: false,
autoInstrumentServerFunctions: false,
autoInstrumentMiddleware: false,
useEffect
as follows:
useEffect(() => {
Sentry.captureException(error, {
tags: {
"cambly.captureLocationTemp": "nextjsPageErrorPageError",
},
});
}, [error]);
Hey @christianvuerings thanks for writing in!
I think your suspicion that something else is capturing the error before it's caught by the error page is correct. We can probably find out what that is by looking at event.exception.values[0].mechanism
. Would you mind logging this out in your beforeSend
hook and reporting back?
Side-note: I see you'Re calling scope.clear()
which is fairly destructive. Is there a specific reason for that? This pretty much wipes almost everything that the SDK currently stores on the scope for this request, including stuff like trace information. So if your error on the server is throwing an error in the browser, these won't be linked in the Sentry UI. Not the end of the world of course but just a heads-up :)
I think your suspicion that something else is capturing the error before it's caught by the error page is correct. We can probably find out what that is by looking at
event.exception.values[0].mechanism
. Would you mind logging this out in yourbeforeSend
hook and reporting back?
@Lms24 event.exception.values[0].mechanism
always logs instrument
which is the same value as what we see for the exception online:
Assuming this is Sentry auto instrumenting exceptions, should autoInstrumentAppDirectory
set to false
fix this? We tried that and also set autoInstrumentServerFunctions
and autoInstrumentMiddleware
to false
without any luck. It always logs instrument
and does not add the tag.
What we want to achieve is for exceptions that hit the error boundary to get a specific tag - e.g. cambly.captureLocation
set to nextjsPageError
but if Sentry already captures those exceptions, we're not sure how to do that.
Side-note: I see you'Re calling
scope.clear()
which is fairly destructive. Is there a specific reason for that? This pretty much wipes almost everything that the SDK currently stores on the scope for this request, including stuff like trace information. So if your error on the server is throwing an error in the browser, these won't be linked in the Sentry UI. Not the end of the world of course but just a heads-up :)
Thanks for pointing that out. It was just for debugging purposes to see if that would allow us to set the tag and not something we use in production.
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
8.32.0
Framework Version
Next.js 14.2.12
Link to Sentry event
https://cambly-inc.sentry.io/issues/5978793591/?project=234235&query=TEST_ERROR_DEFG_1234&referrer=issue-stream&statsPeriod=7d&stream_index=0
Reproduction Example/SDK Setup
Steps to Reproduce
app/error.tsx
file:import { useEffect, type ReactElement } from "react"; import * as Sentry from "@sentry/nextjs";
export default function Error({ error, reset, }: { error: Error & { digest?: string }; reset: () => void; }): ReactElement { console.log("///// captured before", error.__sentry_captured__); useEffect(() => { Sentry.withScope((scope) => { scope.clear(); scope.setTag("cambly.captureLocationTemp", "nextjsPageErrorAppError"); Sentry.captureException(error); }); }, [error]);
return (
Something went wrong{" "}
); }
Expected Result
Error contains
cambly.captureLocationTemp
tagActual Result
Error does not contain
cambly.captureLocationTemp