feat: add low-noise Redis observability - #14309
Conversation
There was a problem hiding this comment.
Pull request overview
Adds low-noise Redis observability to the API by aggregating logical Redis activity into Prometheus metrics and attaching per-request Redis summaries to the existing OpenTelemetry HTTP span, without enabling per-command OTel spans.
Changes:
- Introduces
redisTelemetryhelpers to observe logical Redis operations and aggregate them onto the request span viaAsyncLocalStorage. - Instruments Keyv caches and selected ioredis clients/usages (streams, concurrency, leader election, MCP registry scans, rate limiting) to emit bounded-label Prometheus metrics.
- Extends the Prometheus metrics module with Redis operation counters + latency histogram, plus unit tests validating the new metrics output.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/api/src/telemetry/middleware.ts | Starts/stops per-request Redis aggregation and runs downstream middleware within Redis telemetry context. |
| packages/api/src/telemetry/middleware.spec.ts | Adds coverage ensuring Redis aggregation is attached to the stored request span. |
| packages/api/src/stream/implementations/RedisJobStore.ts | Wraps the stream ioredis client with Redis instrumentation for generation stream use case. |
| packages/api/src/stream/implementations/RedisEventTransport.ts | Instruments publisher/subscriber ioredis clients for pub/sub stream transport use case. |
| packages/api/src/middleware/concurrency.ts | Instruments the ioredis client used by concurrency Lua scripts. |
| packages/api/src/mcp/registry/cache/ServerConfigsCacheRedis.ts | Wraps Redis SCAN iteration in a logical “scan” observation for MCP registry cache reads. |
| packages/api/src/cluster/LeaderElection.ts | Observes Redis get/set/eval operations used for leader election. |
| packages/api/src/cache/redisTelemetry.ts | New core module implementing request aggregation, bounded label normalization, and ioredis/Keyv instrumentation. |
| packages/api/src/cache/redisTelemetry.spec.ts | New unit tests covering use case normalization, aggregation behavior, nested call de-duping, and pipeline error detection. |
| packages/api/src/cache/principals.ts | Instruments Redis client used by the user principals cache path. |
| packages/api/src/cache/index.ts | Re-exports redis telemetry utilities from the cache module barrel. |
| packages/api/src/cache/cacheFactory.ts | Instruments standard Keyv caches, session store Redis client, and rate-limit sendCommand calls. |
| packages/api/src/app/metrics.ts | Adds Redis operation counter + duration histogram and exposes recordRedisOperation. |
| packages/api/src/app/metrics.spec.ts | Adds tests verifying Redis metrics are emitted and labeled correctly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* feat(api): add low-noise Redis observability * fix(api): preserve Redis proxy constructor
* feat(api): add low-noise Redis observability * fix(api): preserve Redis proxy constructor
Summary
Adds low-noise visibility into application Redis latency without enabling per-command OpenTelemetry spans.
Change Type
Testing
npx tsc --noEmit -p packages/api/tsconfig.jsonnpm run build --workspace=@librechat/apiTest Configuration:
Checklist