forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
span.go
44 lines (37 loc) · 1.17 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
package traceutil
import "github.com/ninnemana/datadog-agent/pkg/trace/pb"
const (
// TraceMetricsKey is a tag key which, if set to true,
// ensures all statistics are computed for this span.
// [FIXME] *not implemented yet*
TraceMetricsKey = "datadog.trace_metrics"
// This is a special metric, it's 1 if the span is top-level, 0 if not.
topLevelKey = "_top_level"
)
// HasTopLevel returns true if span is top-level.
func HasTopLevel(s *pb.Span) bool {
return s.Metrics[topLevelKey] == 1
}
// HasForceMetrics returns true if statistics computation should be forced for this span.
func HasForceMetrics(s *pb.Span) bool {
return s.Meta[TraceMetricsKey] == "true"
}
// SetTopLevel sets the top-level attribute of the span.
func SetTopLevel(s *pb.Span, topLevel bool) {
if !topLevel {
if s.Metrics == nil {
return
}
delete(s.Metrics, topLevelKey)
return
}
// Setting the metrics value, so that code downstream in the pipeline
// can identify this as top-level without recomputing everything.
setMetric(s, topLevelKey, 1)
}
func setMetric(s *pb.Span, key string, val float64) {
if s.Metrics == nil {
s.Metrics = make(map[string]float64)
}
s.Metrics[key] = val
}