Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andokai opened this issue Oct 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@andokai
Copy link

andokai commented Oct 27, 2024

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?

@dosubot dosubot bot added the enhancement New feature or request label Oct 27, 2024
@mcollina
Copy link
Member

Sure thing, send a PR over!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants