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:
committed by
ofekshenawa
parent
d588c3ca71
commit
2a7725db63
12
otel.go
12
otel.go
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user