redwood
redwood copied to clipboard
[Bug]: Sentry experimental setup in production
What's not working?
Using the Sentry experimental setup, in production, .env's SENTRY_DSN
isn't read because of Vite's build-time replacement of process.env.X according to redwood.toml included envvars.
How do we reproduce the bug?
Setup sentry : yarn redwood experimental setup-sentry
In the generated web/src/lib/sentry.ts:
let dsn = ''
let environment = 'development'
if (typeof process === 'undefined' || !process.env?.SENTRY_DSN) {
console.error(
'Missing SENTRY_DSN environment variable. Did you forget to add it to ' +
'your redwood.toml file in `includeEnvironmentVariables`?'
)
console.info(`Copy this into your redwood.toml file:`)
console.info(`
includeEnvironmentVariables = [
"SENTRY_DSN"
]
`)
console.info('Sentry is disabled for now')
} else {
dsn = process.env.SENTRY_DSN
environment = process.env.NODE_ENV
}
The builded minified result:
let Ape = ""
, Mpe = "development";
var Jle;
typeof process > "u" || !((Jle = process.env) != null && Jle.SENTRY_DSN)
? (
console.error("Missing SENTRY_DSN environment variable. Did you forget to add it to your redwood.toml file in `includeEnvironmentVariables`?"),
console.info("Copy this into your redwood.toml file:"),
console.info(`
includeEnvironmentVariables = [
"SENTRY_DSN"
]
`),
console.info("Sentry is disabled for now"))
: (
Ape = "https://[email protected]/y",
Mpe = "production"
);
process.env.SENTRY_DSN
is replaced, but !process.env?.SENTRY_DSN
isn't, neither is process
.
Tested simple fix:
const dsn = process.env.SENTRY_DSN;
const environment = process.env.NODE_ENV;
if (!dsn) {
...
What's your environment? (If it applies)
Production environment, redwood 6.6.2
Are you interested in working on this?
Sorry, I can't take the time to PR right now. Thanks to all Redwood's community for this awesome work, that keeps improving at great pace, that's really appreciated!
Thanks @Bigood for reporting. Am going to loop in @Tobbe, @dac09 and @jtoar as they have more background with the Vite change to envars.
On the a Town Hall event yesterday, it as noted that Sentry setup has moved out of experimental in v7.
I also hit this error with v7 Redwood, and didn't use the experimental setup before v7. Only web side is failing, and only in production not being able to find process. ~redwood.toml has the SENTRY_DSN included ~app is deployed to Vercel and has the environment variables setup there ~I'm on v7.0.3 atm