|
1 | 1 | import { NowRequest } from '@now/node/dist';
|
2 | 2 | import * as Sentry from '@sentry/node';
|
3 |
| -import get from 'lodash.get'; |
4 | 3 | import { isBrowser } from '@unly/utils';
|
| 4 | +import get from 'lodash.get'; |
5 | 5 |
|
6 |
| -/** |
7 |
| - * Initialize Sentry and export it. |
8 |
| - * |
9 |
| - * Helper to avoid duplicating the init() call in every /pages/api file. |
10 |
| - * Also used in pages/_app for the client side, which automatically applies it for all frontend pages. |
11 |
| - */ |
12 |
| -Sentry.init({ |
13 |
| - dsn: process.env.SENTRY_DSN, |
14 |
| - enabled: process.env.NODE_ENV !== 'test', |
15 |
| - environment: process.env.APP_STAGE, |
16 |
| - release: process.env.APP_VERSION_RELEASE, |
17 |
| -}); |
| 6 | +// Don't initialise Sentry if SENTRY_DSN isn't defined (won't crash the app, usage of the Sentry lib is resilient to this and doesn't cause any issue) |
| 7 | +if (process.env.SENTRY_DSN) { |
| 8 | + /** |
| 9 | + * Initialize Sentry and export it. |
| 10 | + * |
| 11 | + * Helper to avoid duplicating the init() call in every /pages/api file. |
| 12 | + * Also used in pages/_app for the client side, which automatically applies it for all frontend pages. |
| 13 | + */ |
| 14 | + Sentry.init({ |
| 15 | + dsn: process.env.SENTRY_DSN, |
| 16 | + enabled: process.env.NODE_ENV !== 'test', |
| 17 | + environment: process.env.APP_STAGE, |
| 18 | + release: process.env.APP_VERSION_RELEASE, |
| 19 | + }); |
18 | 20 |
|
19 |
| -if (!process.env.SENTRY_DSN && process.env.NODE_ENV !== 'test') { |
20 |
| - // eslint-disable-next-line no-console |
21 |
| - console.error('Sentry DSN not defined'); |
22 |
| -} |
| 21 | + if (!process.env.SENTRY_DSN && process.env.NODE_ENV !== 'test') { |
| 22 | + // eslint-disable-next-line no-console |
| 23 | + console.error('Sentry DSN not defined'); |
| 24 | + } |
23 | 25 |
|
24 |
| -// Scope configured by default, subsequent calls to "configureScope" will add additional data |
25 |
| -Sentry.configureScope((scope) => { // See https://www.npmjs.com/package/@sentry/node |
26 |
| - scope.setTag('appVersion', process.env.APP_VERSION); |
27 |
| - scope.setTag('nodejs', process.version); |
28 |
| - scope.setTag('nodejsAWS', process.env.AWS_EXECUTION_ENV || null); // Optional - Available on production environment only |
29 |
| - scope.setTag('memory', process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE || null); // Optional - Available on production environment only |
30 |
| - scope.setTag('runtimeEngine', isBrowser() ? 'browser' : 'server'); |
31 |
| - scope.setTag('buildTime', process.env.BUILD_TIME); |
32 |
| -}); |
| 26 | + // Scope configured by default, subsequent calls to "configureScope" will add additional data |
| 27 | + Sentry.configureScope((scope) => { // See https://www.npmjs.com/package/@sentry/node |
| 28 | + scope.setTag('appVersion', process.env.APP_VERSION); |
| 29 | + scope.setTag('nodejs', process.version); |
| 30 | + scope.setTag('nodejsAWS', process.env.AWS_EXECUTION_ENV || null); // Optional - Available on production environment only |
| 31 | + scope.setTag('memory', process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE || null); // Optional - Available on production environment only |
| 32 | + scope.setTag('runtimeEngine', isBrowser() ? 'browser' : 'server'); |
| 33 | + scope.setTag('buildTime', process.env.BUILD_TIME); |
| 34 | + }); |
| 35 | +} |
33 | 36 |
|
34 | 37 | /**
|
35 | 38 | * Configure the Sentry scope by extracting useful tags and context from the given request.
|
|
0 commit comments