1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +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,
// e.g., adding a `Link` instead of setting the `parent`
}
} else {
if p := apitrace.SpanFromContext(ctx); p != nil {
if sdkSpan, ok := p.(*span); ok {
sdkSpan.addChild()
parent = sdkSpan.spanContext
}
}
} else if p, ok := apitrace.SpanFromContext(ctx).(*span); ok {
p.addChild()
parent = p.spanContext
}
spanName := tr.spanNameWithPrefix(name)