From 3491bdc5225bfc81f3220b2f6bf2c2c57edb8cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Wed, 8 Jan 2025 17:14:16 +0100 Subject: [PATCH] Import Sentry in middleware --- packages/gitbook/sentry.server.config.ts | 10 ---------- packages/gitbook/src/instrumentation.ts | 3 +-- packages/gitbook/src/middleware.ts | 1 + .../gitbook/{sentry.edge.config.ts => src/sentry.ts} | 4 ++-- 4 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 packages/gitbook/sentry.server.config.ts rename packages/gitbook/{sentry.edge.config.ts => src/sentry.ts} (81%) diff --git a/packages/gitbook/sentry.server.config.ts b/packages/gitbook/sentry.server.config.ts deleted file mode 100644 index 8c2fb523e..000000000 --- a/packages/gitbook/sentry.server.config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { init } from '@sentry/nextjs'; - -const dsn = process.env.SENTRY_DSN; -if (dsn) { - init({ - dsn, - // Disable tracing as it creates additional requests in an env where subrequests are limited. - tracesSampleRate: 0, - }); -} diff --git a/packages/gitbook/src/instrumentation.ts b/packages/gitbook/src/instrumentation.ts index dc25a5f84..eb2a9c854 100644 --- a/packages/gitbook/src/instrumentation.ts +++ b/packages/gitbook/src/instrumentation.ts @@ -2,8 +2,7 @@ import * as Sentry from '@sentry/nextjs'; import { Instrumentation } from 'next'; export async function register() { - console.log('Instrumentation.register'); - await import('../sentry.edge.config'); + await import('./sentry'); } export const onRequestError: Instrumentation.onRequestError = async (...args) => { diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 9628de899..b3a21cf52 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -1,3 +1,4 @@ +import './sentry'; import { ContentAPITokenPayload, GitBookAPI } from '@gitbook/api'; import { setTag, setContext } from '@sentry/nextjs'; import assertNever from 'assert-never'; diff --git a/packages/gitbook/sentry.edge.config.ts b/packages/gitbook/src/sentry.ts similarity index 81% rename from packages/gitbook/sentry.edge.config.ts rename to packages/gitbook/src/sentry.ts index 104f2c121..1ec6456ad 100644 --- a/packages/gitbook/sentry.edge.config.ts +++ b/packages/gitbook/src/sentry.ts @@ -1,9 +1,9 @@ -import { init } from '@sentry/nextjs'; +import * as Sentry from '@sentry/nextjs'; const dsn = process.env.SENTRY_DSN; if (dsn) { console.log('Initializing Sentry with DSN:', dsn); - init({ + Sentry.init({ dsn, // Disable tracing as it creates additional requests in an env where subrequests are limited. tracesSampleRate: 0,