1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00

Refactor current span check (#419)

- Simplify conditionals.
- Remove unnecessary nil check.

Go type assertions return a bool value indicating whether the
assertion succeeded. When the assertion is performed on a nil value,
the bool becomes false without a panic, therefore the nil check is
unnecessary.
This commit is contained in:
Johannes Liebermann
2020-01-06 20:24:51 +01:00
committed by Liz Fong-Jones
parent 4a8667986b
commit d4557c3dfa

View File

@@ -47,13 +47,9 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.StartOpt
// Future relationship types may have different behavior, // Future relationship types may have different behavior,
// e.g., adding a `Link` instead of setting the `parent` // e.g., adding a `Link` instead of setting the `parent`
} }
} else { } else if p, ok := apitrace.SpanFromContext(ctx).(*span); ok {
if p := apitrace.SpanFromContext(ctx); p != nil { p.addChild()
if sdkSpan, ok := p.(*span); ok { parent = p.spanContext
sdkSpan.addChild()
parent = sdkSpan.spanContext
}
}
} }
spanName := tr.spanNameWithPrefix(name) spanName := tr.spanNameWithPrefix(name)