@@ -8,6 +8,13 @@ import (
88 "github.com/redis/go-redis/v9/internal"
99)
1010
11+ // contextKey is a custom type for context keys to avoid collisions
12+ type contextKey string
13+
14+ const (
15+ startTimeKey contextKey = "start_time"
16+ )
17+
1118// MetricsHook collects metrics about notification processing.
1219type MetricsHook struct {
1320 NotificationCounts map [string ]int64
@@ -30,15 +37,15 @@ func (mh *MetricsHook) PreHook(ctx context.Context, notificationType string, not
3037
3138 // Store start time in context for duration calculation
3239 startTime := time .Now ()
33- _ = context .WithValue (ctx , "start_time" , startTime ) // Context not used further
40+ _ = context .WithValue (ctx , startTimeKey , startTime ) // Context not used further
3441
3542 return notification , true
3643}
3744
3845// PostHook records processing completion and any errors.
3946func (mh * MetricsHook ) PostHook (ctx context.Context , notificationType string , notification []interface {}, result error ) {
4047 // Calculate processing duration
41- if startTime , ok := ctx .Value ("start_time" ).(time.Time ); ok {
48+ if startTime , ok := ctx .Value (startTimeKey ).(time.Time ); ok {
4249 duration := time .Since (startTime )
4350 mh .ProcessingTimes [notificationType ] = duration
4451 }
0 commit comments