From ffaf3c8a1fec1be07ea3b8800e5d8bb55e9a7035 Mon Sep 17 00:00:00 2001 From: Ben Sigelman Date: Wed, 6 Jul 2016 11:42:01 -0700 Subject: [PATCH] Allocate SpanContext to deal with lifetime issues --- raw.go | 2 +- recorder_test.go | 2 +- span.go | 6 ++++-- tracer.go | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/raw.go b/raw.go index 5f66015..e32c24f 100644 --- a/raw.go +++ b/raw.go @@ -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. diff --git a/recorder_test.go b/recorder_test.go index f7a8bf2..940aa57 100644 --- a/recorder_test.go +++ b/recorder_test.go @@ -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, diff --git a/span.go b/span.go index 11bf0c0..a4818f8 100644 --- a/span.go +++ b/span.go @@ -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 { @@ -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 { diff --git a/tracer.go b/tracer.go index 78ec6e8..ef20a01 100644 --- a/tracer.go +++ b/tracer.go @@ -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(