Repository navigation
feat(client): add process-level and per-client custom attributes to OTel metrics - #3573
Conversation
f992653 to
0343a43
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4c4bdc61c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
62c09e4 to
e25b553
Compare
Let callers set metrics.customAttributes in OpenTelemetry.init. Every metric data point from every client in the process carries them, and a custom key replaces a built-in attribute with the same key. withCustomAttributes merges them at each recording site. With no custom attributes set, the call site's object passes through as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Let callers set metrics.customAttributes in the client options. Every metric that client emits carries them, over the process-level ones, and two clients in one process never share or mix them. Pools pass them through their client options, clusters through defaults, and sentinels through nodeClientOptions and sentinelClientOptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69f47c6 to
69a416d
Compare
Unregister the client from the metrics registry only after destroySocket() publishes CONNECTION_CLOSED, so close() still resolves the client's attributes on redis.client.connection.closed. Pass the client ID through the client-side cache, so eviction events (full, ttl, invalidation) carry the client's attributes on redis.client.csc.evictions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69a416d to
81a5af5
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 81a5af5. Configure here.

Description
This pull request adds custom attributes to node-redis OpenTelemetry metrics, so users can label metrics with their own values, such as the service, team or environment. Users who run several clients in one process can also tell those clients apart in dashboards. Before this, the only per-client attribute was a random pool name, and command metrics didn't carry it.
Attributes can be set at two levels:
customAttributesinOpenTelemetry.init({ metrics }). Applies to every metric from every client in the process.metrics: { customAttributes }in the client options. Applies to every metric that client emits. Pools pass it through their client options, clusters throughdefaults, and sentinels throughnodeClientOptionsandsentinelClientOptions, the same way other per-client options work.When a key is set more than once, the most specific value wins: client attributes, then process attributes, then the attributes node-redis sets. Two clients in one process never share or mix attributes.
Checklist
npm testpass with this change (including linting)?Note
Medium Risk
Touches all OTel metric attribute paths and close/unregister ordering; misuse of high-cardinality or built-in attribute keys can skew dashboards or backend cost.
Overview
Adds custom OpenTelemetry metric attributes at two levels: process-wide via
OpenTelemetry.init({ metrics: { customAttributes } })and per client viametrics.customAttributeson client options (clusters/sentinels use the same patterns as other per-client settings). A newwithCustomAttributeshelper merges labels onto every instrument—client overrides process, which overrides built-ins—so multi-client processes can separate metrics without cross-mixing.Client-side cache eviction/request events now carry
clientIdthrough invalidation and capacity paths so CSC metrics stay attributed to the right client.close()defers metrics registry unregister until after the connection-closed event is published, preserving per-client labels on the closed-connection metric.Documentation, the
otel-metricsexample, and broad unit/e2e tests cover merge precedence, overriding built-in keys, isolation across clients/clusters, and real cache evictions.Reviewed by Cursor Bugbot for commit 81a5af5. Bugbot is set up for automated code reviews on this repo. Configure here.