mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-03-29 21:47:00 +02:00
add APIs for traceoption and tracestate. (#60)
* add APIs for traceoption and tracestate. * remove tracestate and refactor traceoptions.
This commit is contained in:
parent
dad5622903
commit
0edf31e1c6
@ -23,9 +23,19 @@ type TraceID struct {
|
||||
Low uint64
|
||||
}
|
||||
|
||||
const (
|
||||
traceOptionBitMaskSampled = byte(0x01)
|
||||
traceOptionBitMaskUnused = byte(0xFE)
|
||||
|
||||
// TraceOptionSampled is a byte with sampled bit set. It is a convenient value initialize
|
||||
// SpanContext when a trace is sampled.
|
||||
TraceOptionSampled = traceOptionBitMaskSampled
|
||||
)
|
||||
|
||||
type SpanContext struct {
|
||||
TraceID TraceID
|
||||
SpanID uint64
|
||||
TraceID TraceID
|
||||
SpanID uint64
|
||||
TraceOptions byte
|
||||
}
|
||||
|
||||
var (
|
||||
@ -52,3 +62,7 @@ func (sc SpanContext) TraceIDString() string {
|
||||
p2 := fmt.Sprintf("%.16x", sc.TraceID.Low)
|
||||
return p1[0:3] + ".." + p2[13:16]
|
||||
}
|
||||
|
||||
func (sc SpanContext) IsSampled() bool {
|
||||
return sc.TraceOptions&traceOptionBitMaskSampled == traceOptionBitMaskSampled
|
||||
}
|
||||
|
@ -135,3 +135,45 @@ func TestTraceIDString(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpanContextIsSampled(t *testing.T) {
|
||||
for _, testcase := range []struct {
|
||||
name string
|
||||
sc SpanContext
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "sampled",
|
||||
sc: SpanContext{
|
||||
TraceID: TraceID{
|
||||
High: uint64(42),
|
||||
Low: uint64(42),
|
||||
},
|
||||
TraceOptions: TraceOptionSampled,
|
||||
},
|
||||
want: true,
|
||||
}, {
|
||||
name: "sampled plus unused",
|
||||
sc: SpanContext{
|
||||
TraceID: TraceID{
|
||||
High: uint64(42),
|
||||
Low: uint64(42),
|
||||
},
|
||||
TraceOptions: TraceOptionSampled | traceOptionBitMaskUnused,
|
||||
},
|
||||
want: true,
|
||||
}, {
|
||||
name: "not sampled/default",
|
||||
sc: SpanContext{TraceID: TraceID{}},
|
||||
want: false,
|
||||
},
|
||||
} {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
//proto: func (sc SpanContext) TraceIDString() string {}
|
||||
have := testcase.sc.IsSampled()
|
||||
if have != testcase.want {
|
||||
t.Errorf("Want: %v, but have: %v", testcase.want, have)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
3
go.mod
3
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/golang/mock v1.2.0 // indirect
|
||||
github.com/golang/protobuf v1.3.1 // indirect
|
||||
github.com/golangci/golangci-lint v1.17.1
|
||||
github.com/google/go-cmp v0.3.0 // indirect
|
||||
github.com/google/go-cmp v0.3.0
|
||||
github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac
|
||||
github.com/onsi/ginkgo v1.8.0 // indirect
|
||||
github.com/onsi/gomega v1.5.0 // indirect
|
||||
@ -20,6 +20,7 @@ require (
|
||||
golang.org/x/sys v0.0.0-20190614160838-b47fdc937951 // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd
|
||||
google.golang.org/appengine v1.4.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect
|
||||
google.golang.org/grpc v1.21.1
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user