/
propagating_tags.go
68 lines (59 loc) · 1.87 KB
/
propagating_tags.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
package tracer
func (t *trace) hasPropagatingTag(k string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
_, ok := t.propagatingTags[k]
return ok
}
func (t *trace) propagatingTag(k string) string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.propagatingTags[k]
}
// setPropagatingTag sets the key/value pair as a trace propagating tag.
func (t *trace) setPropagatingTag(key, value string) {
t.mu.Lock()
defer t.mu.Unlock()
t.setPropagatingTagLocked(key, value)
}
// setPropagatingTagLocked sets the key/value pair as a trace propagating tag.
// Not safe for concurrent use, setPropagatingTag should be used instead in that case.
func (t *trace) setPropagatingTagLocked(key, value string) {
if t.propagatingTags == nil {
t.propagatingTags = make(map[string]string, 1)
}
t.propagatingTags[key] = value
}
// unsetPropagatingTag deletes the key/value pair from the trace's propagated tags.
func (t *trace) unsetPropagatingTag(key string) {
t.mu.Lock()
defer t.mu.Unlock()
delete(t.propagatingTags, key)
}
// iteratePropagatingTags allows safe iteration through the propagating tags of a trace.
// the trace must not be modified during this call, as it is locked for reading.
//
// f should return whether or not the iteration should continue.
func (t *trace) iteratePropagatingTags(f func(k, v string) bool) {
t.mu.RLock()
defer t.mu.RUnlock()
for k, v := range t.propagatingTags {
if !f(k, v) {
break
}
}
}
func (t *trace) replacePropagatingTags(tags map[string]string) {
t.mu.Lock()
defer t.mu.Unlock()
t.propagatingTags = tags
}
func (t *trace) propagatingTagsLen() int {
t.mu.RLock()
defer t.mu.RUnlock()
return len(t.propagatingTags)
}