Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Session Replay "replaysOnErrorSampleRate" variable to accept an array of possible logging levels #9413

Closed
michaelcreatesstuff opened this issue Oct 30, 2023 · 9 comments · Fixed by #9470
Labels
Package: replay Issues related to the Sentry Replay SDK Type: Improvement

Comments

@michaelcreatesstuff
Copy link

Problem Statement

I want to not capture replays for all errors, only errors with a logging level of "error" or "fatal"

I am using Sentry to log events with level "debug". I don't want these included in Session replay

Solution Brainstorm

Allow the user to provide an array of logging levels to include in Session Replay's "replaysOnErrorSampleRate" variable config.

Default this to all logging levels if no value is provided

Thank you!

@mydea
Copy link
Member

mydea commented Nov 2, 2023

Hey,

thanks for writing in!

I think a better way to realise this is to allow to put a property on the event telling replay to ignore this.

E.g. something like this:

Sentry.init({
  beforeSend(event) {
    // if this should not go to replay:
    event.IGNORE_REPLAY = true;
  }
});

cc @billyvg WDYT?

@michaelcreatesstuff
Copy link
Author

@mydea sure, so if we were capturing an exception, it would look like this?

   SentryHelper_captureException(error, {
        level: "debug",
        ignore_replay: true
      });

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 2, 2023
@mydea
Copy link
Member

mydea commented Nov 3, 2023

@mydea sure, so if we were capturing an exception, it would look like this?

   SentryHelper_captureException(error, {
        level: "debug",
        ignore_replay: true
      });

If we go with my idea above, you'd have to add an event processor or a beforeSend callback and add a specified property to each event you want to ignore for replay.

@michaelcreatesstuff
Copy link
Author

If we go with my idea above, you'd have to add an event processor or a beforeSend callback and add a specified property to each event you want to ignore for replay.

Ok, let me make sure I understand correctly.

First I would capture an exception like this:

Sentry.captureException(error, {
  level: "debug",
  extra: {
    ignore_replay: true
  }
}

then in the beforeSend callback I would add this

Sentry.init({
  dsn: "https://**.ingest.sentry.io/**",
  beforeSend(event) {
    if (event.extra.ignore_replay) {
      event.IGNORE_REPLAY = true;
    }
    return event;
  },
});

Is that correct?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 3, 2023
@mydea
Copy link
Member

mydea commented Nov 3, 2023

Yeah, something like this (although the exact API & naming is still open) - but API-wise, that could work I believe!

@michaelcreatesstuff
Copy link
Author

@mydea thank you, that's great to hear. This would be really helpful for us, is this something the Sentry team could implement in the near future?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 6, 2023
@bruno-garcia
Copy link
Member

Do we take hint as a second argument on beforeSend? If so that'd be a better place to set a flag to avoid kicking off the reply.

mydea added a commit that referenced this issue Nov 8, 2023
This adds a new option to `new Replay()` which allows to ignore certain
errors for error-based sampling:

```js
new Replay({
  beforeErrorSampling: (event) => !event.message.includes('ignore me')
});
```

When returning `false` from this callback, the event will not trigger an
error-based sampling.

Note that returning `true` there does not mean this will 100% be
sampled, but just that it will check the `replaysOnErrorSampleRate`. The
purpose of this callback is to be able to ignore certain groups of
errors from triggering an error-based replay at all.

Closes #9413

Related to #8462
(not 100% but partially)
@mydea
Copy link
Member

mydea commented Nov 8, 2023

Hey!

In 7.78.0, you can now configure a callback to replay to solve this:

new Replay({
  beforeErrorSampling(event) {
    // return true to sample for this error, or false to not sample
  }
})

@michaelcreatesstuff
Copy link
Author

Hey!

In 7.78.0, you can now configure a callback to replay to solve this:

new Replay({
  beforeErrorSampling(event) {
    // return true to sample for this error, or false to not sample
  }
})

Thank you so much for the quick turnaround! Much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK Type: Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants