Repository navigation
[AISAGE-502] feat(ai-gateway): share server Sentry and OTel setup with web - #7107
Conversation
…b-shared Move the Node.js Sentry init and the @vercel/otel wiring into packages/web-shared/src/lib/observability so the ai-gateway app can reuse them. apps/web keeps the same Sentry options, redaction, and the kilocode-app OTel service name.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (12 files)
Incremental review of the ai-gateway commit found no new issues: its Previous Review Summary (commit cd90250)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit cd90250)Status: No Issues Found | Recommendation: Merge Files Reviewed (9 files)
Verified behavior is preserved by the refactor: Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
Register the shared Node.js Sentry init and @vercel/otel wiring with the kilocode-ai-gateway service name, and wrap the Next.js config with withSentryConfig for source map uploads, as apps/web does.
…erver-observability
Summary
Prep PR split out of #7052. It moves the web app's server-side Sentry and OpenTelemetry setup into
packages/web-shared, without changingapps/webbehavior, and registers the same setup inapps/ai-gateway. The gateway has had no Sentry or OTel since #6806.apps/web/sentry.server.config.tsmoves topackages/web-shared/src/lib/observability/sentry-server.ts. The top-levelinit()call becomesinitServerSentry(), still skipped in development. The options, the Drizzle error rewriting, the tRPC 4xx filter and the request-data redaction are unchanged. The test moves along with it.@vercel/otelwiring fromapps/web/src/instrumentation.tsmoves toobservability/node-instrumentation.tsasregisterNodeInstrumentation(serviceName). It keeps the Sentry sampler, propagator, span processor and context manager, plusvalidateOpenTelemetrySetup().apps/web/src/instrumentation.tsnow dynamic-imports that module in thenodejsbranch and calls it with'kilocode-app'.onRequestErrorare unchanged.sanitize-analytics-url.tsand its test move to web-shared because the redaction uses it.PostHogProviderstill imports it through@/lib/sanitize-analytics-url.@sentry/opentelemetry,@vercel/otel, and the@opentelemetry/*packages apps/web pins for@vercel/otel's peers (api,api-logs,sdk-logs,sdk-metrics), at the same versions asapps/web.@opentelemetry/apimoves from devDependencies to dependencies.apps/web/tsconfig.jsonandENVIRONMENT.mddrop the oldsentry.server.config.tspath.ai-gateway setup (second commit)
apps/ai-gateway/src/instrumentation.tscallsregisterNodeInstrumentation('kilocode-ai-gateway')in thenodejsruntime, so gateway traces get their ownservice.name. It also exportsonRequestError = captureRequestError.apps/ai-gateway/next.config.mjswraps the config inwithSentryConfigoutside development, with the same build options as web (SENTRY_ORG,SENTRY_PROJECT,SENTRY_AUTH_TOKEN, tree-shaken debug statements, no telemetry).apps/ai-gateway/package.jsonadds@sentry/nextjs10.69.0, the version web uses.ENVIRONMENT.mdnow lists both apps for the Sentry build variables andNEXT_RUNTIME.Verification
pnpm --filter @kilocode/web-shared typecheckandcd apps/web && pnpm exec tsgo --noEmitpass.sentry-server.test.tsandsanitize-analytics-url.test.tspass in their new location (28 tests).pnpm run dependency-cycle-check(no circular dependencies) pass on the changed files.readlink -fshowsnext,@sentry/nextjs,@vercel/oteland@sentry/opentelemetryresolve to the same pnpm store directory fromapps/webandpackages/web-shared;nextand@sentry/nextjsalso fromapps/ai-gateway.pnpm --filter ai-gateway typecheckpasses. A localnext buildofapps/ai-gatewaypasses, and the server chunk contains thekilocode-ai-gatewayservice name.next starton that build answered requests, and startup logged no Sentry or OTel setup warnings.buildjob compiles it. To confirm in production after deploy, check that Sentry still receives server errors and that traces still reportservice.name=kilocode-app.Visual Changes
N/A
Reviewer Notes
sentry-server.tsis a git rename. Its diff only rewrites the header comment, changes thesanitize-analytics-urlimport from a relative path to@/lib/..., and wrapsinit()ininitServerSentry().@sentry/opentelemetryand@vercel/otelare now loaded by static imports in the helper, beforeinitServerSentry()runs, instead of being dynamic-imported after it. Both modules only register anything whenregisterOTel(...)and the span processor are constructed, which still happens after init.