@@ -114,22 +114,25 @@ func New(ctx context.Context, cfg *Config) (*Cache, func() error, error) {
114114
115115// Get retrieves the value for the specified key from Redis.
116116func (c * Cache ) Get (ctx context.Context , key string ) (string , error ) {
117- result , err := c .Client .Get (ctx , key ).Result ()
117+ tracer := otel .Tracer (telemetry .ScopeName , trace .WithInstrumentationVersion (telemetry .ScopeVersion ))
118+ spanCtx , span := tracer .Start (ctx , "redis_get" )
119+ defer span .End ()
120+ result , err := c .Client .Get (spanCtx , key ).Result ()
118121 if c .metrics != nil {
119122 attrs := []attribute.KeyValue {
120123 telemetry .AttrOperation .String ("get" ),
121124 }
122125 switch {
123126 case err == redis .Nil :
124- c .metrics .CacheMissesTotal .Add (ctx , 1 , metric .WithAttributes (attrs ... ))
125- c .metrics .CacheOperationsTotal .Add (ctx , 1 ,
127+ c .metrics .CacheMissesTotal .Add (spanCtx , 1 , metric .WithAttributes (attrs ... ))
128+ c .metrics .CacheOperationsTotal .Add (spanCtx , 1 ,
126129 metric .WithAttributes (append (attrs , telemetry .AttrStatus .String ("miss" ))... ))
127130 case err != nil :
128- c .metrics .CacheOperationsTotal .Add (ctx , 1 ,
131+ c .metrics .CacheOperationsTotal .Add (spanCtx , 1 ,
129132 metric .WithAttributes (append (attrs , telemetry .AttrStatus .String ("error" ))... ))
130133 default :
131- c .metrics .CacheHitsTotal .Add (ctx , 1 , metric .WithAttributes (attrs ... ))
132- c .metrics .CacheOperationsTotal .Add (ctx , 1 ,
134+ c .metrics .CacheHitsTotal .Add (spanCtx , 1 , metric .WithAttributes (attrs ... ))
135+ c .metrics .CacheOperationsTotal .Add (spanCtx , 1 ,
133136 metric .WithAttributes (append (attrs , telemetry .AttrStatus .String ("hit" ))... ))
134137 }
135138 }
@@ -149,8 +152,11 @@ func (c *Cache) Set(ctx context.Context, key, value string, ttl time.Duration) e
149152
150153// Delete removes the specified key from Redis.
151154func (c * Cache ) Delete (ctx context.Context , key string ) error {
152- err := c .Client .Del (ctx , key ).Err ()
153- c .recordOperation (ctx , "delete" , err )
155+ tracer := otel .Tracer (telemetry .ScopeName , trace .WithInstrumentationVersion (telemetry .ScopeVersion ))
156+ spanCtx , span := tracer .Start (ctx , "redis_delete" )
157+ defer span .End ()
158+ err := c .Client .Del (spanCtx , key ).Err ()
159+ c .recordOperation (spanCtx , "delete" , err )
154160 return err
155161}
156162
0 commit comments