Skip to content

Commit a502dc1

Browse files
committed
fix: Rename VITE_ENVIRONMENT to VITE_SENTRY_ENVIRONMENT for consistency in Sentry configuration
added try catch for url parsing
1 parent 5de454c commit a502dc1

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VITE_ENVIRONMENT=
1+
VITE_SENTRY_ENVIRONMENT=
22
# Sentry DSN configuration, no need to be set for local setup
33
# Frontend:
44
SENTRY_ORG=

server.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (!process.env.BFF_SENTRY_DSN || process.env.BFF_SENTRY_DSN.trim() === '') {
1919
// Setting this option to true will send default PII data to Sentry.
2020
// For example, automatic IP address collection on events
2121
sendDefaultPii: true,
22-
environment: process.env.VITE_ENVIRONMENT,
22+
environment: process.env.VITE_SENTRY_ENVIRONMENT,
2323
beforeSend(event) {
2424
if (event.request && event.request.cookies) {
2525
event.request.cookies = Object.keys(event.request.cookies).reduce((acc, key) => {
@@ -51,9 +51,14 @@ const fastify = Fastify({
5151
Sentry.setupFastifyErrorHandler(fastify);
5252
await fastify.register(envPlugin);
5353

54-
let sentryHost = null;
54+
let sentryHost = '';
5555
if (fastify.config.BFF_SENTRY_DSN && fastify.config.BFF_SENTRY_DSN.length > 0) {
56-
sentryHost = new URL(fastify.config.BFF_SENTRY_DSN).hostname;
56+
try {
57+
sentryHost = new URL(fastify.config.BFF_SENTRY_DSN).hostname;
58+
} catch {
59+
console.log('BFF_SENTRY_DSN is not a valid URL');
60+
sentryHost = '';
61+
}
5762
}
5863

5964
fastify.register(helmet, {

server/config/env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const schema = {
3131
FRAME_ANCESTORS: { type: 'string' },
3232
BFF_SENTRY_DSN: { type: 'string' },
3333
VITE_SENTRY_DSN: { type: 'string' },
34-
VITE_ENVIRONMENT: { type: 'string' },
34+
VITE_SENTRY_ENVIRONMENT: { type: 'string' },
3535

3636
// System variables
3737
NODE_ENV: { type: 'string', enum: ['development', 'production'] },

src/mount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (import.meta.env.VITE_SENTRY_DSN && import.meta.env.VITE_SENTRY_DSN.length >
1111
// Setting this option to true will send default PII data to Sentry.
1212
// For example, automatic IP address collection on events
1313
sendDefaultPii: true,
14-
environment: import.meta.env.VITE_ENVIRONMENT,
14+
environment: import.meta.env.VITE_SENTRY_ENVIRONMENT,
1515
integrations: [
1616
Sentry.reactRouterV7BrowserTracingIntegration({
1717
useEffect: React.useEffect,

0 commit comments

Comments
 (0)