-
Notifications
You must be signed in to change notification settings - Fork 0
/
span.go
96 lines (75 loc) · 1.93 KB
/
span.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 ot_logfmt
import (
"bytes"
"log"
"github.com/go-logfmt/logfmt"
opentracing "github.com/opentracing/opentracing-go"
tlog "github.com/opentracing/opentracing-go/log"
)
type span struct {
tracer *tracer
tagEnc *logfmt.Encoder
tagBuf *bytes.Buffer
operationName string
}
func newSpan(t *tracer, operationName string) *span {
tagBuf := &bytes.Buffer{}
return &span{
tracer: t,
tagEnc: logfmt.NewEncoder(tagBuf),
tagBuf: tagBuf,
operationName: operationName}
}
func (s *span) Finish() {}
func (s *span) FinishWithOptions(opts opentracing.FinishOptions) {}
func (s *span) Context() opentracing.SpanContext {
return defaultNoopSpanContext
}
func (s *span) SetOperationName(operationName string) opentracing.Span {
s.operationName = operationName
return s
}
func (s *span) SetTag(key string, value interface{}) opentracing.Span {
err := s.tagEnc.EncodeKeyval(key, value)
if err != nil {
// TODO: Deal with our failures
panic(err)
}
return s
}
func (s *span) LogFields(fields ...tlog.Field) {
buf := bytes.Buffer{}
enc := logfmt.NewEncoder(&buf)
for _, f := range fields {
err := enc.EncodeKeyval(f.Key(), f.Value())
if err != nil {
// TODO: Deal with our failures
panic(err)
}
}
buf.Write([]byte{' '})
r := bytes.NewReader(s.tagBuf.Bytes())
buf.ReadFrom(r)
log.Println(buf.String())
}
func (s *span) LogKV(alternatingKeyValues ...interface{}) {
}
func (s *span) SetBaggageItem(restrictedKey, value string) opentracing.Span {
return s
}
func (s *span) BaggageItem(restrictedKey string) string {
return ""
}
func (s *span) Tracer() opentracing.Tracer {
return s.tracer
}
// Deprecated in the standard, not implemented here.
func (s *span) LogEvent(event string) {
panic("not implemented")
}
func (s *span) LogEventWithPayload(event string, payload interface{}) {
panic("not implemented")
}
func (s *span) Log(data opentracing.LogData) {
panic("not implemented")
}