Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): validate Sentry sample rate env vars are in 0..1

justin01e9933329c8
diff --git a/apps/api/src/instrument.ts b/apps/api/src/instrument.ts
index c9a715efb..72fe84b10 100644
--- a/apps/api/src/instrument.ts
+++ b/apps/api/src/instrument.ts
@@ -2,12 +2,15 @@ import { readFileSync } from "node:fs";
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";
-const tracesSampleRate = Number.parseFloat(
- process.env.SENTRY_TRACES_SAMPLE_RATE ?? "",
-);
+function parseSampleRate(value: string | undefined): number {
+ const n = Number(value);
+ return Number.isFinite(n) && n >= 0 && n <= 1 ? n : 0;
+}
+
+const tracesSampleRate = parseSampleRate(process.env.SENTRY_TRACES_SAMPLE_RATE);
-const profilesSampleRate = Number.parseFloat(
- process.env.SENTRY_PROFILES_SAMPLE_RATE ?? "",
+const profilesSampleRate = parseSampleRate(
+ process.env.SENTRY_PROFILES_SAMPLE_RATE,
);
function readAppVersion() {
@@ -28,10 +31,8 @@ if (process.env.SENTRY_DSN) {
process.env.SENTRY_ENVIRONMENT ?? process.env.NODE_ENV ?? "production",
release: process.env.SENTRY_RELEASE ?? readAppVersion(),
sendDefaultPii: false,
- tracesSampleRate: Number.isFinite(tracesSampleRate) ? tracesSampleRate : 0,
- profilesSampleRate: Number.isFinite(profilesSampleRate)
- ? profilesSampleRate
- : 0,
+ tracesSampleRate,
+ profilesSampleRate,
integrations: [nodeProfilingIntegration()],
});
}