-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement SpanProcessor::onEnding #1483
base: 2.x
Are you sure you want to change the base?
Conversation
added to spec 1.36.0
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #1483 +/- ##
============================================
- Coverage 72.37% 72.28% -0.09%
- Complexity 2733 2737 +4
============================================
Files 402 402
Lines 8169 8177 +8
============================================
- Hits 5912 5911 -1
- Misses 2257 2266 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
$this->hasEnded = true; | ||
$this->spanProcessor->onEnding($this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Span object MUST still be mutable while
OnEnding
is called.
The SDK MUST guarantee that the span can no longer be modified by any other thread before invoking OnEnding of the first SpanProcessor. From that point on, modifications are only allowed synchronously from within the invoked OnEnding callbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part are you querying? $this
is a Span implementing ReadWriteSpanInterface
so is still mutable (and there's a test to show this working). I don't think we need to worry about other threads, and I don't see any other opportunity for modifying the span...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this is a Span implementing ReadWriteSpanInterface so is still mutable
Setting $this->hasEnded = true
prevents all further writes to the span (besides ::setAttributes()
, which is a bug); currently ::onEnding()
cannot modify the span, the following example fails:
$tracerProvider = (new TracerProviderBuilder())
->addSpanProcessor(new class implements SpanProcessorInterface {
public function onEnding(ReadWriteSpanInterface $span): void {
$span->updateName('updated');
assert($span->getName() === 'updated');
}
public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext): void {}
public function onEnd(ReadableSpanInterface $span): void {}
public function forceFlush(?CancellationInterface $cancellation = null): bool { return true; }
public function shutdown(?CancellationInterface $cancellation = null): bool { return true; }
})
->build();
$span = $tracerProvider->getTracer('test')->spanBuilder('span')->startSpan();
$span->end();
I don't think we need to worry about other threads, and I don't see any other opportunity for modifying the span...
Most mentions of "other threads" also apply to fibers/coroutines, for example the following shouldn't throw an assertion error after fixing the issue above:
$tracerProvider = (new TracerProviderBuilder())
->addSpanProcessor(new class implements SpanProcessorInterface {
public function onEnding(ReadWriteSpanInterface $span): void {
$spanName = $span->getName();
delay(0);
assert($span->getName() === $spanName);
}
public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext): void {}
public function onEnd(ReadableSpanInterface $span): void {}
public function forceFlush(?CancellationInterface $cancellation = null): bool { return true; }
public function shutdown(?CancellationInterface $cancellation = null): bool { return true; }
})
->build();
$span = $tracerProvider->getTracer('test')->spanBuilder('span')->startSpan();
async($span->updateName(...), 'should-not-update');
$span->end();
One solution would be to pass a new span object to ::onEnding()
while still hasEnded=true
ending the original span.
A basic implementation (which will create unnecessary array copies on events/links modification that could be avoided by storing the state in a separate object):
public function end(?int $endEpochNanos = null): void
{
if ($this->endEpochNanos) { // should be nullable and check for !== null instead
return;
}
$this->endEpochNanos = $endEpochNanos ?? Clock::getDefault()->now();
$span = clone $this;
$this->hasEnded = true;
$this->spanProcessor->onEnding($span);
$span->hasEnded = true;
$span->checkForDroppedElements();
$this->spanProcessor->onEnd($span);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. I am confusing this PR with #1482 which is similar but for logs. Back to draft while I work on this more.
added to spec 1.36.0