github.com/thanos-io/thanos@v0.32.5/pkg/cache/tracing_cache.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package cache 5 6 import ( 7 "context" 8 "time" 9 10 "github.com/opentracing/opentracing-go" 11 12 "github.com/thanos-io/thanos/pkg/tracing" 13 ) 14 15 // TracingCache includes Fetch operation in the traces. 16 type TracingCache struct { 17 c Cache 18 } 19 20 func NewTracingCache(cache Cache) Cache { 21 return TracingCache{c: cache} 22 } 23 24 func (t TracingCache) Store(data map[string][]byte, ttl time.Duration) { 25 t.c.Store(data, ttl) 26 } 27 28 func (t TracingCache) Fetch(ctx context.Context, keys []string) (result map[string][]byte) { 29 tracing.DoWithSpan(ctx, "cache_fetch", func(spanCtx context.Context, span opentracing.Span) { 30 span.SetTag("name", t.Name()) 31 span.LogKV("requested keys", len(keys)) 32 33 result = t.c.Fetch(spanCtx, keys) 34 35 bytes := 0 36 for _, v := range result { 37 bytes += len(v) 38 } 39 span.LogKV("returned keys", len(result), "returned bytes", bytes) 40 }) 41 return 42 } 43 44 func (t TracingCache) Name() string { 45 return t.c.Name() 46 }