1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-08 08:42:11 +03:00

Adds connection state metrics

Signed-off-by: Elena Kolevska <elena@kolevska.com>
This commit is contained in:
Elena Kolevska
2025-10-27 18:02:15 +00:00
committed by ofekshenawa
parent d588c3ca71
commit 2a7725db63
5 changed files with 157 additions and 1 deletions

12
otel.go
View File

@@ -24,6 +24,9 @@ type ConnInfo interface {
type OTelRecorder interface {
// RecordOperationDuration records the total operation duration (including all retries)
RecordOperationDuration(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, cn ConnInfo)
// RecordConnectionStateChange records when a connection changes state (e.g., idle -> used)
RecordConnectionStateChange(ctx context.Context, cn ConnInfo, fromState, toState string)
}
// SetOTelRecorder sets the global OpenTelemetry recorder.
@@ -55,3 +58,12 @@ func (a *otelRecorderAdapter) RecordOperationDuration(ctx context.Context, durat
}
}
func (a *otelRecorderAdapter) RecordConnectionStateChange(ctx context.Context, cn *pool.Conn, fromState, toState string) {
// Convert internal pool.Conn to public ConnInfo
var connInfo ConnInfo
if cn != nil {
connInfo = cn
}
a.recorder.RecordConnectionStateChange(ctx, connInfo, fromState, toState)
}