Skip to content

Documentation: Clarify ReplayIntegration with beforeErrorSampling in session / buffer mode #15470

@ramonwenger

Description

@ramonwenger

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/vue

SDK Version

9.1.0

Framework Version

Vue 3.2.30

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

When going with the current documentation for filtering out certain errors on the sessions page, the following would not work, e.g. the beforeErrorSampling never be called, the message would not be logged.

    Sentry.init({
      app,
      dsn: '...', // truncated for the obvious reasons
      integrations: [
        Sentry.browserTracingIntegration({ router }),
        Sentry.replayIntegration({
          beforeErrorSampling: (event) => {
            console.log("I'm just here error sampling");
            // actual sampling being done here
            return true;
          },
        }),
      ],
      tracesSampleRate: 1,
      replaysSessionSampleRate: 0.0,
      replaysOnErrorSampleRate: 1.0,

    });

Expected Result

The beforeErrorSampling function should be called, and there should be a log message in the console.

Actual Result

Nothing is logged to the console, the function never gets called.

The reason for this is that, for the beforeErrorSampling function to be called, the replay session apparently needs to be in "buffer" mode instead of "session" mode. This is not explained very clearly, especially not in the part of the documentation dealing with the "beforeErrorSampling" option, neither on the page linked above nor on the configuration page.

The documentation also states this about buffering mode:

If replaysOnErrorSampleRate > 0, we'll start recording in buffering mode and keep checking replaysOnErrorSampleRate whenever an error occurs. Once we see that it's sampled, we'll upload the Replay to Sentry and continue recording normally.

This is not quite true however, as the mode also seems to somehow depend on the stickySession variable, as when it is set to true (as it is by default), then the session mode always seems to be session, and only after explicitly setting it to false the session is not buffer and the beforeErrorSampling starts being called. This works for me:

    Sentry.init({
      app,
      dsn: '...', // truncated for the obvious reasons
      integrations: [
        Sentry.browserTracingIntegration({ router }),
        Sentry.replayIntegration({
          stickySession: false,
          beforeErrorSampling: (event) => {
            console.log("I'm just here error sampling");
            // actual sampling being done here
            return true;
          },
        }),
      ],
      tracesSampleRate: 1,
      replaysSessionSampleRate: 0.0,
      replaysOnErrorSampleRate: 1.0,

    });

I'm not sure if this is just a documentation issue, of if the stickySession should not have any influence and this is a bug.
The integration tests seem to indicate that it's intentional, as they're explicitly setting the variable to false.

Metadata

Metadata

Assignees

Labels

BugPackage: replayIssues related to the Sentry Replay SDK

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions