Consolidate Sentry config into shared package; fix inconsistencies
Introduces @trails-cool/sentry-config with three helpers that encode the common Sentry.init options: - nodeSentryConfig(appContext) for the two HTTP servers - browserSentryConfig(appContext, env) for the Journal client - mobileSentryConfig(__DEV__) for the React Native app - drop404s beforeSend for servers Also fixes three inconsistencies found in the audit: - Planner server was missing sendDefaultPii: false (IPs could leak) - Planner entry.server.tsx didn't call Sentry.captureException on SSR render errors; Journal's SSR did - Sentry.init location now matches across apps (both in server.ts; Journal previously had it in app/entry.server.tsx, which meant init ran lazily on first request rather than at server startup) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4092f21475
commit
8e576ac578
13 changed files with 160 additions and 64 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import * as Sentry from "@sentry/node";
|
||||
import { nodeSentryConfig, drop404s } from "@trails-cool/sentry-config";
|
||||
import { logger } from "./app/lib/logger.server.ts";
|
||||
import { httpRequestDuration } from "./app/lib/metrics.server.ts";
|
||||
import { createRequestListener } from "@react-router/node";
|
||||
|
|
@ -10,26 +11,12 @@ import { createBoss, startWorker } from "@trails-cool/jobs";
|
|||
import { expireSessionsJob } from "./app/jobs/expire-sessions.ts";
|
||||
import postgres from "postgres";
|
||||
|
||||
const sentryEnvironment = process.env.CI ? "ci" : (process.env.NODE_ENV ?? "development");
|
||||
const sentryEnabled = process.env.NODE_ENV === "production" && !process.env.CI;
|
||||
|
||||
Sentry.init({
|
||||
dsn: "https://5215134cd78d5e6c199e29300b8425af@o4509530546634752.ingest.de.sentry.io/4511102546608208",
|
||||
release: process.env.SENTRY_RELEASE,
|
||||
environment: sentryEnvironment,
|
||||
tracesSampleRate: 1.0,
|
||||
enabled: sentryEnabled,
|
||||
beforeSend(event) {
|
||||
const serialized = event.extra?.__serialized__ as Record<string, unknown> | undefined;
|
||||
if (serialized?.status === 404) return null;
|
||||
return event;
|
||||
},
|
||||
...nodeSentryConfig("planner server"),
|
||||
beforeSend: drop404s,
|
||||
});
|
||||
|
||||
if (!sentryEnabled && !process.env.CI) {
|
||||
console.debug(`[sentry] planner server init inert (env=${sentryEnvironment}); would send to Sentry in production`);
|
||||
}
|
||||
|
||||
const port = Number(process.env.PORT ?? 3001);
|
||||
const CLIENT_DIR = resolve(import.meta.dirname, "build", "client");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue