#Sentry replay error sampling (beforeErrorSampling callback not working as expected)

13 messages · Page 1 of 1 (latest)

hazy cosmos
#

I am receiving session replays for all errors, even when beforeErrorSampling returns false. I'm using @sentry/vue version 8.47.0. It seems that the beforeErrorSampling callback is never called. The integration is included in replayIntegration, and replaysOnErrorSampleRate is set to 1.0.

Perhaps I’m misunderstanding something. The documentation is not very detailed: https://docs.sentry.io/platforms/javascript/session-replay/understanding-sessions/#ignore-certain-errors-for-error-sampling

For example, I’m unsure whether replaysOnErrorSampleRate correlates with beforeErrorSampling or if beforeErrorSampling completely overrides it. Regardless, it seems that beforeErrorSampling is never called. What am I missing?

I want to filter out replays for specific errors, such as:
Error: Failed to fetch https://api.mapbox.com/v4/mapb....

If the error message includes "Failed to fetch https://api.mapbox.com/", I return false in beforeErrorSampling(). However, this does not work. Why?

Learn about customizing sessions with the Session Replay SDK.

frail bronze
#

Is it possible that the replays are captured via the normal replaysSessionSampleRate? What have you set that value to?

hazy cosmos
#

replaysSessionSampleRate: 0

hazy cosmos
#

Any other ideas?

frail bronze
#

Can you share all the code from your app that seems relevant to you?

hazy cosmos
#
const integrations = [
    Sentry.replayIntegration({
        maskAllText: false,
        blockAllMedia: false,
        beforeErrorSampling: (error) => {
            const excludedErrorsContaining = [
                "AxiosError: Network Error",
                "Failed to fetch https://api.mapbox.com",
            ];

            // Skip sampling if the error message includes any of the excluded substrings
            return !excludedErrorsContaining.some((substring) =>
                error.message?.includes(substring),
            );
        },
    }),
    Sentry.replayCanvasIntegration(),
    Sentry.extraErrorDataIntegration(),
    Sentry.browserTracingIntegration(),
    Sentry.captureConsoleIntegration({
        levels: ["error", "debug"],
    }),
];


Sentry.init({
    app,
    dsn: import.meta.env.VITE_SENTRY_LARAVEL_DSN,
    integrations: integrations,
    tracesSampleRate: 0.5,
    replaysSessionSampleRate: 0,
    replaysOnErrorSampleRate: 1.0,
    ignoreErrors: ["canvas.contentDocument", "conduitPage"],
    denyUrls: [/mapbox\.com/i, /^chrome-extension:\/\//i],
});
frail bronze
#

are you 100% sure that the errors match what you configured in excludedErrorsContaining?

hazy cosmos
#

Looks like I found the problem!

beforeErrorSampling: (error) => {
    console.log("error.message", error.message);
    console.log("error", error);

Console contents:

#

I'm triggering the error by calling: console.log("my_custom_error", abc);

#

What is the proper way to access the error message? In docs it is said error.message but it's undefined...

frail bronze
#

right, the docs are wrong! We'll fix that

#

you should probably look at error.exception.values[0].value