22/* eslint import/no-nodejs-modules:0 */
33
44import React from 'react' ;
5+
56import PageContext from 'sentry-docs/components/pageContext' ;
67
8+ const sentryEnvironment = process . env . GATSBY_ENV || process . env . NODE_ENV || 'development' ;
9+ const sentryLoaderUrl = process . env . SENTRY_LOADER_URL ;
10+
711export const wrapPageElement = ( { element, props : { pageContext} } ) => (
812 < PageContext . Provider value = { pageContext } > { element } </ PageContext . Provider >
913) ;
@@ -28,7 +32,41 @@ export const onPreRenderHTML = ({getHeadComponents}) => {
2832 } ) ;
2933} ;
3034
35+ function SentryLoaderScript ( ) {
36+ return (
37+ < script key = "sentry-loader-script" src = { sentryLoaderUrl } crossOrigin = "anonymous" />
38+ ) ;
39+ }
40+
41+ function SentryLoaderConfig ( ) {
42+ return (
43+ < script
44+ key = "sentry-loader-config"
45+ dangerouslySetInnerHTML = { {
46+ __html : `
47+ Sentry.onLoad(function() {
48+ Sentry.init({
49+ integrations: [
50+ new Sentry.Replay({
51+ unmask: ['.hover-card-link'],
52+ }),
53+ ],
54+ tracesSampleRate: ${ sentryEnvironment === 'development' ? 0 : 1 } ,
55+ replaysSessionSampleRate: ${ sentryEnvironment === 'development' ? 0 : 0.1 } ,
56+ replaysOnErrorSampleRate: ${ sentryEnvironment === 'development' ? 0 : 1 } ,
57+ });
58+ });` ,
59+ } }
60+ />
61+ ) ;
62+ }
63+
3164export const onRenderBody = ( { setHeadComponents} ) => {
65+ // Sentry SDK setup
66+ if ( sentryLoaderUrl ) {
67+ setHeadComponents ( [ SentryLoaderScript ( ) , SentryLoaderConfig ( ) ] ) ;
68+ }
69+
3270 setHeadComponents ( [
3371 // Set up the data layer, enable privacy defaults
3472 < script
0 commit comments