add OpenTelemetry metrics instrumentation

Merged
PA
7mo ago
+6092-180

Description

TODO

  • Add docs
  • Add examples

Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

[!NOTE]
Medium Risk
Touches core request/connection paths (RedisClient, RedisSocket, queues, cluster redirection) to emit metrics and maintain per-client identity/registry, so mistakes could add overhead or skew counts. Functional behavior should be unchanged, but instrumentation around errors/closures and cache invalidation needs careful review.

Overview
Adds first-class OpenTelemetry metrics support via a new OpenTelemetry.init() entrypoint and an internal metrics/registry layer that can be enabled before client creation.

Instruments core client operations to emit metrics for command durations (including MULTI/PIPELINE batches), connection lifecycle (create time, active count, close reasons, relaxed timeouts, handoff), resiliency/errors (including cluster redirections and maintenance notifications), pub/sub message in/out, stream lag from XREAD/XREADGROUP, and client-side caching hits/misses/evictions.

Introduces stable per-client identity (_clientId) and a ClientRegistry so observable gauges and metric attribution can track standalone clients, pools, and cluster nodes; updates pool/cluster/node creation to set roles/parent IDs and unregisters clients on close/destroy/quit. Documentation and an otel-metrics.js example are added, along with new OpenTelemetry dev dependencies and extensive tests for the metrics implementation.

Written by Cursor Bugbot for commit 6b0433169d9dc7cd0f337e89695662cb30b99889. This will update automatically on new commits. Configure here.