nuxt-community / sentry-module

Sentry module for Nuxt 2
https://sentry.nuxtjs.org
MIT License
501 stars 114 forks source link

Manually start replay #673

Closed JeffAroma closed 3 months ago

JeffAroma commented 3 months ago

Hi,

We would like to start manually replays (on a specific page) but I couldn't find a way to do it. I've tried to look at the $sentry object but didn't find a way to do it. I've also tried to use the official Sentry documentation and do it manually as specified but I got the Error: Multiple Sentry Session Replay instances are not supported error. Do you have an idea on how to do it?

Versions: @nuxtjs/sentry@^8.0.7 @sentry/core@7.100.1

rchl commented 3 months ago

What have you tried exactly? Have you tried https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/#lazy-loading-replay ?

JeffAroma commented 3 months ago

I've tried:

import * as Sentry from '@sentry/vue';
...
const replay = Sentry.getReplay();
replay.start();

but getReplay() does not exist.

I've also tried

import * as Sentry from '@sentry/vue';
...
const replay = Sentry.replayIntegration();
replay.start();

but here I get the afore mentioned error.

Here is my config of Sentry:

sentry: {
    lazy: false,
    clientIntegrations: {
      Replay: {
        maskAllText: false,
        blockAllMedia: false,
      },
    },
    release: {
      setCommits: {
        auto: true,
      },
    },
    publishRelease: {
      authToken: process.env.SENTRY_AUTH_TOKEN,
      org: process.env.SENTRY_ORG,
      project: process.env.SENTRY_PROJECT,
      errorHandler(error) {
        console.error(`Sentry Release Error: ${error.message}`);
      },
    },
    clientConfig: {
      // This sets the sample rate to be 10%. You may want this to be 100% while
      // in development and sample at a lower rate in production
      replaysSessionSampleRate: 0,
      // If the entire session is not sampled, use the below sample rate to sample
      // sessions when an error occurs.
      replaysOnErrorSampleRate: 0,
    },
  },
rchl commented 3 months ago

The Sentry documentation says not the enable the integration globally. So remove Replay from clientIntegrations.

Then something like this might work but haven't tried:

            const Sentry = await import('@sentry/vue');
            Sentry.addIntegration(Sentry.replayIntegration());

Note that you have to ensure that this code doesn't execute on the server-side since it's a client-only integration.

JeffAroma commented 3 months ago

Thanks for advice, unfortunately I get the same error.

rchl commented 3 months ago

You would need to create an example project that reproduces the issue for me to look into it.

Or at least show exactly where you are executing this code from.

JeffAroma commented 3 months ago

It seems that I messed something up earlier. I've retested your snippet and it does work! Thanks for your (really quick) help on this.