Skip to content

Commit

Permalink
[opentracing] back reference from SpanContext to Span
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Palazzetti committed Dec 4, 2017
1 parent fbfde3d commit 4a17da0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion opentracing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type SpanContext struct {
spanID uint64
parentID uint64
sampled bool
span *Span
baggage map[string]string
}

Expand Down Expand Up @@ -34,5 +35,12 @@ func (c SpanContext) WithBaggageItem(key, val string) SpanContext {
newBaggage[key] = val
}
// Use positional parameters so the compiler will help catch new fields.
return SpanContext{c.traceID, c.spanID, c.parentID, c.sampled, newBaggage}
return SpanContext{
traceID: c.traceID,
spanID: c.spanID,
parentID: c.parentID,
sampled: c.sampled,
span: c.span,
baggage: newBaggage,
}
}
18 changes: 15 additions & 3 deletions opentracing/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ func (s *Span) Log(data ot.LogData) {

// NewSpan is the OpenTracing Span constructor
func NewSpan(operationName string) *Span {
return &Span{
Span: &datadog.Span{
Name: operationName,
span := &datadog.Span{
Name: operationName,
}

otSpan := &Span{
Span: span,
context: SpanContext{
traceID: span.TraceID,
spanID: span.SpanID,
parentID: span.ParentID,
sampled: span.Sampled,
},
}

// SpanContext is propagated and used to create children
otSpan.context.span = otSpan
return otSpan
}

0 comments on commit 4a17da0

Please sign in to comment.