forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_tracing.go
84 lines (69 loc) · 2.58 KB
/
service_tracing.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
package pkger
import (
"context"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/opentracing/opentracing-go/log"
)
type traceMW struct {
next SVC
}
// MWTracing adds tracing functionality for the service.
func MWTracing() SVCMiddleware {
return func(svc SVC) SVC {
return &traceMW{next: svc}
}
}
var _ SVC = (*traceMW)(nil)
func (s *traceMW) InitStack(ctx context.Context, userID influxdb.ID, newStack StackCreate) (Stack, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.InitStack(ctx, userID, newStack)
}
func (s *traceMW) UninstallStack(ctx context.Context, identifiers struct{ OrgID, UserID, StackID influxdb.ID }) (Stack, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.UninstallStack(ctx, identifiers)
}
func (s *traceMW) DeleteStack(ctx context.Context, identifiers struct{ OrgID, UserID, StackID influxdb.ID }) error {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.DeleteStack(ctx, identifiers)
}
func (s *traceMW) ListStacks(ctx context.Context, orgID influxdb.ID, f ListFilter) ([]Stack, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
stacks, err := s.next.ListStacks(ctx, orgID, f)
span.LogFields(
log.String("org_id", orgID.String()),
log.Int("num_stacks", len(stacks)),
)
return stacks, err
}
func (s *traceMW) ReadStack(ctx context.Context, id influxdb.ID) (Stack, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.ReadStack(ctx, id)
}
func (s *traceMW) UpdateStack(ctx context.Context, upd StackUpdate) (Stack, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.UpdateStack(ctx, upd)
}
func (s *traceMW) Export(ctx context.Context, opts ...ExportOptFn) (template *Template, err error) {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
return s.next.Export(ctx, opts...)
}
func (s *traceMW) DryRun(ctx context.Context, orgID, userID influxdb.ID, opts ...ApplyOptFn) (ImpactSummary, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
span.LogKV("orgID", orgID.String(), "userID", userID.String())
defer span.Finish()
return s.next.DryRun(ctx, orgID, userID, opts...)
}
func (s *traceMW) Apply(ctx context.Context, orgID, userID influxdb.ID, opts ...ApplyOptFn) (ImpactSummary, error) {
span, ctx := tracing.StartSpanFromContext(ctx)
span.LogKV("orgID", orgID.String(), "userID", userID.String())
defer span.Finish()
return s.next.Apply(ctx, orgID, userID, opts...)
}