Closed ghost closed 2 years ago
Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️
Hi, I do not see anything wrong with your configuration. Are you using the Sentry Vercel integration? There you might be able to set the SENTRY_ENVIRONMENT
env variable. More info.
Also, are you sending errors to sentry using the custom-staging
environment? You need to send at least one event to sentry before the environment appears in the interface. Can you verify this?
I have the same issue. I've tried with Sentry Vercel integration and adding SENTRY_ENVIRONMENT as "staging".
And sentry somehow ignores that and set it as "production" 😭
I've tried without Sentry Vercel integration too, manually calling Sentry.init and setting the environment not working, seems like Sentry is reading from another env, probably NODE_ENV.
I read the sentry guide, it only said either set environment
manually during Sentry.init or use env SENTRY_ENVIRONMENT. Both not working and I'm not sure how to continue now.
Ok, i think i've got it working.
So first I'm connecting my project with Sentry Vercel Integration, which will add some SENTRY environments to my Vercel. For some reason, the env only available for Vercel production env, I change those for Vercel production,preview & development.
Then I follow instructions mentioned here Sentry NextJS guide which will generate some files and some of them are sentry.client.config.js
and sentry.server.config.js
.
Inside those file there should be Sentry.init function and I place the environment there, but with prefix NEXTPUBLIC* for both sentry.client.config.js
and sentry.server.config.js
.
Sentry.init({
dsn: SENTRY_DSN || '',
tracesSampleRate: 1.0,
release: process.env.VERCEL_GIT_COMMIT_SHA,
// Add prefix NEXT_PUBLIC_*
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
});
Then it's working. I think the issue is sentry.client.config.js
can't read process.env.SENTRY_ENVIRONMENT since it's not available to browser version.
@pawlarius, you are right! 🎉
This is by Next.js's design. It is stripping environment variables exposed to the browser for security reasons. You can read more about it here - Next.js: Exposing Environment Variables to the Browser, but essentially it boils down to this:
By default environment variables are only available in the Node.js environment, meaning they won't be exposed to the browser.
@thienna-beincomm, please prefix your env variables with NEXT_PUBLIC_
so Next.js exposes it on the browser and it will work.
@thienna-beincomm, please let us know if this resolves the issue for you.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog
or Status: In Progress
, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
Environment
SaaS (https://sentry.io/)
Version
No response
Steps to Reproduce
My project using NextJS and deploy it with Vercel, I am integrating with Sentry and I want to filter environment to like dev, staging, production. I have followed the instruction to pass the config environment to the Sentry init, but it doesn't work, any idea?
sentry.client.config.js
sentry.server.config.js
Expected Result
Has new filter when release a new version
Actual Result
It has only production and development