25 | 25 |
spanID int64
|
26 | 26 |
parentSpanID int64
|
27 | 27 |
|
28 | |
annotations []annotation
|
29 | |
//binaryAnnotations []BinaryAnnotation // TODO
|
|
28 |
annotations []annotation
|
|
29 |
binaryAnnotations []binaryAnnotation
|
30 | 30 |
}
|
31 | 31 |
|
32 | 32 |
// NewSpan returns a new Span, which can be annotated and collected by a
|
|
93 | 93 |
s.AnnotateDuration(value, 0)
|
94 | 94 |
}
|
95 | 95 |
|
|
96 |
// AnnotateBinary annotates the span with a key and a byte value.
|
|
97 |
func (s *Span) AnnotateBinary(key string, value []byte) {
|
|
98 |
s.binaryAnnotations = append(s.binaryAnnotations, binaryAnnotation{
|
|
99 |
key: key,
|
|
100 |
value: value,
|
|
101 |
annotationType: zipkincore.AnnotationType_BYTES,
|
|
102 |
host: s.host,
|
|
103 |
})
|
|
104 |
}
|
|
105 |
|
|
106 |
// AnnotateString annotates the span with a key and a string value.
|
|
107 |
func (s *Span) AnnotateString(key, value string) {
|
|
108 |
s.binaryAnnotations = append(s.binaryAnnotations, binaryAnnotation{
|
|
109 |
key: key,
|
|
110 |
value: []byte(value),
|
|
111 |
annotationType: zipkincore.AnnotationType_STRING,
|
|
112 |
host: s.host,
|
|
113 |
})
|
|
114 |
}
|
|
115 |
|
96 | 116 |
// AnnotateDuration annotates the span with the given value and duration.
|
97 | 117 |
func (s *Span) AnnotateDuration(value string, duration time.Duration) {
|
98 | 118 |
s.annotations = append(s.annotations, annotation{
|
|
108 | 128 |
// TODO lots of garbage here. We can improve by preallocating e.g. the
|
109 | 129 |
// Thrift stuff into an encoder struct, owned by the ScribeCollector.
|
110 | 130 |
zs := zipkincore.Span{
|
111 | |
TraceId: s.traceID,
|
112 | |
Name: s.methodName,
|
113 | |
Id: s.spanID,
|
114 | |
BinaryAnnotations: []*zipkincore.BinaryAnnotation{}, // TODO
|
115 | |
Debug: true, // TODO
|
|
131 |
TraceId: s.traceID,
|
|
132 |
Name: s.methodName,
|
|
133 |
Id: s.spanID,
|
|
134 |
// BinaryAnnotations: []*zipkincore.BinaryAnnotation{}, // TODO
|
|
135 |
Debug: true, // TODO
|
116 | 136 |
}
|
|
137 |
|
117 | 138 |
if s.parentSpanID != 0 {
|
118 | 139 |
zs.ParentId = new(int64)
|
119 | 140 |
(*zs.ParentId) = s.parentSpanID
|
120 | 141 |
}
|
|
142 |
|
121 | 143 |
zs.Annotations = make([]*zipkincore.Annotation, len(s.annotations))
|
122 | 144 |
for i, a := range s.annotations {
|
123 | 145 |
zs.Annotations[i] = &zipkincore.Annotation{
|
|
125 | 147 |
Value: a.value,
|
126 | 148 |
Host: a.host,
|
127 | 149 |
}
|
|
150 |
|
128 | 151 |
if a.duration > 0 {
|
129 | 152 |
zs.Annotations[i].Duration = new(int32)
|
130 | 153 |
*(zs.Annotations[i].Duration) = int32(a.duration / time.Microsecond)
|
131 | 154 |
}
|
132 | 155 |
}
|
|
156 |
|
|
157 |
zs.BinaryAnnotations = make([]*zipkincore.BinaryAnnotation, len(s.binaryAnnotations))
|
|
158 |
for i, a := range s.binaryAnnotations {
|
|
159 |
zs.BinaryAnnotations[i] = &zipkincore.BinaryAnnotation{
|
|
160 |
Key: a.key,
|
|
161 |
Value: a.value,
|
|
162 |
AnnotationType: a.annotationType,
|
|
163 |
Host: a.host,
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
133 | 167 |
return &zs
|
134 | 168 |
}
|
135 | 169 |
|
|
139 | 173 |
duration time.Duration // optional
|
140 | 174 |
host *zipkincore.Endpoint
|
141 | 175 |
}
|
|
176 |
|
|
177 |
type binaryAnnotation struct {
|
|
178 |
key string
|
|
179 |
value []byte
|
|
180 |
annotationType zipkincore.AnnotationType
|
|
181 |
host *zipkincore.Endpoint
|
|
182 |
}
|