-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtracing.go
96 lines (77 loc) · 2.07 KB
/
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
85
86
87
88
89
90
91
92
93
94
95
96
package gocb
import (
"github.com/couchbase/gocbcore/v8"
)
func tracerAddRef(tracer requestTracer) {
if tracer == nil {
return
}
if refTracer, ok := tracer.(interface {
AddRef() int32
}); ok {
refTracer.AddRef()
}
}
func tracerDecRef(tracer requestTracer) {
if tracer == nil {
return
}
if refTracer, ok := tracer.(interface {
DecRef() int32
}); ok {
refTracer.DecRef()
}
}
// requestTracer describes the tracing abstraction in the SDK.
type requestTracer interface {
StartSpan(operationName string, parentContext requestSpanContext) requestSpan
}
// requestSpan is the interface for spans that are created by a requestTracer.
type requestSpan interface {
Finish()
Context() requestSpanContext
SetTag(key string, value interface{}) requestSpan
}
// requestSpanContext is the interface for for external span contexts that can be passed in into the SDK option blocks.
type requestSpanContext interface {
}
type requestTracerWrapper struct {
tracer requestTracer
}
func (tracer *requestTracerWrapper) StartSpan(operationName string, parentContext gocbcore.RequestSpanContext) gocbcore.RequestSpan {
return requestSpanWrapper{
span: tracer.tracer.StartSpan(operationName, parentContext),
}
}
type requestSpanWrapper struct {
span requestSpan
}
func (span requestSpanWrapper) Finish() {
span.span.Finish()
}
func (span requestSpanWrapper) Context() gocbcore.RequestSpanContext {
return span.span.Context()
}
func (span requestSpanWrapper) SetTag(key string, value interface{}) gocbcore.RequestSpan {
span.span = span.span.SetTag(key, value)
return span
}
type noopSpan struct{}
type noopSpanContext struct{}
var (
defaultNoopSpanContext = noopSpanContext{}
defaultNoopSpan = noopSpan{}
)
type noopTracer struct {
}
func (tracer *noopTracer) StartSpan(operationName string, parentContext requestSpanContext) requestSpan {
return defaultNoopSpan
}
func (span noopSpan) Finish() {
}
func (span noopSpan) Context() requestSpanContext {
return defaultNoopSpanContext
}
func (span noopSpan) SetTag(key string, value interface{}) requestSpan {
return defaultNoopSpan
}