1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-10 09:50:58 +02:00

oteltest: ensure valid SpanContext created for span started WithNewRoot (#2073)

* oteltest: ensure valid SpanContext created for span started WithNewRoot

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Add CHANGELOG entry

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Anthony Mirabella 2021-07-09 16:01:44 -04:00 committed by GitHub
parent 484258eb36
commit 12f737c7a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 1 deletions

View File

@ -29,6 +29,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

View File

@ -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() {

View File

@ -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()