Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wildefires authored Aug 25, 2022
1 parent 1d2a936 commit 97d898c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ func TestStartSpanWithParent(t *testing.T) {
}
}

// Test we get a successful span as a new root if a nil context is sent in, as opposed to a panic.
// See https://github.com/open-telemetry/opentelemetry-go/issues/3109
func TestStartSpanWithNilContext(t *testing.T) {
alwaysSampleTp := NewTracerProvider()
sampledTr := alwaysSampleTp.Tracer("AlwaysSampled")

defer func() {
if r := recover(); r != nil {
t.Error("unexpected panic creating span with nil context")
}
}()

_, _ := sampledTr.Start(nil, "should-not-panic")
}

func TestStartSpanNewRootNotSampled(t *testing.T) {
alwaysSampleTp := NewTracerProvider()
sampledTr := alwaysSampleTp.Tracer("AlwaysSampled")
Expand All @@ -385,6 +400,9 @@ func TestStartSpanNewRootNotSampled(t *testing.T) {
if s3.SpanContext().IsSampled() {
t.Error(fmt.Errorf("got child span is sampled, want child span WithNewRoot() and with sampler: ParentBased(NeverSample()) to not be sampled"))
}

// Test we get a successful span as a new root if a nil context is sent in
_, s4 := neverSampledTr.Start(nil, "span3-new-root", trace.WithNewRoot())
}

func TestSetSpanAttributesOnStart(t *testing.T) {
Expand Down

0 comments on commit 97d898c

Please sign in to comment.