@@ -5,6 +5,9 @@ import React from 'react';
55
66import PageContext from '~src/components/pageContext' ;
77
8+ const sentryEnvironment = process . env . GATSBY_ENV || process . env . NODE_ENV || 'development' ;
9+ const sentryDsn = process . env . GATSBY_SENTRY_DSN ;
10+
811export const wrapPageElement = ( { element, props : { pageContext} } ) => (
912 < PageContext . Provider value = { pageContext } > { element } </ PageContext . Provider >
1013) ;
@@ -29,7 +32,45 @@ export const onPreRenderHTML = ({getHeadComponents}) => {
2932 } ) ;
3033} ;
3134
35+ function SentryLoaderScript ( ) {
36+ return (
37+ < script
38+ key = "sentry-loader-script"
39+ src = { `https://js.sentry-cdn.com/${ sentryDsn } .min.js` }
40+ crossOrigin = "anonymous"
41+ />
42+ ) ;
43+ }
44+
45+ function SentryLoaderConfig ( ) {
46+ return (
47+ < script
48+ key = "sentry-loader-config"
49+ dangerouslySetInnerHTML = { {
50+ __html : `
51+ Sentry.onLoad(function() {
52+ Sentry.init({
53+ integrations: [
54+ new Sentry.Replay({
55+ unmask: ['.hover-card-link'],
56+ }),
57+ ],
58+ tracesSampleRate: ${ sentryEnvironment === 'development' ? 0 : 1 } ,
59+ replaysSessionSampleRate: ${ sentryEnvironment === 'development' ? 0 : 0.1 } ,
60+ replaysOnErrorSampleRate: ${ sentryEnvironment === 'development' ? 0 : 1 } ,
61+ });
62+ });` ,
63+ } }
64+ />
65+ ) ;
66+ }
67+
3268export const onRenderBody = ( { setHeadComponents} ) => {
69+ // Sentry SDK setup
70+ if ( sentryDsn ) {
71+ setHeadComponents ( [ SentryLoaderScript ( ) , SentryLoaderConfig ( ) ] ) ;
72+ }
73+
3374 setHeadComponents ( [
3475 // Set up the data layer, enable privacy defaults
3576 < script
0 commit comments