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.

feat(api): tag Sentry events with the app release

Andrej33270e37a76e
diff --git a/apps/api/src/instrument.ts b/apps/api/src/instrument.ts
index 811c15a5e..6edea47ec 100644
--- a/apps/api/src/instrument.ts
+++ b/apps/api/src/instrument.ts
@@ -1,14 +1,29 @@
+import { readFileSync } from "node:fs";
import * as Sentry from "@sentry/node";
const tracesSampleRate = Number.parseFloat(
process.env.SENTRY_TRACES_SAMPLE_RATE ?? "",
);
+// The monorepo root package.json sits three levels up from both src/ (dev)
+// and dist/ (the esbuild bundle), locally and in the Docker image.
+function readAppVersion() {
+ try {
+ const pkg = JSON.parse(
+ readFileSync(new URL("../../../package.json", import.meta.url), "utf8"),
+ );
+ return typeof pkg.version === "string" ? pkg.version : undefined;
+ } catch {
+ return undefined;
+ }
+}
+
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment:
process.env.SENTRY_ENVIRONMENT ?? process.env.NODE_ENV ?? "production",
+ release: process.env.SENTRY_RELEASE ?? readAppVersion(),
sendDefaultPii: false,
tracesSampleRate: Number.isFinite(tracesSampleRate) ? tracesSampleRate : 0,
});