Skip to content

Commit 72bdbcd

Browse files
feyclaude
andcommitted
fix: initialize Sentry before app load via --import for ESM
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 95457e6 commit 72bdbcd

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

bin/start.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
set -e
44

5-
COMMAND="fastify start server/plugin.js -a 0.0.0.0 -l info | pino-pretty -S"
5+
export NODE_OPTIONS="--import ./instrument.js"
66

7-
echo $COMMAND
8-
eval $COMMAND
7+
fastify start server/plugin.js -a 0.0.0.0 -l info | pino-pretty -S

instrument.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
if (process.env.SENTRY_DSN) {
4+
Sentry.init({ dsn: process.env.SENTRY_DSN });
5+
}

server/plugin.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import addRoutes from './routes.js';
1212

1313
const __dirname = fileURLToPath(path.dirname(import.meta.url));
1414

15-
if (process.env.SENTRY_DSN) {
16-
Sentry.init({ dsn: process.env.SENTRY_DSN });
17-
}
18-
1915
const registerErrorHandler = (app) => {
2016
app.setErrorHandler((error, _request, reply) => {
2117
const { message: errorMessage } = error;

0 commit comments

Comments
 (0)