|
| 1 | +import { APP_VERSION, SENTRY_DSN, SENTRY_ENV } from './env'; |
| 2 | + |
1 | 3 | type SentryConfigType = {
|
2 | 4 | dsn: string;
|
3 | 5 | environment: string;
|
4 | 6 | tracesSampleRate: number;
|
5 | 7 | release: string;
|
| 8 | + replaysSessionSampleRate: number; |
| 9 | + replaysOnErrorSampleRate: number; |
6 | 10 | };
|
7 | 11 |
|
8 | 12 | export const generateSentryConfig = (): SentryConfigType => {
|
9 |
| - let SENTRY_ENVIRONMENT = 'development'; |
10 |
| - let SENTRY_TRACE_SAMPLE_RATE = 1.0; |
11 |
| - switch (import.meta.env.MODE) { |
12 |
| - case 'production': |
13 |
| - SENTRY_ENVIRONMENT = 'production'; |
14 |
| - SENTRY_TRACE_SAMPLE_RATE = 0.1; |
15 |
| - break; |
16 |
| - case 'test': |
17 |
| - SENTRY_TRACE_SAMPLE_RATE = 0.0; |
18 |
| - break; |
19 |
| - case 'development': |
20 |
| - SENTRY_TRACE_SAMPLE_RATE = 0.0; |
21 |
| - break; |
22 |
| - default: |
23 |
| - } |
| 13 | + // This sets the sample rate to be 10%. You may want this to be 100% while |
| 14 | + // in development and sample at a lower rate in production |
| 15 | + const DEV_TRACE_SAMPLE_RATE = 1.0; |
| 16 | + const DEV_REPLAY_SAMPLE_RATE = 0.1; |
| 17 | + const PROD_TRACE_SAMPLE_RATE = 0.1; |
| 18 | + const PROD_REPLAY_SAMPLE_RATE = 0.1; |
24 | 19 |
|
25 | 20 | return {
|
26 |
| - dsn: (!window.Cypress && import.meta.env.SENTRY_DSN) || '', |
27 |
| - environment: SENTRY_ENVIRONMENT, |
28 |
| - tracesSampleRate: SENTRY_TRACE_SAMPLE_RATE, |
29 |
| - release: import.meta.env.APP_VERSION || '', |
| 21 | + // dsn is set only when not running inside cypress |
| 22 | + dsn: (!window.Cypress && SENTRY_DSN) || '', |
| 23 | + environment: SENTRY_ENV, |
| 24 | + tracesSampleRate: import.meta.env.PROD |
| 25 | + ? PROD_TRACE_SAMPLE_RATE |
| 26 | + : DEV_TRACE_SAMPLE_RATE, |
| 27 | + // release is set only when building for production |
| 28 | + release: APP_VERSION, |
| 29 | + |
| 30 | + replaysSessionSampleRate: import.meta.env.PROD |
| 31 | + ? PROD_REPLAY_SAMPLE_RATE |
| 32 | + : DEV_REPLAY_SAMPLE_RATE, |
| 33 | + // If the entire session is not sampled, use the below sample rate to sample |
| 34 | + // sessions when an error occurs. |
| 35 | + replaysOnErrorSampleRate: 1.0, |
30 | 36 | };
|
31 | 37 | };
|
0 commit comments