Skip to content

feat: add low-noise Redis observability - #14309

Merged
danny-avila merged 2 commits into
devfrom
rlazar/redis-observability
Jul 16, 2026
Merged

danny-avila merged 2 commits into
devfrom
rlazar/redis-observability

Conversation

@upman

@upman upman commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds low-noise visibility into application Redis latency without enabling per-command OpenTelemetry spans.

  • records logical Redis operation count and latency in Prometheus, grouped by bounded client, use case, operation, and status labels
  • aggregates Redis calls, duration, errors, maximum call time, and the ten most expensive use cases onto the existing HTTP request span
  • covers Keyv caches, sessions, rate limits, concurrency, principals, stream jobs and pub/sub, MCP registry scans, and leader election
  • excludes connection lifecycle pings and global Redis maintenance commands; namespace-scoped cache clears are recorded as one logical operation

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • npx tsc --noEmit -p packages/api/tsconfig.json
  • ESLint on all changed files
  • focused API suites: 75 tests passed
  • broad API unit suite: 7,022 tests passed
  • npm run build --workspace=@librechat/api

Test Configuration:

  • Node.js 22.21.0

Checklist

  • My code adheres to this project style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that this feature works
  • Local unit tests pass with my changes

Copilot AI review requested due to automatic review settings July 16, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 redisTelemetry helpers to observe logical Redis operations and aggregate them onto the request span via AsyncLocalStorage.
  • 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.

Comment thread packages/api/src/cache/redisTelemetry.ts
Comment thread packages/api/src/cache/redisTelemetry.ts
@upman

upman commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ba109bda2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@upman
upman marked this pull request as ready for review July 16, 2026 14:08
@danny-avila
danny-avila changed the base branch from main to dev July 16, 2026 14:21
@danny-avila danny-avila changed the title feat(api): add low-noise Redis observability feat: add low-noise Redis observability Jul 16, 2026
@danny-avila
danny-avila merged commit 6f21be7 into dev Jul 16, 2026
18 checks passed
@danny-avila
danny-avila deleted the rlazar/redis-observability branch July 16, 2026 14:22
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request Aug 7, 2026
* feat(api): add low-noise Redis observability

* fix(api): preserve Redis proxy constructor
LogicalAbsurd pushed a commit to LogicalAbsurd/LibreChat that referenced this pull request Aug 27, 2026
* feat(api): add low-noise Redis observability

* fix(api): preserve Redis proxy constructor
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.

3 participants