getsentry / sentry-webpack-plugin

Repo moved to https://github.com/getsentry/sentry-javascript-bundler-plugins. Please open any issues/PRs there.
MIT License
662 stars 116 forks source link

How to provide compiling in org, project, and authToken via webpack #443

Closed chris-hailstorm closed 1 year ago

chris-hailstorm commented 1 year ago

Sentry is a great tool.

I'm using NextJS + BlitzJS. The examples provided by Next set the org, project, and authToken at build time via Webpack.

I can't assume all instances of my software will use a single Sentry org and project. Customers may want to have their own Sentry accounts, for example. So I'd prefer to provide those values at run time, long after the Next build and docker image build.

Is there a normal way to do that? Or do I need to patch those values into the post-build JS code (yuk but OK if necessary).

AbhiPrasad commented 1 year ago

Hey, thanks for writing in.

This is an interesting use case, but we need to have these values at build time so that source-maps are uploaded, otherwise you get bad stacktrace.

For server-side, you can just rely on reading environmental variables to grab a DSN and send to different projects accordingly. This is a little more tricky for client-side code, since webpack builds it all into a bundle, and that has some DSN value hardcoded in it. You can maybe do a string replace on the generated client side bundle to again replace the DSN, but yes it's a little hacky.

The only other way I can think of making this work is you run a build X times for X customers, but that also feels not good.

lforst commented 1 year ago

Unfortunately, the plugin needs to be run at compile time. There is no way (at least in production code) to do source maps upload at runtime.