diff --git a/api/trace/b3_propagator.go b/api/trace/b3_propagator.go index 349a4d274..fe78f8727 100644 --- a/api/trace/b3_propagator.go +++ b/api/trace/b3_propagator.go @@ -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 } diff --git a/api/trace/span_context.go b/api/trace/span_context.go index 309cd6379..b15975568 100644 --- a/api/trace/span_context.go +++ b/api/trace/span_context.go @@ -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" diff --git a/api/trace/span_context_test.go b/api/trace/span_context_test.go index b94c1b1b0..74a314bd3 100644 --- a/api/trace/span_context_test.go +++ b/api/trace/span_context_test.go @@ -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, }, { diff --git a/api/trace/testtrace/b3_propagator_data_test.go b/api/trace/testtrace/b3_propagator_data_test.go index c7a1abc41..6cb4a092c 100644 --- a/api/trace/testtrace/b3_propagator_data_test.go +++ b/api/trace/testtrace/b3_propagator_data_test.go @@ -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", diff --git a/api/trace/testtrace/trace_context_propagator_benchmark_test.go b/api/trace/testtrace/trace_context_propagator_benchmark_test.go index 413aadad3..f6ebc4d85 100644 --- a/api/trace/testtrace/trace_context_propagator_benchmark_test.go +++ b/api/trace/testtrace/trace_context_propagator_benchmark_test.go @@ -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") diff --git a/api/trace/testtrace/trace_context_propagator_test.go b/api/trace/testtrace/trace_context_propagator_test.go index 513d63147..2a8fea2fc 100644 --- a/api/trace/testtrace/trace_context_propagator_test.go +++ b/api/trace/testtrace/trace_context_propagator_test.go @@ -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", }, diff --git a/api/trace/trace_context_propagator.go b/api/trace/trace_context_propagator.go index 2792e91b3..d8263745e 100644 --- a/api/trace/trace_context_propagator.go +++ b/api/trace/trace_context_propagator.go @@ -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() diff --git a/internal/trace/mock_tracer.go b/internal/trace/mock_tracer.go index 4498434e8..6c58dff01 100644 --- a/internal/trace/mock_tracer.go +++ b/internal/trace/mock_tracer.go @@ -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 diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 6e0a8f540..ff89c4517 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -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") diff --git a/sdk/trace/span.go b/sdk/trace/span.go index dc24d3c21..9753968d2 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -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} diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 137e85f22..c96d6bce7 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -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) }