From 8d55ed32680696e4e2d28d3c965f6f9773740624 Mon Sep 17 00:00:00 2001 From: rahulpa Date: Wed, 25 Sep 2019 10:42:54 -0700 Subject: [PATCH] change TraceOptions to TraceFlags. --- api/core/span_context.go | 18 ++--- api/core/span_context_test.go | 4 +- experimental/bridge/opentracing/bridge.go | 16 ++--- .../bridge/opentracing/internal/mock.go | 6 +- exporter/trace/jaeger/jaeger.go | 2 +- internal/trace/mock_tracer.go | 2 +- propagation/http_trace_context_propagator.go | 4 +- .../http_trace_context_propagator_test.go | 50 +++++++------- sdk/trace/simple_span_processor_test.go | 6 +- sdk/trace/span.go | 6 +- sdk/trace/trace_test.go | 66 +++++++++---------- 11 files changed, 90 insertions(+), 90 deletions(-) diff --git a/api/core/span_context.go b/api/core/span_context.go index 078cc8a63bb9..fbe9150347aa 100644 --- a/api/core/span_context.go +++ b/api/core/span_context.go @@ -24,19 +24,19 @@ type TraceID struct { } const ( - traceOptionBitMaskSampled = byte(0x01) - traceOptionBitMaskUnused = byte(0xFE) + traceFlagsBitMaskSampled = byte(0x01) + traceFlagsBitMaskUnused = byte(0xFE) - // TraceOptionSampled is a byte with sampled bit set. It is a convenient value initialize + // TraceFlagsSampled is a byte with sampled bit set. It is a convenient value initialize // SpanContext when a trace is sampled. - TraceOptionSampled = traceOptionBitMaskSampled - TraceOptionUnused = traceOptionBitMaskUnused + TraceFlagsSampled = traceFlagsBitMaskSampled + TraceFlagsUnused = traceFlagsBitMaskUnused ) type SpanContext struct { - TraceID TraceID - SpanID uint64 - TraceOptions byte + TraceID TraceID + SpanID uint64 + TraceFlags byte } // EmptySpanContext is meant for internal use to return invalid span context during error conditions. @@ -67,5 +67,5 @@ func (sc SpanContext) TraceIDString() string { } func (sc SpanContext) IsSampled() bool { - return sc.TraceOptions&traceOptionBitMaskSampled == traceOptionBitMaskSampled + return sc.TraceFlags&traceFlagsBitMaskSampled == traceFlagsBitMaskSampled } diff --git a/api/core/span_context_test.go b/api/core/span_context_test.go index 2b72735951fd..f0b5fa4299e8 100644 --- a/api/core/span_context_test.go +++ b/api/core/span_context_test.go @@ -193,7 +193,7 @@ func TestSpanContextIsSampled(t *testing.T) { High: uint64(42), Low: uint64(42), }, - TraceOptions: core.TraceOptionSampled, + TraceFlags: core.TraceFlagsSampled, }, want: true, }, { @@ -203,7 +203,7 @@ func TestSpanContextIsSampled(t *testing.T) { High: uint64(42), Low: uint64(42), }, - TraceOptions: core.TraceOptionSampled | core.TraceOptionUnused, + TraceFlags: core.TraceFlagsSampled | core.TraceFlagsUnused, }, want: true, }, { diff --git a/experimental/bridge/opentracing/bridge.go b/experimental/bridge/opentracing/bridge.go index 3bf937971339..4880af116a01 100644 --- a/experimental/bridge/opentracing/bridge.go +++ b/experimental/bridge/opentracing/bridge.go @@ -491,7 +491,7 @@ func otSpanReferenceTypeToOtelRelationshipType(srt ot.SpanReferenceType) oteltra var ( traceIDHeader = http.CanonicalHeaderKey("x-otelbridge-trace-id") spanIDHeader = http.CanonicalHeaderKey("x-otelbridge-span-id") - traceOptionsHeader = http.CanonicalHeaderKey("x-otelbridge-trace-options") + traceFlagsHeader = http.CanonicalHeaderKey("x-otelbridge-trace-flags") baggageHeaderPrefix = http.CanonicalHeaderKey("x-otelbridge-baggage-") ) @@ -516,7 +516,7 @@ func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier int } hhcarrier.Set(traceIDHeader, traceIDString(bridgeSC.otelSpanContext.TraceID)) hhcarrier.Set(spanIDHeader, spanIDToString(bridgeSC.otelSpanContext.SpanID)) - hhcarrier.Set(traceOptionsHeader, traceOptionsToString(bridgeSC.otelSpanContext.TraceOptions)) + hhcarrier.Set(traceFlagsHeader, traceFlagsToString(bridgeSC.otelSpanContext.TraceFlags)) bridgeSC.ForeachBaggageItem(func(k, v string) bool { // we assume that keys are already canonicalized hhcarrier.Set(baggageHeaderPrefix+k, v) @@ -535,9 +535,9 @@ func spanIDToString(spanID uint64) string { return fmt.Sprintf("%.16x", spanID) } -func traceOptionsToString(opts byte) string { +func traceFlagsToString(opts byte) string { var parts []string - if opts&otelcore.TraceOptionSampled == otelcore.TraceOptionSampled { + if opts&otelcore.TraceFlagsSampled == otelcore.TraceFlagsSampled { parts = append(parts, "sampled") } return strings.Join(parts, ",") @@ -571,8 +571,8 @@ func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.Span return err } bridgeSC.otelSpanContext.SpanID = spanID - case traceOptionsHeader: - bridgeSC.otelSpanContext.TraceOptions = stringToTraceOptions(v) + case traceFlagsHeader: + bridgeSC.otelSpanContext.TraceFlags = stringToTraceFlags(v) default: if strings.HasPrefix(ck, baggageHeaderPrefix) { bk := strings.TrimPrefix(ck, baggageHeaderPrefix) @@ -614,12 +614,12 @@ func spanIDFromString(s string) (uint64, error) { return strconv.ParseUint(s, 16, 64) } -func stringToTraceOptions(s string) byte { +func stringToTraceFlags(s string) byte { var opts byte for _, part := range strings.Split(s, ",") { switch part { case "sampled": - opts |= otelcore.TraceOptionSampled + opts |= otelcore.TraceFlagsSampled } } return opts diff --git a/experimental/bridge/opentracing/internal/mock.go b/experimental/bridge/opentracing/internal/mock.go index a89b9da11ee1..959638e9e888 100644 --- a/experimental/bridge/opentracing/internal/mock.go +++ b/experimental/bridge/opentracing/internal/mock.go @@ -98,9 +98,9 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S startTime = time.Now() } spanContext := otelcore.SpanContext{ - TraceID: t.getTraceID(ctx, &spanOpts), - SpanID: t.getSpanID(), - TraceOptions: 0, + TraceID: t.getTraceID(ctx, &spanOpts), + SpanID: t.getSpanID(), + TraceFlags: 0, } span := &MockSpan{ mockTracer: t, diff --git a/exporter/trace/jaeger/jaeger.go b/exporter/trace/jaeger/jaeger.go index 4ddeb3bd7155..185144f55cd7 100644 --- a/exporter/trace/jaeger/jaeger.go +++ b/exporter/trace/jaeger/jaeger.go @@ -217,7 +217,7 @@ func spanDataToThrift(data *trace.SpanData) *gen.Span { SpanId: int64(data.SpanContext.SpanID), ParentSpanId: int64(data.ParentSpanID), OperationName: data.Name, // TODO: if span kind is added then add prefix "Sent"/"Recv" - Flags: int32(data.SpanContext.TraceOptions), + Flags: int32(data.SpanContext.TraceFlags), StartTime: data.StartTime.UnixNano() / 1000, Duration: data.EndTime.Sub(data.StartTime).Nanoseconds() / 1000, Tags: tags, diff --git a/internal/trace/mock_tracer.go b/internal/trace/mock_tracer.go index 101748bd2a01..4e0ebe9b6510 100644 --- a/internal/trace/mock_tracer.go +++ b/internal/trace/mock_tracer.go @@ -76,7 +76,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Span }, } if mt.Sampled { - sc.TraceOptions = core.TraceOptionSampled + sc.TraceFlags = core.TraceFlagsSampled } } else { sc = opts.Reference.SpanContext diff --git a/propagation/http_trace_context_propagator.go b/propagation/http_trace_context_propagator.go index 7ce6f614aeb0..3483c2db6f63 100644 --- a/propagation/http_trace_context_propagator.go +++ b/propagation/http_trace_context_propagator.go @@ -47,7 +47,7 @@ func (hp httpTraceContextPropagator) Inject(ctx context.Context, supplier apipro sc.TraceID.High, sc.TraceID.Low, sc.SpanID, - sc.TraceOptions&core.TraceOptionSampled) + sc.TraceFlags&core.TraceFlagsSampled) supplier.Set(traceparentHeader, h) } } @@ -118,7 +118,7 @@ func (hp httpTraceContextPropagator) Extract(ctx context.Context, supplier apipr if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) { return core.EmptySpanContext() } - sc.TraceOptions = opts[0] &^ core.TraceOptionUnused + sc.TraceFlags = opts[0] &^ core.TraceFlagsUnused if !sc.IsValid() { return core.EmptySpanContext() diff --git a/propagation/http_trace_context_propagator_test.go b/propagation/http_trace_context_propagator_test.go index 65be3b95b334..8bda23d5c7f3 100644 --- a/propagation/http_trace_context_propagator_test.go +++ b/propagation/http_trace_context_propagator_test.go @@ -53,27 +53,27 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { name: "valid header and sampled", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, { name: "future version", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, { name: "future options with sampled bit set", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, { @@ -88,27 +88,27 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { name: "future additional data", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-XYZxsf09", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, { name: "valid header ending in dash", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, { name: "future valid header ending in dash", header: "01-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-", wantSc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, }, } @@ -230,9 +230,9 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { { name: "valid spancontext, sampled", sc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: core.TraceOptionSampled, + TraceID: traceID, + SpanID: spanID, + TraceFlags: core.TraceFlagsSampled, }, wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01", }, @@ -245,11 +245,11 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-00", }, { - name: "valid spancontext, with unsupported bit set in traceoption", + name: "valid spancontext, with unsupported bit set in traceflags", sc: core.SpanContext{ - TraceID: traceID, - SpanID: spanID, - TraceOptions: 0xff, + TraceID: traceID, + SpanID: spanID, + TraceFlags: 0xff, }, wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-01", }, diff --git a/sdk/trace/simple_span_processor_test.go b/sdk/trace/simple_span_processor_test.go index 94a160524638..88ff1b48038b 100644 --- a/sdk/trace/simple_span_processor_test.go +++ b/sdk/trace/simple_span_processor_test.go @@ -62,9 +62,9 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) { tid := core.TraceID{High: 0x0102030405060708, Low: 0x0102040810203040} sid := uint64(0x0102040810203040) sc := core.SpanContext{ - TraceID: tid, - SpanID: sid, - TraceOptions: 0x1, + TraceID: tid, + SpanID: sid, + TraceFlags: 0x1, } _, span := apitrace.GlobalTracer().Start(context.Background(), "OnEnd", apitrace.ChildOf(sc)) span.Finish() diff --git a/sdk/trace/span.go b/sdk/trace/span.go index f0347f9481e9..5a43d94a04e4 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -373,7 +373,7 @@ func makeSamplingDecision(data samplingData) { if data.noParent || data.remoteParent { // If this span is the child of a local span and no // Sampler is set in the options, keep the parent's - // TraceOptions. + // TraceFlags. // // Otherwise, consult the Sampler in the options if it // is non-nil, otherwise the default sampler. @@ -389,9 +389,9 @@ func makeSamplingDecision(data samplingData) { Name: data.name, HasRemoteParent: data.remoteParent}).Sample if sampled { - spanContext.TraceOptions |= core.TraceOptionSampled + spanContext.TraceFlags |= core.TraceFlagsSampled } else { - spanContext.TraceOptions &^= core.TraceOptionSampled + spanContext.TraceFlags &^= core.TraceFlagsSampled } } } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 1268878f9342..ef97eb96ec45 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -134,9 +134,9 @@ func TestRecordingIsOff(t *testing.T) { func TestStartSpanWithChildOf(t *testing.T) { sc1 := core.SpanContext{ - TraceID: tid, - SpanID: sid, - TraceOptions: 0x0, + TraceID: tid, + SpanID: sid, + TraceFlags: 0x0, } _, s1 := apitrace.GlobalTracer().Start(context.Background(), "span1-unsampled-parent1", apitrace.ChildOf(sc1)) if err := checkChild(sc1, s1); err != nil { @@ -149,9 +149,9 @@ func TestStartSpanWithChildOf(t *testing.T) { } sc2 := core.SpanContext{ - TraceID: tid, - SpanID: sid, - TraceOptions: 0x1, + TraceID: tid, + SpanID: sid, + TraceFlags: 0x1, //Tracestate: testTracestate, } _, s3 := apitrace.GlobalTracer().Start(context.Background(), "span3-sampled-parent2", apitrace.ChildOf(sc2)) @@ -183,8 +183,8 @@ func TestSetSpanAttributes(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -212,8 +212,8 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -252,8 +252,8 @@ func TestEvents(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -299,8 +299,8 @@ func TestEventsOverLimit(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -336,8 +336,8 @@ func TestAddLinks(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -373,8 +373,8 @@ func TestLinks(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -411,8 +411,8 @@ func TestLinksOverLimit(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -432,9 +432,9 @@ func TestSetSpanName(t *testing.T) { want := "SpanName-1" _, span := apitrace.GlobalTracer().Start(context.Background(), want, apitrace.ChildOf(core.SpanContext{ - TraceID: tid, - SpanID: sid, - TraceOptions: 1, + TraceID: tid, + SpanID: sid, + TraceFlags: 1, }), ) got, err := endSpan(span) @@ -457,8 +457,8 @@ func TestSetSpanStatus(t *testing.T) { want := &SpanData{ SpanContext: core.SpanContext{ - TraceID: tid, - TraceOptions: 0x1, + TraceID: tid, + TraceFlags: 0x1, }, ParentSpanID: sid, Name: "span0", @@ -484,9 +484,9 @@ func TestUnregisterExporter(t *testing.T) { func remoteSpanContext() core.SpanContext { return core.SpanContext{ - TraceID: tid, - SpanID: sid, - TraceOptions: 1, + TraceID: tid, + SpanID: sid, + TraceFlags: 1, } } @@ -503,7 +503,7 @@ func checkChild(p core.SpanContext, apiSpan apitrace.Span) error { if childID, parentID := s.spanContext.SpanIDString(), p.SpanIDString(); childID == parentID { return fmt.Errorf("got child span ID %s, parent span ID %s; want unequal IDs", childID, parentID) } - if got, want := s.spanContext.TraceOptions, p.TraceOptions; got != want { + if got, want := s.spanContext.TraceFlags, p.TraceFlags; got != want { return fmt.Errorf("got child trace options %d, want %d", got, want) } // TODO [rgheita] : Fix tracestate test @@ -521,7 +521,7 @@ func startSpan() apitrace.Span { // startNamed Span is a test utility func that starts a span with a // passed name and with ChildOf option. remote span context contains -// traceoption with sampled bit set. This allows the span to be +// TraceFlags with sampled bit set. This allows the span to be // automatically sampled. func startNamedSpan(name string) apitrace.Span { _, span := apitrace.GlobalTracer().Start( @@ -685,9 +685,9 @@ func TestExecutionTracerTaskEnd(t *testing.T) { "foo", apitrace.ChildOf( core.SpanContext{ - TraceID: core.TraceID{High: 0x0102030405060708, Low: 0x090a0b0c0d0e0f}, - SpanID: uint64(0x0001020304050607), - TraceOptions: 0, + TraceID: core.TraceID{High: 0x0102030405060708, Low: 0x090a0b0c0d0e0f}, + SpanID: uint64(0x0001020304050607), + TraceFlags: 0, }, ), )