Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Allocate SpanContext to deal with lifetime issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Sigelman committed Jul 6, 2016
1 parent 9ad37cc commit ffaf3c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type RawSpan struct {
// The RawSpan embeds its SpanContext. Those recording the RawSpan
// should also record the contents of its SpanContext.
SpanContext
*SpanContext

// The SpanID of this SpanContext's first intra-trace reference (i.e.,
// "parent"), or 0 if there is no parent.
Expand Down
2 changes: 1 addition & 1 deletion recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestInMemoryRecorderSpans(t *testing.T) {
recorder := NewInMemoryRecorder()
var apiRecorder SpanRecorder = recorder
span := RawSpan{
SpanContext: SpanContext{},
SpanContext: &SpanContext{},
Operation: "test-span",
Start: time.Now(),
Duration: -1,
Expand Down
6 changes: 4 additions & 2 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (s *spanImpl) reset() {
// a buffer pool when GC considers them unreachable, which should ease
// some of the load. Hard to say how quickly that would be in practice
// though.
s.raw = RawSpan{}
s.raw = RawSpan{
SpanContext: &SpanContext{},
}
}

func (s *spanImpl) SetOperationName(operationName string) opentracing.Span {
Expand Down Expand Up @@ -153,7 +155,7 @@ func (s *spanImpl) Tracer() opentracing.Tracer {
}

func (s *spanImpl) Context() opentracing.SpanContext {
return &s.raw.SpanContext
return s.raw.SpanContext
}

func (s *spanImpl) Operation() string {
Expand Down
6 changes: 5 additions & 1 deletion tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func (t *tracerImpl) getSpan() *spanImpl {
sp.reset()
return sp
}
return &spanImpl{}
return &spanImpl{
raw: RawSpan{
SpanContext: &SpanContext{},
},
}
}

func (t *tracerImpl) StartSpanWithOptions(
Expand Down

0 comments on commit ffaf3c8

Please sign in to comment.