Skip to content

Commit 590bf4b

Browse files
committed
fix: moved sentry information to bff supplied at runtime
1 parent 691c39d commit 590bf4b

File tree

8 files changed

+57
-15
lines changed

8 files changed

+57
-15
lines changed

.env.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
VITE_SENTRY_ENVIRONMENT=
21
# Sentry DSN configuration, no need to be set for local setup
32
# Frontend:
43
SENTRY_ORG=
54
SENTRY_PROJECT=
6-
VITE_SENTRY_DSN=
5+
FRONTEND_SENTRY_DSN=
6+
FRONTEND_SENTRY_ENVIRONMENT=
77
# BFF:
88
BFF_SENTRY_DSN=
99
DYNATRACE_SCRIPT_URL=

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
<script type="module" src="/src/mount.ts"></script>
1414
</body>
1515

16-
</html>
16+
</html>

package-lock.json

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"npm": "^11.0.0"
88
},
99
"scripts": {
10-
"dev": "node --loader ts-node/esm ./server.ts --local-dev",
10+
"dev": "tsx ./server.ts --local-dev",
1111
"start": "node dist/server.js",
12-
"build": "tsc && npm run build:server && vite build",
12+
"build": "npm run build:server && npm run build:client",
13+
"build:client": "vite build",
1314
"build:server": "tsc -p tsconfig.server.json",
1415
"lint": "eslint ./src --report-unused-disable-directives --max-warnings 0",
1516
"lint:fix": "eslint ./src --fix",
@@ -92,6 +93,7 @@
9293
"globals": "^16.0.0",
9394
"prettier": "^3.5.3",
9495
"ts-node": "^10.9.2",
96+
"tsx": "^4.20.5",
9597
"typescript": "^5.7.3",
9698
"typescript-eslint": "^8.26.1",
9799
"vite": "^6.3.4",

server.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ await fastify.register(envPlugin);
7272

7373
let sentryHost = '';
7474
// @ts-ignore
75-
if (fastify.config.VITE_SENTRY_DSN && fastify.config.VITE_SENTRY_DSN.length > 0) {
75+
if (fastify.config.FRONTEND_SENTRY_DSN && fastify.config.FRONTEND_SENTRY_DSN.length > 0) {
7676
try {
7777
// @ts-ignore
78-
sentryHost = new URL(fastify.config.VITE_SENTRY_DSN).hostname;
78+
sentryHost = new URL(fastify.config.FRONTEND_SENTRY_DSN).hostname;
7979
} catch {
80-
console.log('VITE_SENTRY_DSN is not a valid URL');
80+
console.log('FRONTEND_SENTRY_DSN is not a valid URL');
8181
sentryHost = '';
8282
}
8383
}
@@ -114,6 +114,15 @@ await fastify.register(FastifyVite, {
114114
spa: true,
115115
});
116116

117+
fastify.get('/sentry', function (req, reply) {
118+
return reply.send({
119+
// @ts-ignore
120+
FRONTEND_SENTRY_DSN: fastify.config.FRONTEND_SENTRY_DSN,
121+
// @ts-ignore
122+
FRONTEND_SENTRY_ENVIRONMENT: fastify.config.FRONTEND_SENTRY_ENVIRONMENT,
123+
});
124+
});
125+
117126
// @ts-ignore
118127
fastify.get('/', function (req, reply) {
119128
return reply.html();

server/config/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const schema = {
3030
FEEDBACK_URL_LINK: { type: 'string' },
3131
FRAME_ANCESTORS: { type: 'string' },
3232
BFF_SENTRY_DSN: { type: 'string' },
33-
VITE_SENTRY_DSN: { type: 'string' },
34-
VITE_SENTRY_ENVIRONMENT: { type: 'string' },
33+
FRONTEND_SENTRY_DSN: { type: 'string' },
34+
FRONTEND_SENTRY_ENVIRONMENT: { type: 'string' },
3535

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

src/mount.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ import React from 'react';
55
import { Routes, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes } from 'react-router-dom';
66

77
let sentryRoutes = Routes;
8-
if (import.meta.env.VITE_SENTRY_DSN && import.meta.env.VITE_SENTRY_DSN.length > 0) {
8+
9+
const sentryConfig = await fetch('/sentry').then((res) => res.json());
10+
11+
if (
12+
sentryConfig.FRONTEND_SENTRY_DSN &&
13+
sentryConfig.FRONTEND_SENTRY_DSN.length > 0 &&
14+
sentryConfig.FRONTEND_SENTRY_ENVIRONMENT &&
15+
sentryConfig.FRONTEND_SENTRY_ENVIRONMENT.length > 0
16+
) {
917
Sentry.init({
10-
dsn: import.meta.env.VITE_SENTRY_DSN,
11-
environment: import.meta.env.VITE_SENTRY_ENVIRONMENT,
18+
dsn: sentryConfig.FRONTEND_SENTRY_DSN,
19+
environment: sentryConfig.FRONTEND_SENTRY_ENVIRONMENT,
1220
integrations: [
1321
Sentry.reactRouterV7BrowserTracingIntegration({
1422
useEffect: React.useEffect,

vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default defineConfig({
1414
sentryVitePlugin({
1515
org: process.env.SENTRY_ORG,
1616
project: process.env.SENTRY_PROJECT,
17+
telemetry: false,
1718
reactComponentAnnotation: {
1819
enabled: true,
1920
},
@@ -22,5 +23,6 @@ export default defineConfig({
2223

2324
build: {
2425
sourcemap: true,
26+
target: 'esnext', // Support top-level await
2527
},
2628
});

0 commit comments

Comments
 (0)