Skip to content

SpanProcessor incorrect calls to SpanExporter::forceFlush()#787

Closed
amber0612 wants to merge 29 commits into
open-telemetry:mainfrom
amber0612:main
Closed

SpanProcessor incorrect calls to SpanExporter::forceFlush()#787
amber0612 wants to merge 29 commits into
open-telemetry:mainfrom
amber0612:main

Conversation

@amber0612

Copy link
Copy Markdown
Contributor

@amber0612
amber0612 marked this pull request as draft August 1, 2022 12:11
@codecov

codecov Bot commented Aug 1, 2022

Copy link
Copy Markdown

Codecov Report

Merging #787 (fcc9e73) into main (0f30849) will decrease coverage by 0.64%.
The diff coverage is 100.00%.

❗ Current head fcc9e73 differs from pull request most recent head f2dd0c2. Consider uploading reports for the commit f2dd0c2 to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #787      +/-   ##
============================================
- Coverage     81.03%   80.38%   -0.65%     
+ Complexity     1825     1768      -57     
============================================
  Files           225      222       -3     
  Lines          4687     4523     -164     
============================================
- Hits           3798     3636     -162     
+ Misses          889      887       -2     
Flag Coverage Δ
7.4 80.38% <100.00%> (-0.65%) ⬇️
8.0 80.42% <100.00%> (-0.65%) ⬇️
8.1 80.42% <100.00%> (-0.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php 100.00% <100.00%> (ø)
src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php 100.00% <0.00%> (ø)
...c/API/Trace/Propagation/TraceContextPropagator.php 100.00% <0.00%> (ø)
src/Extension/Propagator/B3/B3Propagator.php
.../Extension/Propagator/B3/B3DebugFlagContextKey.php
src/Extension/Propagator/B3/B3MultiPropagator.php
src/Extension/Propagator/B3/B3SinglePropagator.php
src/API/Trace/Propagation/B3MultiPropagator.php 100.00% <0.00%> (ø)
src/SDK/Trace/SpanProcessorFactory.php 100.00% <0.00%> (+7.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f30849...f2dd0c2. Read the comment docs.

@amber0612
amber0612 marked this pull request as ready for review August 1, 2022 12:15

@Nevay Nevay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Please rebase your branch to remove the unrelated commits.)

if ($this->bufferReachedExportLimit() || $this->enoughTimeHasPassed()) {
$this->forceFlush();
$this->exporter->export($this->queue);
$this->queue = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queue has to be cleared before calling ::export(), otherwise we might export the batch multiple times if the exporter suspends execution. We will need a $queueSize property to handle $maxQueueSize after this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a try block inside which export would take place. If somehow exporter suspends execution and fails , finally block would clear the queue. Will this help resolving the issue??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant suspend as in Fiber::suspend(). Something like the following would resolve it:

$batch = $this->queue;
$this->queue = [];
$this->stopwatch->reset();

try {
    $this->exporter->export($batch);
} finally {
    $this->queueSize -= count($batch);
}

The spec mentions that "Export() will never be called concurrently for the same exporter instance", but I don't see a way for us to follow the spec unless we queue execution in a single fiber. This would mean even more blocking for the Span::end() call that triggered the initial export (worst case blocking forever) ("Expect this operation to be called in the "hot path" of production applications. It needs to be designed to complete fast, if not immediately.").

@amber0612
amber0612 marked this pull request as ready for review August 16, 2022 06:03
@amber0612 amber0612 closed this Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants