opentracing / opentracing-php

OpenTracing API for PHP
Apache License 2.0
509 stars 56 forks source link

Should we remove SpanContextNotFound? #49

Closed jcchavezs closed 6 years ago

jcchavezs commented 6 years ago

Problem

After doing a couple implementation of OpenTracing, I did not have the necessity of using the SpanContextNotFound exception. More over, the flow when using this exception is cumbersome:

try {
    $context = $tracer->extract(...);
} catch(Exception $e) {
    $context = SpanContext::createAsRoot();
}

whereas returning a null would be:

$context = $tracer->extract(...);

if ($context === null) {
    ... // build root context
}

Finally, the SpanContextNotFound does not add additional value to the failure, so returning a null is good enough.

Proposal

Get rid of the exception and return null in such cases.

Ping @tedsuo @yurishkuro @beberlei @felixfbecker @lvht

yurishkuro commented 6 years ago

+1, especially if childOf() can accept null, then you don't even need the null check.