Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

loader script: configure replay options #8704

Answered by AbhiPrasad
mustafa0x asked this question in Q&A
Discussion options

I'm using the js-sdk-loader, which loads bundle.tracing.replay.min.js. My question is how to configure the replay options?

I tried this, but it didn't always work (due to minification, and onLoad, when loading the page the second time, was firing before all integrations were loaded).

Sentry.onLoad(() => {
 const {client} = Sentry.getCurrentHub().getStack()[0]
 Object.assign(client._integrations.Replay._recordingOptions, {maskAllInputs: false, maskAllText: false}) 
})

I settled on loader.replace(/new \w+.Replay/, '$&({maskAllInputs: false, maskAllText: false})') but it's a bit hacky.

Related: it's also difficult to send the release slug when using the loader. Perhaps if a global variable can be set, that the loader reads from if present (similar to window._sentryDebugIds).

You must be logged in to vote

Hey @mustafa0x

My question is how to configure the replay options

You can call Sentry.init again in Sentry.onLoad and configure the replay integration there.

Sentry.onLoad(() => {
 Sentry.init({
 tracesSampleRate: 1.0,
 replaysSessionSampleRate: 0.1,
 replaysOnErrorSampleRate: 1.0,
 integrations: [
 new Sentry.Replay({
 maskAllInputs: false,
 maskAllText: false,
 }),
 new Sentry.BrowserTracing(),
 ],
 });
});

I heavily recommend setting maskAllInputs to false though as you could be sending PII or other sensitive information to Sentry.

Related: it's also difficult to send the release slug when using the loader. Perhaps if a global variable ...

Replies: 1 comment 5 replies

Comment options

Hey @mustafa0x

My question is how to configure the replay options

You can call Sentry.init again in Sentry.onLoad and configure the replay integration there.

Sentry.onLoad(() => {
 Sentry.init({
 tracesSampleRate: 1.0,
 replaysSessionSampleRate: 0.1,
 replaysOnErrorSampleRate: 1.0,
 integrations: [
 new Sentry.Replay({
 maskAllInputs: false,
 maskAllText: false,
 }),
 new Sentry.BrowserTracing(),
 ],
 });
});

I heavily recommend setting maskAllInputs to false though as you could be sending PII or other sensitive information to Sentry.

Related: it's also difficult to send the release slug when using the loader. Perhaps if a global variable can be set, that the loader reads from if present (similar to window._sentryDebugIds).

You can set the window.SENTRY_RELEASE.id variable as a global variable for the release. See the code here:

// This supports the variable that sentry-webpack-plugin injects
if (WINDOW.SENTRY_RELEASE && WINDOW.SENTRY_RELEASE.id) {
options.release = WINDOW.SENTRY_RELEASE.id;
}

Docs: https://docs.sentry.io/platforms/javascript/install/loader/#sdk-configuration

You must be logged in to vote
5 replies
Comment options

Thanks @AbhiPrasad, appreciated! I can also set the release in .init() too, right? Since I'm calling it anyways.

Comment options

I can also set the release in .init() too, right?

Yup you can!

Comment options

Is this answer still valid?
I'm using the Loader Script SDK 8.x with Enable Session Replay switched on.
But I get an error when trying to adjust maskAllText

<script>
window.sentryOnLoad = () => {
 Sentry.init({
 integrations: [
 new Sentry.Replay({
 maskAllText: false,
 }),
 ],
 });
};
</script>
<script src="url-copied-from-sentry-control-panel" crossorigin="anonymous"></script>

produces the following error:
TypeError: Sentry.Replay is not a constructor

Otherwise, Sentry works as expected, but I'd like to find a way to keep the text from being masked on session replays.

PS. Poking around at the Sentry object, this seems to work without throwing errors, but I'm hesitant to use it since .me isn't documented anywhere:
window.Sentry.getClient().getIntegrationByName("Replay").me.maskAllText = false

Comment options

@karlbot Sentry.Replay was renamed to Sentry.replayIntegration in v8 of the SDK.

Comment options

thank you! I had tried that but must've introduced an error somewhere. Anyway can confirm this works:

<script>
 window.sentryOnLoad = () => {
 Sentry.init({
 integrations: [
 Sentry.replayIntegration({
 maskAllText: false,
 }),
 ],
 });
 };
</script>
Answer selected by lforst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /