From 3567c302f1601d3c0c4d0dc2f60ed8279d698d4f Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Thu, 8 Jul 2021 13:40:30 -0400 Subject: [PATCH 1/2] oteltest: ensure valid SpanContext created for span started WithNewRoot Signed-off-by: Anthony J Mirabella --- oteltest/tracer.go | 2 +- oteltest/tracer_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/oteltest/tracer.go b/oteltest/tracer.go index 3171462fd63..db119a5eb13 100644 --- a/oteltest/tracer.go +++ b/oteltest/tracer.go @@ -52,7 +52,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanStart } if c.NewRoot() { - span.spanContext = trace.SpanContext{} + span.spanContext = t.provider.config.SpanContextFunc(context.Background()) } else { span.spanContext = t.provider.config.SpanContextFunc(ctx) if current := trace.SpanContextFromContext(ctx); current.IsValid() { diff --git a/oteltest/tracer_test.go b/oteltest/tracer_test.go index ecde7cff72c..69de7472363 100644 --- a/oteltest/tracer_test.go +++ b/oteltest/tracer_test.go @@ -161,6 +161,7 @@ func TestTracer(t *testing.T) { e.Expect(ok).ToBeTrue() childSpanContext := testSpan.SpanContext() + e.Expect(childSpanContext.IsValid()).ToBeTrue() e.Expect(childSpanContext.TraceID()).NotToEqual(napSpanContext.TraceID()) e.Expect(childSpanContext.SpanID()).NotToEqual(napSpanContext.SpanID()) e.Expect(testSpan.ParentSpanID().IsValid()).ToBeFalse() From 3e99cbf87d298b15f8762eaecb5cca7d6748a5dd Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Thu, 8 Jul 2021 14:06:13 -0400 Subject: [PATCH 2/2] Add CHANGELOG entry Signed-off-by: Anthony J Mirabella --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a508a7a17..0ee418deac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - When using WithNewRoot, don't use the parent context for making sampling decisions. (#2032) +- `oteltest.Tracer` now creates a valid `SpanContext` when using `WithNewRoot`. (#2073) ### Security