Skip to content

Prod monitoring: route latency middleware + metrics history snapshots + threshold alerting#1667

Draft
pulzzejason wants to merge 1 commit into
mainfrom
goal/9e9dbe55
Draft

Prod monitoring: route latency middleware + metrics history snapshots + threshold alerting#1667
pulzzejason wants to merge 1 commit into
mainfrom
goal/9e9dbe55

Conversation

@pulzzejason

Copy link
Copy Markdown
Contributor

Integration PR for this goal — its tasks commit onto this branch (one PR per goal). Opened automatically by the engine on first push; left as a draft until the goal completes.

…y populates

Registers LatencySpanProcessor on the NodeSDK in instrumentation.ts whose
onEnd() records incoming HTTP SERVER-span duration into the in-process latency
store (recordLatency), backing the admin Prod Metrics "Request Latency" panel
that was permanently empty (recordLatency had zero callers).

Key decisions:
- Span processor over per-handler wrappers: the OTel HTTP auto-instrumentation
  already emits one SERVER span per request, so onEnd() captures EVERY route
  uniformly with no handler edits.
- Node runtime only: capture cannot live in edge middleware.ts, which can't
  reach the ioredis-backed Node in-process store.
- SDK now starts REGARDLESS of OTEL_EXPORTER_OTLP_ENDPOINT (shipped empty in
  .env.example); previously the whole tracing SDK was gated on it, so the
  processor would have captured nothing in the common deployment. OTLP export
  is attached as an extra BatchSpanProcessor only when the endpoint is set
  (NodeSDK uses spanProcessors verbatim and ignores traceExporter).
- Route keys normalized via normalize-route.ts (collapses ids/slugs) to bound
  map cardinality; static assets (_next/static, _next/image, favicon, asset
  file extensions) excluded.

Verified end-to-end: booting the SDK with no OTLP endpoint + real HTTP traffic
yields non-empty p50/p95/p99 rows for normalized routes, with static assets and
outbound CLIENT spans excluded. Unit tests cover the store, percentile helper,
route extraction/normalization, exclusion rules, and the processor.

No PM agent config change: this is an admin-ops surface (Prod Metrics dashboard),
not agent-visible data or tools.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant