-
Notifications
You must be signed in to change notification settings - Fork 0
/
span.zzzgo
100 lines (88 loc) · 3.53 KB
/
span.zzzgo
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
97
98
99
100
package xop
import (
"github.com/xoplog/xop-go/xopat"
"github.com/xoplog/xop-go/xopbase"
"github.com/xoplog/xop-go/xoptrace"
"github.com/mohae/deepcopy"
)
// Request provides access to the span that describes the overall
// request. Metadata may be added at the request level.
func (logger *Logger) Request() *Span {
return logger.request.capSpan
}
// Request provides access to the current span
// Metadata may be added at the span level.
func (logger *Logger) Span() *Span {
return logger.capSpan
}
func (span *Span) TraceState() xoptrace.State { return span.seed.traceBundle.State }
func (span *Span) TraceBaggage() xoptrace.Baggage { return span.seed.traceBundle.Baggage }
func (span *Span) ParentTrace() xoptrace.Trace { return span.seed.traceBundle.Parent.Copy() }
func (span *Span) Trace() xoptrace.Trace { return span.seed.traceBundle.Trace.Copy() }
func (span *Span) Bundle() xoptrace.Bundle { return span.seed.traceBundle.Copy() }
func (span *Span) eft() *Span {
span.logger.hasActivity(true)
return span
}
// Int64 adds a int64 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int64(k *xopat.Int64Attribute, v int64) *Span {
span.base.MetadataInt64(k, v)
return span.eft()
}
// EmbeddedEnum adds a kev/value attribute to the Span. The key and the value
// are bundled together: the key is derrived from the type of the Enum.
// Alternatively, use xopat.KeyedEnumAttribute() to create functions
// to add enum key/value pairs where the key and value are specified
// separately. See xopconst.SpanType for an example of creating an
// EmbeddedEnum.
// The return value does not need to be used.
func (span *Span) EmbeddedEnum(kv xopat.EmbeddedEnum) *Span {
return span.Enum(kv.EnumAttribute(), kv)
}
// AnyImmutable adds a key/value attribute to the current Span. The provided
// value must be immutable. If it is not, then there could be race conditions
// or the value that ends up logged could be different from the value at the
// time when AnyImmutible was called.
//
// While the AnyAttribute has an expectation
// for the type of the value, that type may or may not be checked depending
// on the base logger being used.
// The return value does not need to be used.
func (span *Span) AnyImmutable(k *xopat.AnyAttribute, v interface{}) *Span {
span.base.MetadataAny(k, xopbase.ModelArg{
Model: v,
})
return span.eft()
}
// Any adds a key/value attribute to the current Span. The provided
// value may be copied using github.com/mohae/deepcopy if any of the
// base loggers hold the value instead of immediately serializing it.
// While the AnyAttribute has an expectation
// for the type of the value, that type may or may not be checked depending
// on the base logger being used.
// The return value does not need to be used.
func (span *Span) Any(k *xopat.AnyAttribute, v interface{}) *Span {
if span.logger.span.referencesKept {
v = deepcopy.Copy(v)
}
span.base.MetadataAny(k, xopbase.ModelArg{
Model: v,
})
return span.eft()
}
// MACRO BaseAttribute SKIP:Any,Int64
// ZZZ adds a zzz key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) ZZZ(k *xopat.ZZZAttribute, v zzz) *Span {
span.base.MetadataZZZ(k, v)
return span.eft()
}
// should skip Int64
// MACRO IntsPlus SKIP:Int64
// ZZZ adds a zzz key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) ZZZ(k *xopat.ZZZAttribute, v zzz) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}