Skip to content

Commit f7acd55

Browse files
committed
Send spans in batches
1 parent b0bd5f4 commit f7acd55

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/Client/ThriftClient.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
namespace Jaeger\Client;
55

6+
use Jaeger\Process\CliProcess;
67
use Jaeger\Process\FpmProcess;
78
use Jaeger\Process\InternalServerProcess;
8-
use Jaeger\Thrift\Agent\AgentIf as AgentInterface;
9-
use Jaeger\Process\CliProcess;
109
use Jaeger\Span\Batch\SpanBatch;
1110
use Jaeger\Span\SpanInterface;
11+
use Jaeger\Thrift\Agent\AgentIf as AgentInterface;
1212

1313
class ThriftClient implements ClientInterface
1414
{
15+
const MAX_BATCH_SIZE = 100;
16+
1517
private $serviceName;
1618

1719
private $agent;
@@ -28,10 +30,10 @@ public function add(SpanInterface $span): ClientInterface
2830
{
2931
$this->spans[] = $span;
3032

31-
return $this;
33+
return $this->flush();
3234
}
3335

34-
public function getSpans() : array
36+
public function getSpans(): array
3537
{
3638
return $this->spans;
3739
}
@@ -49,7 +51,9 @@ public function flush(): ClientInterface
4951
$process = new FpmProcess($this->serviceName);
5052
break;
5153
}
52-
$this->agent->emitBatch(new SpanBatch($process, $this->spans));
54+
foreach (array_chunk($this->spans, self::MAX_BATCH_SIZE) as $batch) {
55+
$this->agent->emitBatch(new SpanBatch($process, $batch));
56+
}
5357
$this->spans = [];
5458

5559
return $this;

0 commit comments

Comments
 (0)