-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
refs jaegertracing#397
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import ( | |
"github.com/opentracing/opentracing-go/log" | ||
) | ||
|
||
const SelfRef opentracing.SpanReferenceType = 99 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yurishkuro
|
||
|
||
// Span implements opentracing.Span | ||
type Span struct { | ||
// referenceCounter used to increase the lifetime of | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,7 +221,8 @@ func (t *Tracer) startSpanWithOptions( | |
|
||
var references []Reference | ||
var parent SpanContext | ||
var hasParent bool // need this because `parent` is a value, not reference | ||
var hasParent bool // need this because `parent` is a value, not reference | ||
var selfReference *SpanContext // self references skip the ID generation | ||
for _, ref := range options.References { | ||
ctx, ok := ref.ReferencedContext.(SpanContext) | ||
if !ok { | ||
|
@@ -234,6 +235,13 @@ func (t *Tracer) startSpanWithOptions( | |
continue | ||
} | ||
references = append(references, Reference{Type: ref.Type, Context: ctx}) | ||
|
||
// if | ||
if ref.Type == SelfRef { | ||
selfReference = &ctx | ||
This comment has been minimized.
Sorry, something went wrong.
yurishkuro
|
||
break | ||
This comment has been minimized.
Sorry, something went wrong.
dm03514
Author
Owner
|
||
} | ||
|
||
if !hasParent { | ||
parent = ctx | ||
hasParent = ref.Type == opentracing.ChildOfRef | ||
|
@@ -253,42 +261,46 @@ func (t *Tracer) startSpanWithOptions( | |
var samplerTags []Tag | ||
var ctx SpanContext | ||
newTrace := false | ||
if !hasParent || !parent.IsValid() { | ||
newTrace = true | ||
ctx.traceID.Low = t.randomID() | ||
if t.options.gen128Bit { | ||
ctx.traceID.High = t.options.highTraceIDGenerator() | ||
} | ||
ctx.spanID = SpanID(ctx.traceID.Low) | ||
ctx.parentID = 0 | ||
ctx.flags = byte(0) | ||
if hasParent && parent.isDebugIDContainerOnly() && t.isDebugAllowed(operationName) { | ||
ctx.flags |= (flagSampled | flagDebug) | ||
samplerTags = []Tag{{key: JaegerDebugHeader, value: parent.debugID}} | ||
} else if sampled, tags := t.sampler.IsSampled(ctx.traceID, operationName); sampled { | ||
ctx.flags |= flagSampled | ||
samplerTags = tags | ||
} | ||
} else { | ||
ctx.traceID = parent.traceID | ||
if rpcServer && t.options.zipkinSharedRPCSpan { | ||
// Support Zipkin's one-span-per-RPC model | ||
ctx.spanID = parent.spanID | ||
ctx.parentID = parent.parentID | ||
if selfReference == nil { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yurishkuro
|
||
if !hasParent || !parent.IsValid() { | ||
newTrace = true | ||
ctx.traceID.Low = t.randomID() | ||
if t.options.gen128Bit { | ||
ctx.traceID.High = t.options.highTraceIDGenerator() | ||
} | ||
ctx.spanID = SpanID(ctx.traceID.Low) | ||
ctx.parentID = 0 | ||
ctx.flags = byte(0) | ||
if hasParent && parent.isDebugIDContainerOnly() && t.isDebugAllowed(operationName) { | ||
ctx.flags |= (flagSampled | flagDebug) | ||
samplerTags = []Tag{{key: JaegerDebugHeader, value: parent.debugID}} | ||
} else if sampled, tags := t.sampler.IsSampled(ctx.traceID, operationName); sampled { | ||
ctx.flags |= flagSampled | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yurishkuro
|
||
samplerTags = tags | ||
} | ||
} else { | ||
ctx.spanID = SpanID(t.randomID()) | ||
ctx.parentID = parent.spanID | ||
ctx.traceID = parent.traceID | ||
if rpcServer && t.options.zipkinSharedRPCSpan { | ||
// Support Zipkin's one-span-per-RPC model | ||
ctx.spanID = parent.spanID | ||
ctx.parentID = parent.parentID | ||
} else { | ||
ctx.spanID = SpanID(t.randomID()) | ||
ctx.parentID = parent.spanID | ||
} | ||
ctx.flags = parent.flags | ||
} | ||
ctx.flags = parent.flags | ||
} | ||
if hasParent { | ||
// copy baggage items | ||
if l := len(parent.baggage); l > 0 { | ||
ctx.baggage = make(map[string]string, len(parent.baggage)) | ||
for k, v := range parent.baggage { | ||
ctx.baggage[k] = v | ||
if hasParent { | ||
// copy baggage items | ||
if l := len(parent.baggage); l > 0 { | ||
ctx.baggage = make(map[string]string, len(parent.baggage)) | ||
for k, v := range parent.baggage { | ||
ctx.baggage[k] = v | ||
} | ||
} | ||
} | ||
} else { | ||
ctx = *selfReference | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
sp := t.newSpan() | ||
|
Where's the best spot for this? What's the best value?