You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +02:00
Handle nil testSpanProcessor (#2400)
Remove nil check on return from NewTestSpanProcessor as it can never be nil, addressing #2396. Also, add nil checks for testSpanProcessor methods to prevent panics.
This commit is contained in:
@@ -31,6 +31,9 @@ type testSpanProcessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) {
|
func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) {
|
||||||
|
if t == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
psc := trace.SpanContextFromContext(parent)
|
psc := trace.SpanContextFromContext(parent)
|
||||||
kv := []attribute.KeyValue{
|
kv := []attribute.KeyValue{
|
||||||
{
|
{
|
||||||
@@ -55,15 +58,24 @@ func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWrite
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan) {
|
func (t *testSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan) {
|
||||||
|
if t == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
t.spansEnded = append(t.spansEnded, s)
|
t.spansEnded = append(t.spansEnded, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSpanProcessor) Shutdown(_ context.Context) error {
|
func (t *testSpanProcessor) Shutdown(_ context.Context) error {
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
t.shutdownCount++
|
t.shutdownCount++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSpanProcessor) ForceFlush(context.Context) error {
|
func (t *testSpanProcessor) ForceFlush(context.Context) error {
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +217,6 @@ func TestSpanProcessorShutdown(t *testing.T) {
|
|||||||
name := "Increment shutdown counter of a span processor"
|
name := "Increment shutdown counter of a span processor"
|
||||||
tp := basicTracerProvider(t)
|
tp := basicTracerProvider(t)
|
||||||
sp := NewTestSpanProcessor("sp")
|
sp := NewTestSpanProcessor("sp")
|
||||||
if sp == nil {
|
|
||||||
t.Fatalf("Error creating new instance of TestSpanProcessor\n")
|
|
||||||
}
|
|
||||||
tp.RegisterSpanProcessor(sp)
|
tp.RegisterSpanProcessor(sp)
|
||||||
|
|
||||||
wantCount := 1
|
wantCount := 1
|
||||||
@@ -226,9 +235,6 @@ func TestMultipleUnregisterSpanProcessorCalls(t *testing.T) {
|
|||||||
name := "Increment shutdown counter after first UnregisterSpanProcessor call"
|
name := "Increment shutdown counter after first UnregisterSpanProcessor call"
|
||||||
tp := basicTracerProvider(t)
|
tp := basicTracerProvider(t)
|
||||||
sp := NewTestSpanProcessor("sp")
|
sp := NewTestSpanProcessor("sp")
|
||||||
if sp == nil {
|
|
||||||
t.Fatalf("Error creating new instance of TestSpanProcessor\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
wantCount := 1
|
wantCount := 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user