-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraced_storage.go
111 lines (91 loc) · 2.21 KB
/
traced_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package storage
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
type TracingStorage interface {
Storage
GetMultiple(ctx context.Context, keys []string) ([]Object, error)
}
type tracedStorage struct {
storage Storage
tracer trace.Tracer
}
func NewTracingStorage(storage Storage, tracer trace.Tracer) TracingStorage {
return &tracedStorage{
storage: storage,
tracer: tracer,
}
}
func (s *tracedStorage) Get(ctx context.Context, key string) ([]byte, error) {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "get",
trace.WithAttributes(
attribute.String("key", key),
),
)
defer span.End()
}
return s.storage.Get(ctx, key)
}
func (s *tracedStorage) GetMultiple(ctx context.Context, keys []string) ([]Object, error) {
return s.storage.GetMultiple(ctx, keys)
}
func (s *tracedStorage) Exists(ctx context.Context, key string) (bool, error) {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "exists",
trace.WithAttributes(
attribute.String("key", key),
),
)
defer span.End()
}
return s.storage.Exists(ctx, key)
}
func (s *tracedStorage) List(ctx context.Context, prefix string) ([]Object, error) {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "list",
trace.WithAttributes(
attribute.String("prefix", prefix),
),
)
defer span.End()
}
return s.storage.List(ctx, prefix)
}
func (s *tracedStorage) Delete(ctx context.Context, key string) error {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "delete",
trace.WithAttributes(
attribute.String("key", key),
),
)
defer span.End()
}
return s.storage.Delete(ctx, key)
}
func (s *tracedStorage) Put(ctx context.Context, key string, data []byte) error {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "put",
trace.WithAttributes(
attribute.String("key", key),
),
)
defer span.End()
}
return s.storage.Put(ctx, key, data)
}
func (s *tracedStorage) Purge(ctx context.Context) error {
if s.tracer != nil {
var span trace.Span
ctx, span = s.tracer.Start(ctx, "purge")
defer span.End()
}
return s.storage.Purge(ctx)
}