Просмотр исходного кода

feat(sentry-plugin): Log error instead of throw error when dsn is not set

David Höck 3 месяцев назад
Родитель
Сommit
0bd9ea6fef
1 измененных файлов с 33 добавлено и 32 удалено
  1. 33 32
      packages/sentry-plugin/instrument.ts

+ 33 - 32
packages/sentry-plugin/instrument.ts

@@ -15,36 +15,37 @@ const SENTRY_CAPTURE_LOG_LEVELS = process.env.SENTRY_CAPTURE_LOG_LEVELS
     : ['log', 'warn', 'error'];
 
 if (!SENTRY_DSN) {
-    throw new Error('SENTRY_DSN is not set');
-}
-
-Sentry.init({
-    dsn: SENTRY_DSN,
-    integrations: [
-        nodeProfilingIntegration(),
-        ...(SENTRY_ENABLE_LOGS
-            ? [Sentry.consoleLoggingIntegration({ levels: SENTRY_CAPTURE_LOG_LEVELS as ConsoleLevel[] })]
-            : []),
-    ],
-    /**
-     * @description
-     * The sample rate for tracing. Value should be between 0 and 1.
-     * By default, tracing is disabled.
-     * @default undefined
-     */
-    tracesSampleRate: SENTRY_TRACES_SAMPLE_RATE,
-    /**
-     * @description
-     * The sample rate for profiling. Value should be between 0 and 1.
-     * By default, profiling is disabled.
-     * @default undefined
-     */
-    profilesSampleRate: SENTRY_PROFILES_SAMPLE_RATE,
+    // eslint-disable-next-line
+    console.error('SENTRY_DSN is not set');
+} else {
+    Sentry.init({
+        dsn: SENTRY_DSN,
+        integrations: [
+            nodeProfilingIntegration(),
+            ...(SENTRY_ENABLE_LOGS
+                ? [Sentry.consoleLoggingIntegration({ levels: SENTRY_CAPTURE_LOG_LEVELS as ConsoleLevel[] })]
+                : []),
+        ],
+        /**
+         * @description
+         * The sample rate for tracing. Value should be between 0 and 1.
+         * By default, tracing is disabled.
+         * @default undefined
+         */
+        tracesSampleRate: SENTRY_TRACES_SAMPLE_RATE,
+        /**
+         * @description
+         * The sample rate for profiling. Value should be between 0 and 1.
+         * By default, profiling is disabled.
+         * @default undefined
+         */
+        profilesSampleRate: SENTRY_PROFILES_SAMPLE_RATE,
 
-    /**
-     * @description
-     * Enable logs to be sent to Sentry.
-     * @default false
-     */
-    enableLogs: SENTRY_ENABLE_LOGS,
-});
+        /**
+         * @description
+         * Enable logs to be sent to Sentry.
+         * @default false
+         */
+        enableLogs: SENTRY_ENABLE_LOGS,
+    });
+}