From 8fc43dbb7a291ef0c9128bb82f1b085798a7be9a Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 23 Apr 2024 11:22:06 +0200 Subject: [PATCH] fix(instrumentation): Call `Sentry.init()` as early as possible --- src/index.ts | 13 ++++++++++++- src/renderServer.ts | 11 ----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index a0819d7..7402f12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,18 @@ #!/usr/bin/env node import * as Sentry from '@sentry/node'; +import {nodeProfilingIntegration} from '@sentry/profiling-node'; + +Sentry.init({ + dsn: process.env.SENTRY_DSN, + integrations: [nodeProfilingIntegration()], + profilesSampleRate: 1, + tracesSampleRate: 1, + _experiments: { + metricsAggregator: true, + }, +}); + import dotenv from 'dotenv'; import yargs from 'yargs'; @@ -11,7 +23,6 @@ import {renderStream} from './renderStream'; import {PollingConfig} from './types'; dotenv.config(); -Sentry.init({dsn: process.env.SENTRY_DSN}); const defaultPollingConfig: PollingConfig = { /** diff --git a/src/renderServer.ts b/src/renderServer.ts index a0424f4..3842aab 100644 --- a/src/renderServer.ts +++ b/src/renderServer.ts @@ -2,7 +2,6 @@ import {performance} from 'node:perf_hooks'; import * as Sentry from '@sentry/node'; -import {nodeProfilingIntegration} from '@sentry/profiling-node'; import express from 'express'; import {ConfigService} from './config'; @@ -17,16 +16,6 @@ export function renderServer(config: ConfigService) { const app = express(); const renderRoutes = express.Router(); - Sentry.init({ - dsn: process.env.SENTRY_DSN, - integrations: [nodeProfilingIntegration()], - profilesSampleRate: 1, - tracesSampleRate: 1, - _experiments: { - metricsAggregator: true, - }, - }); - renderRoutes.use(express.json({limit: '20mb'})); renderRoutes.use((req, resp) => { if (!config.isLoaded) {