Skip to content

Commit 99794d7

Browse files
committed
feat: setup sentry for the controlplane
1 parent 61d53ce commit 99794d7

File tree

5 files changed

+712
-11
lines changed

5 files changed

+712
-11
lines changed

controlplane/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ PROMETHEUS_ENABLED="false"
7474
PROMETHEUS_HTTP_PATH="/metrics"
7575
PROMETHEUS_PORT="8088"
7676
PROMETHEUS_HOST="localhost"
77+
78+
# Sentry integration
79+
SENTRY_ENABLED="false"
80+
SENTRY_DSN=""
81+
SENTRY_SEND_DEFAULT_PII="false"
82+
SENTRY_TRACES_SAMPLE_RATE="1.0"
83+
SENTRY_PROFILE_SESSION_SAMPLE_RATE="1.0"
84+
SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS="100"

controlplane/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"dev": "tsx watch src/index.ts",
14-
"build": "del dist && tsc",
14+
"build": "rm -rf dist && tsc",
1515
"seed": "API_KEY=cosmo_669b576aaadc10ee1ae81d9193425705 tsx src/bin/seed.ts",
1616
"delete-user": "tsx src/bin/delete-user.ts",
1717
"deactivate-org": "tsx src/bin/deactivate-org.ts",
@@ -51,6 +51,9 @@
5151
"@graphql-tools/utils": "^10.1.2",
5252
"@keycloak/keycloak-admin-client": "^25.0.2",
5353
"@octokit/webhooks-types": "^7.6.1",
54+
"@sentry/node": "^10.11.0",
55+
"@sentry/node-native": "^10.11.0",
56+
"@sentry/profiling-node": "^10.11.0",
5457
"@tiptap/core": "^2.1.13",
5558
"@wundergraph/composition": "workspace:*",
5659
"@wundergraph/cosmo-connect": "workspace:*",
@@ -116,4 +119,4 @@
116119
"typescript": "5.5.2",
117120
"vitest": "^3.2.4"
118121
}
119-
}
122+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// sentry.config.ts
2+
import * as Sentry from "@sentry/node";
3+
4+
import { nodeProfilingIntegration } from "@sentry/profiling-node";
5+
import { eventLoopBlockIntegration } from "@sentry/node-native";
6+
7+
if (process.env.SENTRY_ENABLED) {
8+
Sentry.init({
9+
dsn: process.env.SENTRY_DSN,
10+
integrations: [
11+
eventLoopBlockIntegration({ threshold: Number(process.env.SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS) }),
12+
nodeProfilingIntegration()
13+
],
14+
profileSessionSampleRate: Number(process.env.SENTRY_PROFILE_SESSION_SAMPLE_RATE),
15+
sendDefaultPii: Boolean(process.env.SENTRY_SEND_DEFAULT_PII),
16+
tracesSampleRate: Number(process.env.SENTRY_TRACES_SAMPLE_RATE)
17+
});
18+
}
19+
20+
export * as Sentry from "@sentry/node";

controlplane/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ if (STRIPE_SECRET_KEY) {
170170
};
171171
}
172172

173+
if (process.env.SENTRY_ENABLED === "true") {
174+
if (process.env.SENTRY_DSN) {
175+
await import("./core/sentry.config.js");
176+
}
177+
else {
178+
throw new Error('SENTRY_ENABLED is set but SENTRY_DSN is not');
179+
}
180+
}
181+
173182
const app = await build(options);
174183

175184
await app.listen({

0 commit comments

Comments
 (0)