Closed jcchavezs closed 6 years ago
@yurishkuro @ellisv I fixed your comments.
Sorry for commenting so late. I actually proposed the previous API, because i feel returning the scope makes for a bad API. You always grab the span from it to call additional stuff and its a constant law of demeter violation with complicated code.
PHP is single threaded, request based shared nothing. This is different to all other OT languages so far. So i felt it warranted a different API. In addition PHP doesn't have a with keyword like python/java, making the scope so weird, and $scope->close()
is not called automatically.
The default, 90% use case for clients of this library would be the API:
$span = $tracer->startActiveSpan(...);
$span->annotate(...);
//..
$span->annotate(...);
$span->finish($closeOnFinish = true);
now its going to be:
$scope = $tracer->startActiveSpan(...);
$scope->getSpan()->annotate(...);
//..
$scope->getSpan()->annotate(...);
$scope->close($finishOnClose = true);
In previous case having a scope was unecessary at all in my opinion as it was never exposed to the user and may confuse implementors. That is why I opened #55. Instead we could have removed scope concept at all and left Tracer::getActiveSpan()
for implementors to implement in which ever way they want. Or something like
interface SpanManager
{
public function activate(Span $span): void;
public function getActive(): Span;
}
Or put activateSpan()
on Tracer itself.
So in my opinion we can turn two ways:
So I did this implementation three times under three different vendors (mock tracer, datadog and zipkin) I can share my experiences with this:
Span
and Scope
(both being aware of each other).In the other hand, I agree with most of @beberlei's points as returning a Scope
has some inconveniences.
At some point I came up with this approach of having a ScopedSpan
which would be wrapping both a Scope
and Span
and implement both interfaces. That approach felt quite good until you did ScopeManager::activate
which forced you to create a new object:
$scopedSpan = $tracer->getScopeManager()->activate($span);
$scopedSpan->tag(....)
So I backed off. To be honest this is not an inconvenience because ScopeSpan
would carry the existing span + when doing activating you always need to keep track of the scope if you want to avoid the circular dependency.
I would go for the ScopedSpan
, feels more natural for me.
Thoughts @beberlei @yurishkuro @ellisv
I just opened this issue as it was on my mind recently. If it's decided in favor of ScopeContext
then the notion of the Scope
will probably need to be preserved.
Read #61 for more context
Short description of what this PR does:
Tracer::startActiveSpan
signature to return a scope.ScopeManager
to not to be aware of spansThis is a breaking change but since we are still in beta, it is OK.
Checklist
Fixes #61
Ping @beberlei @yurishkuro @ellisv @tedsuo