Skip to content

feat(client): add process-level and per-client custom attributes to OTel metrics - #3573

Open
PavelPashov wants to merge 2 commits into
redis:masterfrom
PavelPashov:feat/otel-custom-attributes
Open

PavelPashov wants to merge 2 commits into
redis:masterfrom
PavelPashov:feat/otel-custom-attributes

Conversation

@PavelPashov

@PavelPashov PavelPashov commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Process: customAttributes in OpenTelemetry.init({ metrics }). Applies to every metric from every client in the process.
  • Client: metrics: { customAttributes } in the client options. Applies to every metric that client emits. Pools pass it through their client options, clusters through defaults, and sentinels through nodeClientOptions and sentinelClientOptions, the same way other per-client options work.
OpenTelemetry.init({ metrics: { enabled: true, customAttributes: { env: 'production' } } });

const orders = createClient({ metrics: { customAttributes: { app: 'orders' } } });
const billing = createCluster({
  rootNodes,
  defaults: { metrics: { customAttributes: { app: 'billing' } } },
});

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

  • 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
Changes affect all metric data point labels; misconfigured high-cardinality custom attributes or overriding built-in keys like server.address can inflate time series cost and alter grouping, though behavior is additive and well-tested.

Overview
Adds custom attributes on OpenTelemetry metrics so dashboards can label series by environment, service, team, or individual Redis clients in the same process.

Configuration is two-tier: customAttributes in OpenTelemetry.init({ metrics }) applies process-wide, and metrics.customAttributes on client options (including cluster defaults / sentinel node options) applies per client and wins on key conflicts over process-level values. Built-in node-redis attributes are merged first and can be replaced if the same key is used in customAttributes.

Implementation threads client options through the metrics registry handle and merges labels via withCustomAttributes on every instrument path (commands, connections, errors, pub/sub, streams, CSC, gauges). Docs, the otel-metrics example, and unit/E2E tests cover precedence, built-in overrides, and isolation between multiple clients/clusters.

Reviewed by Cursor Bugbot for commit c16e7b0. Bugbot is set up for automated code reviews on this repo. Configure here.

@PavelPashov
PavelPashov force-pushed the feat/otel-custom-attributes branch 2 times, most recently from f992653 to 0343a43 Compare November 2, 2026 16:29
@PavelPashov
PavelPashov marked this pull request as ready for review November 3, 2026 11:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T16:26:55.178865Z c16e7b0 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f4c4bdc. Configure here.

@PavelPashov PavelPashov changed the title feat(client): add customAttributes to OTel metrics config feat(client): add process-level and per-client custom attributes to OTel metrics Nov 3, 2026
@PavelPashov
PavelPashov force-pushed the feat/otel-custom-attributes branch from 62c09e4 to e25b553 Compare November 3, 2026 16:19
PavelPashov and others added 2 commits November 3, 2026 18:20
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>
@PavelPashov
PavelPashov force-pushed the feat/otel-custom-attributes branch from e25b553 to c16e7b0 Compare November 3, 2026 16:23

This branch has not been deployed

No deployments
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.

1 participant