1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +02:00

Rename TraceFlagsSampled, TraceFlagsUnused

This commit is contained in:
tensorchen 2020-05-06 01:41:54 +08:00
parent 40e8769e83
commit 2ffbd869d7
11 changed files with 38 additions and 38 deletions

View File

@ -56,7 +56,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) {
return
}
if b3.SingleHeader {
sampled := sc.TraceFlags & TraceFlagsSampled
sampled := sc.TraceFlags & FlagsSampled
supplier.Set(B3SingleHeader,
fmt.Sprintf("%s-%s-%.1d", sc.TraceID, sc.SpanID, sampled))
} else {
@ -105,8 +105,8 @@ func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext {
if !ok {
return EmptySpanContext()
}
if debug == TraceFlagsSampled {
sampled = TraceFlagsSampled
if debug == FlagsSampled {
sampled = FlagsSampled
}
sc := SpanContext{
@ -176,14 +176,14 @@ func (b3 B3) extractSampledState(sampled string) (flag byte, ok bool) {
case "", "0":
return 0, true
case "1":
return TraceFlagsSampled, true
return FlagsSampled, true
case "true":
if !b3.SingleHeader {
return TraceFlagsSampled, true
return FlagsSampled, true
}
case "d":
if b3.SingleHeader {
return TraceFlagsSampled, true
return FlagsSampled, true
}
}
return 0, false
@ -195,7 +195,7 @@ func (b3 B3) extracDebugFlag(debug string) (flag byte, ok bool) {
case "", "0":
return 0, true
case "1":
return TraceFlagsSampled, true
return FlagsSampled, true
}
return 0, false
}

View File

@ -24,10 +24,10 @@ const (
traceFlagsBitMaskSampled = byte(0x01)
traceFlagsBitMaskUnused = byte(0xFE)
// TraceFlagsSampled is a byte with sampled bit set. It is a convenient value initializer
// FlagsSampled is a byte with sampled bit set. It is a convenient value initializer
// for SpanContext TraceFlags field when a trace is sampled.
TraceFlagsSampled = traceFlagsBitMaskSampled
TraceFlagsUnused = traceFlagsBitMaskUnused
FlagsSampled = traceFlagsBitMaskSampled
FlagsUnused = traceFlagsBitMaskUnused
ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase"

View File

@ -169,14 +169,14 @@ func TestSpanContextIsSampled(t *testing.T) {
name: "sampled",
sc: trace.SpanContext{
TraceID: trace.ID([16]byte{1}),
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
want: true,
}, {
name: "sampled plus unused",
sc: trace.SpanContext{
TraceID: trace.ID([16]byte{1}),
TraceFlags: trace.TraceFlagsSampled | trace.TraceFlagsUnused,
TraceFlags: trace.FlagsSampled | trace.FlagsUnused,
},
want: true,
}, {

View File

@ -58,7 +58,7 @@ var extractMultipleHeaders = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -71,7 +71,7 @@ var extractMultipleHeaders = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -84,7 +84,7 @@ var extractMultipleHeaders = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -101,7 +101,7 @@ var extractMultipleHeaders = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -115,7 +115,7 @@ var extractMultipleHeaders = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -156,7 +156,7 @@ var extractSingleHeader = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -167,7 +167,7 @@ var extractSingleHeader = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -178,7 +178,7 @@ var extractSingleHeader = []extractTest{
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -446,7 +446,7 @@ var injectB3MultipleHeader = []injectTest{
parentSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
wantHeaders: map[string]string{
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
@ -496,7 +496,7 @@ var injectB3SingleleHeader = []injectTest{
parentSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
wantHeaders: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",

View File

@ -49,7 +49,7 @@ func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) {
sc := trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
}
ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc)
ctx, _ = mockTracer.Start(ctx, "inject")

View File

@ -62,7 +62,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -71,7 +71,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -80,7 +80,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -97,7 +97,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -106,7 +106,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
{
@ -115,7 +115,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
wantSc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
},
}
@ -240,7 +240,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
sc: trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
},
wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01",
},

View File

@ -62,7 +62,7 @@ func (TraceContext) Inject(ctx context.Context, supplier propagation.HTTPSupplie
supportedVersion,
sc.TraceID,
sc.SpanID,
sc.TraceFlags&TraceFlagsSampled)
sc.TraceFlags&FlagsSampled)
supplier.Set(traceparentHeader, h)
}
@ -137,7 +137,7 @@ func (TraceContext) extract(supplier propagation.HTTPSupplier) SpanContext {
if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) {
return EmptySpanContext()
}
sc.TraceFlags = opts[0] &^ TraceFlagsUnused
sc.TraceFlags = opts[0] &^ FlagsUnused
if !sc.IsValid() {
return EmptySpanContext()

View File

@ -69,7 +69,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Star
sc = apitrace.SpanContext{}
_, _ = rand.Read(sc.TraceID[:])
if mt.Sampled {
sc.TraceFlags = apitrace.TraceFlagsSampled
sc.TraceFlags = apitrace.FlagsSampled
}
} else {
sc = parentSpanContext

View File

@ -29,7 +29,7 @@ func TestAlwaysParentSampleWithParentSampled(t *testing.T) {
parentCtx := trace.SpanContext{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.TraceFlagsSampled,
TraceFlags: trace.FlagsSampled,
}
if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled {
t.Error("Sampling decision should be RecordAndSampled")

View File

@ -403,13 +403,13 @@ func makeSamplingDecision(data samplingData) SamplingResult {
Links: data.links,
})
if sampled.Decision == RecordAndSampled {
spanContext.TraceFlags |= apitrace.TraceFlagsSampled
spanContext.TraceFlags |= apitrace.FlagsSampled
} else {
spanContext.TraceFlags &^= apitrace.TraceFlagsSampled
spanContext.TraceFlags &^= apitrace.FlagsSampled
}
return sampled
}
if data.parent.TraceFlags&apitrace.TraceFlagsSampled != 0 {
if data.parent.TraceFlags&apitrace.FlagsSampled != 0 {
return SamplingResult{Decision: RecordAndSampled}
}
return SamplingResult{Decision: NotRecord}

View File

@ -200,7 +200,7 @@ func TestSampling(t *testing.T) {
SpanID: idg.NewSpanID(),
}
if tc.sampledParent {
psc.TraceFlags = apitrace.TraceFlagsSampled
psc.TraceFlags = apitrace.FlagsSampled
}
ctx = apitrace.ContextWithRemoteSpanContext(ctx, psc)
}