mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
common/ had become the backend's library: 30 of its 41 modules were imported by nothing in the frontend, so the name no longer said what belonged there. It now holds only what the frontend or the build imports too; backend-only code moved to server/, flat except for datasets/ (the dataset engine and its readers). The *-db/ dataset directories stay in common/: self-hosting docs and Docker volumes mount those paths. frontend/utils/ keeps its app-wide modules at the root and gains ip/ (IP / ASN shaping and validation), report/ (the report pipeline) and features/ (the pure layer of a single feature). Paths only — no logic changes. The Dockerfile copies server/, and the AGENTS.md files say where a new module goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
// Sentry bootstrap for the Express backend. Loaded via `node --import` (see
|
|
// the dev / start scripts in package.json) so the SDK registers its ESM
|
|
// loader hooks BEFORE express & co. load — that's what makes automatic
|
|
// per-route tracing work.
|
|
//
|
|
// Gated on SENTRY_DSN_BACKEND, same philosophy as the frontend: when the env
|
|
// var is unset this module does nothing and @sentry/node is never even
|
|
// loaded. SENTRY_ENVIRONMENT=development skips init too, so a local run never
|
|
// reports. backend-server.js attaches the matching Express error handler.
|
|
import dotenv from 'dotenv';
|
|
|
|
import { scrubBreadcrumb, scrubEventRequest, scrubSpan } from './server/sentry-scrub.js';
|
|
|
|
dotenv.config({ quiet: true });
|
|
|
|
// SENTRY_ENVIRONMENT=development (a local `pnpm dev` machine) skips init:
|
|
// experiments in progress are not production signal, same rule as the cron
|
|
// check-ins in server/sentry-cron.js.
|
|
if (process.env.SENTRY_DSN_BACKEND && process.env.SENTRY_ENVIRONMENT !== 'development') {
|
|
const Sentry = await import('@sentry/node');
|
|
Sentry.init({
|
|
dsn: process.env.SENTRY_DSN_BACKEND,
|
|
environment: process.env.SENTRY_ENVIRONMENT || 'production',
|
|
// 100% trace sampling (per-route latency / throughput / error rate under Insights)
|
|
tracesSampleRate: 1.0,
|
|
// Sentry Logs — receives warn/error/fatal lines forwarded by the
|
|
// logMethod hook in server/logger.js
|
|
enableLogs: true,
|
|
// Never attach caller IPs / headers to events (privacy tool)
|
|
sendDefaultPii: false,
|
|
// Upstream query strings carry API keys — redact those params in
|
|
// breadcrumbs, spans, and request contexts (the rest of the query
|
|
// stays: it's debugging context).
|
|
beforeBreadcrumb: scrubBreadcrumb,
|
|
beforeSendSpan: scrubSpan,
|
|
beforeSend: scrubEventRequest,
|
|
beforeSendTransaction: scrubEventRequest,
|
|
});
|
|
}
|