1
0
Fork 0

Add Tracing Header Context Name option for Jaeger

This commit is contained in:
Mohamed Abdelkader Hizaoui 2019-02-05 18:20:03 +01:00 committed by Traefiker Bot
parent f0ee2890b2
commit 156f6b8d3c
17 changed files with 327 additions and 49 deletions

View file

@ -50,6 +50,7 @@ type Tracer struct {
gen128Bit bool // whether to generate 128bit trace IDs
zipkinSharedRPCSpan bool
highTraceIDGenerator func() uint64 // custom high trace ID generator
maxTagValueLength int
// more options to come
}
// pool for Span objects
@ -152,6 +153,9 @@ func NewTracer(
t.logger.Error("Overriding high trace ID generator but not generating " +
"128 bit trace IDs, consider enabling the \"Gen128Bit\" option")
}
if t.options.maxTagValueLength == 0 {
t.options.maxTagValueLength = DefaultMaxTagValueLength
}
t.process = Process{
Service: serviceName,
UUID: strconv.FormatUint(t.randomNumber(), 16),
@ -194,6 +198,12 @@ func (t *Tracer) startSpanWithOptions(
options.StartTime = t.timeNow()
}
// Predicate whether the given span context is a valid reference
// which may be used as parent / debug ID / baggage items source
isValidReference := func(ctx SpanContext) bool {
return ctx.IsValid() || ctx.isDebugIDContainerOnly() || len(ctx.baggage) != 0
}
var references []Reference
var parent SpanContext
var hasParent bool // need this because `parent` is a value, not reference
@ -205,7 +215,7 @@ func (t *Tracer) startSpanWithOptions(
reflect.ValueOf(ref.ReferencedContext)))
continue
}
if !(ctx.IsValid() || ctx.isDebugIDContainerOnly() || len(ctx.baggage) != 0) {
if !isValidReference(ctx) {
continue
}
references = append(references, Reference{Type: ref.Type, Context: ctx})
@ -214,7 +224,7 @@ func (t *Tracer) startSpanWithOptions(
hasParent = ref.Type == opentracing.ChildOfRef
}
}
if !hasParent && parent.IsValid() {
if !hasParent && isValidReference(parent) {
// If ChildOfRef wasn't found but a FollowFromRef exists, use the context from
// the FollowFromRef as the parent
hasParent = true