Skip to content

add OpenTelemetry metrics instrumentation#3110

Open
PavelPashov wants to merge 52 commits intoredis:masterfrom
PavelPashov:feat/add-opentelemetry-metrics
Open

add OpenTelemetry metrics instrumentation#3110
PavelPashov wants to merge 52 commits intoredis:masterfrom
PavelPashov:feat/add-opentelemetry-metrics

Conversation

@PavelPashov
Copy link
Contributor

@PavelPashov PavelPashov commented Oct 24, 2025

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 6b04331. This will update automatically on new commits. Configure here.

@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch 4 times, most recently from a11117e to 5fb1791 Compare October 31, 2025 11:39
@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch 2 times, most recently from 1be4565 to 03db1a2 Compare November 5, 2025 11:03
Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

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

❌ The following Jit checks failed to run:

  • license-compliance-checker
  • secret-detection-trufflehog
  • software-component-analysis-js
  • static-code-analysis-semgrep-pro

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch 3 times, most recently from 1106f8a to 242e98d Compare November 6, 2025 13:55
@elimelt
Copy link
Contributor

elimelt commented Dec 8, 2025

This is an exciting feature, I hope it makes it to main!

@jit-ci
Copy link

jit-ci bot commented Jan 19, 2026

❌ Security scan failed

Security scan failed: Branch feat/add-opentelemetry-metrics does not exist in the remote repository


💡 Need to bypass this check? Comment @sera bypass to override.

@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch from 364ff86 to 30b0e8c Compare January 19, 2026 08:35
@jit-ci
Copy link

jit-ci bot commented Jan 19, 2026

❌ Security scan failed

Security scan failed: Branch feat/add-opentelemetry-metrics does not exist in the remote repository


💡 Need to bypass this check? Comment @sera bypass to override.

1 similar comment
@jit-ci
Copy link

jit-ci bot commented Jan 19, 2026

❌ Security scan failed

Security scan failed: Branch feat/add-opentelemetry-metrics does not exist in the remote repository


💡 Need to bypass this check? Comment @sera bypass to override.

@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch 2 times, most recently from 0e91b34 to e2cc888 Compare February 20, 2026 15:32
@PavelPashov PavelPashov marked this pull request as ready for review February 25, 2026 11:28
@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch from af9f0fb to d0f42d3 Compare February 25, 2026 11:34
@PavelPashov PavelPashov changed the title wip: add OpenTelemetry metrics instrumentation add OpenTelemetry metrics instrumentation Feb 25, 2026
TRANSFORM_LEGACY_REPLY?: boolean;
transformReply: TransformReply | Record<RespVersions, TransformReply>;
unstableResp3?: boolean;
onSuccess?: (args: ReadonlyArray<RedisArgument>, reply: unknown, clientId: string) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nkaradzhov we might want to rename onSuccess to something more metrics/otel related

Comment on lines +1127 to +1128
if (command.onSuccess) {
command.onSuccess(parser.redisArgs, finalReply, this._self._clientId);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nkaradzhov there might be a better way to record specific command related metrics that require the server response

Comment on lines +65 to +73
// Build the appropriate function based on options
if (options.hasIncludeCommands || options.hasExcludeCommands) {
// Version with filtering
this.createRecordOperationDuration = this.#createWithFiltering.bind(this);
} else {
this.createRecordOperationDuration =
this.#createWithoutFiltering.bind(this);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why have two fns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nkaradzhov to make sure we don't do unnecessary checks after initiating the metrics singleton if the user hasn't provided any included or excluded commands

@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch from bf97457 to adbe066 Compare March 5, 2026 14:57
@PavelPashov PavelPashov force-pushed the feat/add-opentelemetry-metrics branch from adbe066 to bc14732 Compare March 5, 2026 15:01
@PavelPashov
Copy link
Contributor Author

PavelPashov commented Mar 23, 2026

@nkaradzhov & @vladvildanov

Created a separated PR for conversion of ObservableGauges to up UpDownCounters.

After the current PR is released I'll need to create 3 issues for:

  1. redis.client.csc.network_saved - disabled, due to incorrect values computed from inside the metrics class
  2. db.client.connection.count - state is always used, this should be renamed and converted to ObservableGauge in order to be more accurate.
  3. db.client.connection.pending_requests - disabled, should be renamed and remain a ObservableGauge, as converting it to UpDownCounter will likely result in a performance hit when enabled.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

logaretm added a commit to logaretm/node-redis that referenced this pull request Mar 26, 2026
No subscriber existed for this event. The original redis#3110 code only
recorded at wait end, not start. Remove the speculative event.

Co-Authored-By: Claude Opus 4.6 (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.

4 participants