Skip to content

OTel-Native: Fix metric instrument types#3743

Merged
ndyakov merged 21 commits into
masterfrom
fix/metric-instrument-types
Apr 21, 2026
Merged

OTel-Native: Fix metric instrument types#3743
ndyakov merged 21 commits into
masterfrom
fix/metric-instrument-types

Conversation

@ofekshenawa

@ofekshenawa ofekshenawa commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

This PR updates the redisotel-native observability instrumentation to use the correct OpenTelemetry instrument types for connection pool metrics, as specified by the OTel database semantic conventions v1.38.0.

Metric instrument type migration:

  • db.client.connection.count: Changed from ObservableGauge (async polling) → UpDownCounter (synchronous increment/decrement)
  • db.client.connection.pending_requests: Changed from ObservableGaugeUpDownCounter

fix #3730


Note

Medium Risk
Touches hot-path connection pool lifecycle and shutdown logic to emit metric deltas, so mistakes could cause incorrect counts or edge-case races under concurrency, though changes are scoped to instrumentation.

Overview
Updates redisotel-native to match OTel DB semconv by switching db.client.connection.count and db.client.connection.pending_requests from async ObservableGauge polling to synchronous Int64UpDownCounter instruments.

Removes the pool registry + RegisterCallback gauge polling and instead emits +/- deltas from internal/pool on connection create/idle↔used transitions, pending-request wait start/stop, PubSub track/untrack, and pool shutdown; also adds an optional OTelConnectionCounter interface (wired through the otelRecorderAdapter) so existing third-party OTelRecorder implementations aren’t broken by the new methods.

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

@jit-ci

jit-ci Bot commented Mar 22, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@ofekshenawa ofekshenawa force-pushed the fix/metric-instrument-types branch from 64f576c to 858116f Compare March 22, 2026 15:21
@ofekshenawa ofekshenawa marked this pull request as ready for review March 22, 2026 15:36
Comment thread internal/pool/pool.go Outdated
Comment thread internal/pool/pool.go
@ofekshenawa ofekshenawa changed the title Fix/metric instrument types Fix metric instrument types Mar 22, 2026
Fix two bugs in the UpDownCounter metric instrumentation:

1. Cache miss path double-counts idle connections (High Severity):
   newConn() records +1 idle for every new connection, but the cache miss
   path in getConn() only recorded +1 used without compensating -1 idle.
   This caused the idle counter to grow unboundedly. Fixed by adding
   -1 idle compensation in the cache miss path and in the hook failure
   path for new connections.

2. Hook-rejected idle connection causes incorrect state accounting
   (Medium Severity): When a hook rejects an idle connection without
   error, putConnWithoutTurn calls putConn which records -1 used, +1 idle.
   But the connection was never transitioned to used state, causing the
   used counter to go negative. Fixed by recording the idle->used
   transition before calling putConnWithoutTurn so putConn's used->idle
   accounting is balanced.
Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 9, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

ndyakov
ndyakov previously approved these changes Apr 9, 2026

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, let's see in which order we would like to merge them with #3770

@jit-ci

jit-ci Bot commented Apr 10, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 10, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go Outdated
@jit-ci

jit-ci Bot commented Apr 10, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@jit-ci

jit-ci Bot commented Apr 10, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

3 similar comments
@jit-ci

jit-ci Bot commented Apr 11, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

@jit-ci

jit-ci Bot commented Apr 12, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

@jit-ci

jit-ci Bot commented Apr 13, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

@ofekshenawa

Copy link
Copy Markdown
Collaborator Author

@sera bypass

@jit-ci

jit-ci Bot commented Apr 20, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

Comment thread internal/pool/pool.go
@ofekshenawa ofekshenawa changed the title Fix metric instrument types OTel-Native: Fix metric instrument types Apr 20, 2026

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me!

@jit-ci

jit-ci Bot commented Apr 21, 2026

Copy link
Copy Markdown

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


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

@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 and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e144ad7. Configure here.

Comment thread internal/pool/pool.go
@ndyakov ndyakov merged commit 6cc94eb into master Apr 21, 2026
67 of 69 checks passed
@ndyakov ndyakov deleted the fix/metric-instrument-types branch April 21, 2026 11:12
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.

bug(redisotel-native): some metric type and description does not follow semconv

2 participants