Skip to content

Commit

Permalink
change TraceOptions to TraceFlags.
Browse files Browse the repository at this point in the history
  • Loading branch information
rghetia committed Sep 25, 2019
1 parent 7966e63 commit 8d55ed3
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 90 deletions.
18 changes: 9 additions & 9 deletions api/core/span_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -67,5 +67,5 @@ func (sc SpanContext) TraceIDString() string {
}

func (sc SpanContext) IsSampled() bool {
return sc.TraceOptions&traceOptionBitMaskSampled == traceOptionBitMaskSampled
return sc.TraceFlags&traceFlagsBitMaskSampled == traceFlagsBitMaskSampled
}
4 changes: 2 additions & 2 deletions api/core/span_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestSpanContextIsSampled(t *testing.T) {
High: uint64(42),
Low: uint64(42),
},
TraceOptions: core.TraceOptionSampled,
TraceFlags: core.TraceFlagsSampled,
},
want: true,
}, {
Expand All @@ -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,
}, {
Expand Down
16 changes: 8 additions & 8 deletions experimental/bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-")
)

Expand All @@ -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)
Expand All @@ -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, ",")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions experimental/bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/trace/mock_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions propagation/http_trace_context_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()
Expand Down
50 changes: 25 additions & 25 deletions propagation/http_trace_context_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
{
Expand All @@ -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,
},
},
}
Expand Down Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down
6 changes: 3 additions & 3 deletions sdk/trace/simple_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
}
Loading

0 comments on commit 8d55ed3

Please sign in to comment.