fastify / fastify/help

Recommended approach to integrate Sentry with Fastify seems to involve jumping though a bunch of unnecessary hoops when using project generated by the CLI

Open
#1,066 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

The recommended approach to integrate Sentry is listed here.

https://docs.sentry.io/platforms/javascript/guides/fastify/

It's reasonably straightforward for a normal Fastify project but less so for a generated one.

The crux of the issue is, in order to enable instrumentation, Sentry needs to be initialised before any other module is imported/required.

Using the -i or --import flag of the start command to preload the script does not do so early enough. The only solution I've found that works involves using the NODE_OPTIONS environment variable to set the Node.js --import flag in the npm commands, i.e.

`cross-env \"NODE_OPTIONS=${NODE_OPTIONS} --import ./instrument.js\" fastify start -l info -o src/app.js`

For Windows compatibility it meant I needed to add the cross-env dependency too which isn't ideal.

Is there a better approach to this and if not, would there be any appetite to update the CLI to make the preload/integration possible without working around it?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.