1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/* eslint-disable no-restricted-imports */
import {
init,
browserTracingIntegration,
// exports
captureException,
SDK_VERSION,
} from '@sentry/browser';
const initSentry = () => {
if (!gon?.sentry_dsn) {
return;
}
const page = document?.body?.dataset?.page;
init({
dsn: gon.sentry_dsn,
release: gon.revision,
allowUrls:
process.env.NODE_ENV === 'production'
? [gon.gitlab_url]
: [gon.gitlab_url, 'webpack-internal://'],
environment: gon.sentry_environment,
autoSessionTracking: true,
// Browser tracing configuration
enableTracing: true,
tracePropagationTargets: [/^\//], // only trace internal requests
tracesSampleRate: gon.sentry_clientside_traces_sample_rate || 0,
integrations: [
browserTracingIntegration({
beforeStartSpan(context) {
return {
...context,
// `page` acts as transaction name for performance tracing.
// If missing, use default Sentry behavior: window.location.pathname
name: page || window?.location?.pathname,
};
},
}),
],
initialScope(scope) {
scope.setTags({
version: gon.version,
feature_category: gon.feature_category,
page,
});
if (gon.current_user_id) {
scope.setUser({
id: gon.current_user_id,
});
}
return scope;
},
});
// The _Sentry object is globally exported so it can be used by
// ./sentry_browser_wrapper.js
// This hack allows us to load a single version of `~/sentry/sentry_browser_wrapper`
// in the browser, see app/views/layouts/_head.html.haml to find how it is imported.
// eslint-disable-next-line no-underscore-dangle
window._Sentry = {
captureException,
SDK_VERSION, // used to verify compatibility with the Sentry instance
};
};
export { initSentry };
|