Skip to content

[AISAGE-502] feat(ai-gateway): share server Sentry and OTel setup with web - #7107

Merged
chrarnoldus merged 3 commits into
mainfrom
refactor/web-shared-server-observability
Oct 5, 2026
Merged

chrarnoldus merged 3 commits into
mainfrom
refactor/web-shared-server-observability

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prep PR split out of #7052. It moves the web app's server-side Sentry and OpenTelemetry setup into packages/web-shared, without changing apps/web behavior, and registers the same setup in apps/ai-gateway. The gateway has had no Sentry or OTel since #6806.

  • apps/web/sentry.server.config.ts moves to packages/web-shared/src/lib/observability/sentry-server.ts. The top-level init() call becomes initServerSentry(), 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.
  • The @vercel/otel wiring from apps/web/src/instrumentation.ts moves to observability/node-instrumentation.ts as registerNodeInstrumentation(serviceName). It keeps the Sentry sampler, propagator, span processor and context manager, plus validateOpenTelemetrySetup().
    • apps/web/src/instrumentation.ts now dynamic-imports that module in the nodejs branch and calls it with 'kilocode-app'.
    • The Edge branch and onRequestError are unchanged.
  • sanitize-analytics-url.ts and its test move to web-shared because the redaction uses it. PostHogProvider still imports it through @/lib/sanitize-analytics-url.
  • web-shared now depends on @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 as apps/web. @opentelemetry/api moves from devDependencies to dependencies.
  • apps/web/tsconfig.json and ENVIRONMENT.md drop the old sentry.server.config.ts path.

ai-gateway setup (second commit)

  • apps/ai-gateway/src/instrumentation.ts calls registerNodeInstrumentation('kilocode-ai-gateway') in the nodejs runtime, so gateway traces get their own service.name. It also exports onRequestError = captureRequestError.
    • There is no client or Edge Sentry config: the app is API-only and has no Edge routes or middleware.
  • apps/ai-gateway/next.config.mjs wraps the config in withSentryConfig outside 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.json adds @sentry/nextjs 10.69.0, the version web uses. ENVIRONMENT.md now lists both apps for the Sentry build variables and NEXT_RUNTIME.

Verification

  • pnpm --filter @kilocode/web-shared typecheck and cd apps/web && pnpm exec tsgo --noEmit pass.
  • sentry-server.test.ts and sanitize-analytics-url.test.ts pass in their new location (28 tests).
  • oxlint, oxfmt and pnpm run dependency-cycle-check (no circular dependencies) pass on the changed files.
  • readlink -f shows next, @sentry/nextjs, @vercel/otel and @sentry/opentelemetry resolve to the same pnpm store directory from apps/web and packages/web-shared; next and @sentry/nextjs also from apps/ai-gateway.
  • pnpm --filter ai-gateway typecheck passes. A local next build of apps/ai-gateway passes, and the server chunk contains the kilocode-ai-gateway service name. next start on that build answered requests, and startup logged no Sentry or OTel setup warnings.
  • I did not run the web app locally. CI's build job compiles it. To confirm in production after deploy, check that Sentry still receives server errors and that traces still report service.name=kilocode-app.

Visual Changes

N/A

Reviewer Notes

  • sentry-server.ts is a git rename. Its diff only rewrites the header comment, changes the sanitize-analytics-url import from a relative path to @/lib/..., and wraps init() in initServerSentry().
  • Small ordering difference: @sentry/opentelemetry and @vercel/otel are now loaded by static imports in the helper, before initServerSentry() runs, instead of being dynamic-imported after it. Both modules only register anything when registerOTel(...) and the span processor are constructed, which still happens after init.

…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.
@chrarnoldus chrarnoldus self-assigned this Oct 2, 2026
@chrarnoldus chrarnoldus changed the title refactor(web): share the server Sentry and OpenTelemetry setup via web-shared refactor(web): share server Sentry and OTel setup via web-shared Oct 2, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (12 files)
  • ENVIRONMENT.md
  • apps/ai-gateway/next.config.mjs
  • apps/ai-gateway/package.json
  • apps/ai-gateway/src/instrumentation.ts
  • apps/web/src/instrumentation.ts
  • apps/web/tsconfig.json
  • packages/web-shared/package.json
  • packages/web-shared/src/lib/observability/node-instrumentation.ts
  • packages/web-shared/src/lib/observability/sentry-server.ts
  • packages/web-shared/src/lib/observability/sentry-server.test.ts
  • packages/web-shared/src/lib/sanitize-analytics-url.ts
  • packages/web-shared/src/lib/sanitize-analytics-url.test.ts

Incremental review of the ai-gateway commit found no new issues: its @/ path mapping resolves the shared helper to packages/web-shared, the nodejs guard and onRequestError wiring match apps/web, @sentry/nextjs is pinned to the same 10.69.0 as web and web-shared, and there are no Edge routes or middleware that would need an Edge Sentry config.

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)
  • ENVIRONMENT.md
  • apps/web/src/instrumentation.ts
  • apps/web/tsconfig.json
  • packages/web-shared/package.json
  • packages/web-shared/src/lib/observability/node-instrumentation.ts
  • packages/web-shared/src/lib/observability/sentry-server.ts
  • packages/web-shared/src/lib/observability/sentry-server.test.ts
  • packages/web-shared/src/lib/sanitize-analytics-url.ts
  • packages/web-shared/src/lib/sanitize-analytics-url.test.ts

Verified behavior is preserved by the refactor: initServerSentry() reproduces the original NODE_ENV !== 'development' guard, the @/ alias fallback resolves both moved modules under apps/web and web-shared (tsconfig, Jest moduleNameMapper, tRPC rollup), the added @opentelemetry/*, @sentry/opentelemetry, and @vercel/otel versions match apps/web, and no remaining references to the old sentry.server.config.ts or src/lib/sanitize-analytics-url paths exist.


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

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.
@chrarnoldus chrarnoldus changed the title refactor(web): share server Sentry and OTel setup via web-shared feat(ai-gateway): share server Sentry and OTel setup with web Oct 2, 2026
@chrarnoldus
chrarnoldus merged commit 483a8d9 into main Oct 5, 2026
30 checks passed
@chrarnoldus
chrarnoldus deleted the refactor/web-shared-server-observability branch October 5, 2026 09:42
@chrarnoldus chrarnoldus changed the title feat(ai-gateway): share server Sentry and OTel setup with web [AISAGE-502] feat(ai-gateway): share server Sentry and OTel setup with web Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants