-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Context
After reverting Sentry from dj-site (Cloudflare Workers incompatibility), neither repo has error tracking. Backend-Service runs on EC2 with no compatibility issues, so we use @sentry/node for server-side error capture and performance tracing.
Changes
Sentry Initialization
apps/backend/instrument.tsandapps/auth/instrument.ts--Sentry.init()with DSN, release, environment, andtracesSampleRate: 1.0. Auto-detected integrations cover Express, HTTP, and PostgreSQL.
Express Integration
apps/backend/app.ts--import './instrument.js'as first line,Sentry.setupExpressErrorHandler(app)after routes beforeerrorHandler,requestIdMiddlewareafterexpress.json().apps/auth/app.ts--import './instrument.js'as first line,Sentry.setupExpressErrorHandler(app)after routes, new fallback error handler (auth had none).
Cross-Service Correlation
apps/backend/middleware/requestId.ts-- ReadsX-Request-Idfrom incoming request (sent by dj-site) or generates one viacrypto.randomUUID(). Sets on response header and tags Sentry scope withrequest_id.- CORS updated --
X-Request-Idadded toallowedHeadersandexposedHeaders.
Build Configuration
apps/backend/tsup.config.ts--external: ['@sentry/node'],sourcemap: true(Sentry monkey-patches require unbundled modules).apps/auth/tsup.config.ts--'@sentry/node'added to existingexternalarray.
Deploy
.github/actions/deploy-service/action.yml---e SENTRY_RELEASE=$TARGET_APP@$DEPLOY_TAGadded todocker run.
Tests
tests/unit/middleware/requestId.test.ts-- 5 tests: UUID generation, pass-through of existing header, response header setting, Sentry scope tagging.
Environment Variables
Add to .env on EC2:
SENTRY_DSN-- Sentry project DSN
Verification
npm run buildsucceeds for both workspacesnpm run test:unitpasses (125 tests, including 5 new requestId tests)- Deploy to EC2, hit
/healthcheck-- confirmX-Request-Idresponse header - Trigger an error -- confirm it appears in Sentry with
request_idtag - Check Sentry Performance tab for Express spans
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels