Skip to content

Commit 9fd24ce

Browse files
committed
Merge branch '3.0.x'
2 parents bfebfc7 + dc086aa commit 9fd24ce

File tree

80 files changed

+5977
-4873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+5977
-4873
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
21
# PHP OpenTracing API using Jaeger
32

4-
53
## Installation
64

7-
```
5+
```bash
86
composer require code-tool/jaeger-client-php
97
```
108

119
## Getting Started
1210

13-
It is strictly advised to use any form of DI container (e.g. [Symfony](https://github.com/code-tool/jaeger-client-symfony-bridge)).
14-
```$xslt
11+
It is strictly advised to use any form of DI container (e.g. [Symfony Bundle](https://github.com/code-tool/jaeger-client-symfony-bridge)).
12+
13+
```php
1514
<?php
1615

16+
use Jaeger\Tag\StringTag;
17+
use Jaeger\Tracer\TracerInterface;
18+
19+
/** @var TracerInterface $tracer */
20+
1721
$span = $tracer->start('Parent Operation Name', [new StringTag('test.tag', 'Hello world in parent')]);
1822
$childSpan = $tracer->start('Child Operation Name', [new StringTag('test.tag', 'Hello world in child')]);
1923
$tracer->finish($childSpan);

bin/thrift-gen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

44
cd "$(dirname "$0")/.."
55

6-
git clone https://github.com/uber/jaeger-idl
6+
git clone https://github.com/jaegertracing/jaeger-idl
77
pushd jaeger-idl
88

99
rm -rf ../src/Thrift

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
},
99
"require": {
1010
"php": ">=7.1",
11-
"apache/thrift": "0.11.*",
12-
"psr/log": "^1.0.2"
11+
"ext-sockets": "*",
12+
"apache/thrift": ">=0.11, <0.16"
1313
},
1414
"require-dev": {
1515
"phpunit/phpunit": "@stable"

src/Client/ThriftClient.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212

1313
class ThriftClient implements ClientInterface
1414
{
15-
const MAX_BATCH_SIZE = 100;
15+
public const MAX_BATCH_SIZE = 32;
1616

1717
private $serviceName;
1818

1919
private $agent;
2020

21+
private $batch;
22+
2123
private $spans = [];
2224

23-
public function __construct(string $serviceName, AgentInterface $agent)
25+
public function __construct(string $serviceName, AgentInterface $agent, $batch = self::MAX_BATCH_SIZE)
2426
{
2527
$this->serviceName = $serviceName;
2628
$this->agent = $agent;
29+
$this->batch = (int)$batch;
2730
}
2831

2932
public function add(SpanInterface $span): ClientInterface
@@ -51,7 +54,7 @@ public function flush(): ClientInterface
5154
$process = new FpmProcess($this->serviceName);
5255
break;
5356
}
54-
foreach (array_chunk($this->spans, self::MAX_BATCH_SIZE) as $batch) {
57+
foreach (array_chunk($this->spans, $this->batch) as $batch) {
5558
$this->agent->emitBatch(new SpanBatch($process, $batch));
5659
}
5760
$this->spans = [];

src/Codec/CodecRegistry.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ class CodecRegistry implements \ArrayAccess
77
{
88
private $codecs = [];
99

10+
/**
11+
* @return bool
12+
*/
13+
#[\ReturnTypeWillChange]
1014
public function offsetExists($offset)
1115
{
1216
return array_key_exists($offset, $this->codecs);
1317
}
1418

19+
/**
20+
* @return mixed
21+
*/
22+
#[\ReturnTypeWillChange]
1523
public function offsetGet($offset)
1624
{
1725
if (false === array_key_exists($offset, $this->codecs)) {
@@ -21,13 +29,21 @@ public function offsetGet($offset)
2129
return $this->codecs[$offset];
2230
}
2331

32+
/**
33+
* @return $this
34+
*/
35+
#[\ReturnTypeWillChange]
2436
public function offsetSet($offset, $value)
2537
{
2638
$this->codecs[$offset] = $value;
2739

2840
return $this;
2941
}
3042

43+
/**
44+
* @return $this
45+
*/
46+
#[\ReturnTypeWillChange]
3147
public function offsetUnset($offset)
3248
{
3349
if (false === array_key_exists($offset, $this->codecs)) {

src/Sampler/OperationGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class OperationGenerator implements GeneratorInterface
77
{
88
public function generate(int $traceId, string $operationName): string
99
{
10-
return $operationName;
10+
return 'operation:' . $operationName;
1111
}
1212
}

src/Span/Context/SpanContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function getParentId(): int
4444
return $this->parentId;
4545
}
4646

47+
public function isSampled(): bool
48+
{
49+
return (bool)($this->flags & 0x01);
50+
}
51+
4752
public function isDebug(): bool
4853
{
4954
return (bool)($this->flags & 0x02);
@@ -59,6 +64,10 @@ public function getBaggage(): array
5964
return $this->baggage;
6065
}
6166

67+
/**
68+
* @return \Traversable
69+
*/
70+
#[\ReturnTypeWillChange]
6271
public function getIterator()
6372
{
6473
return new \ArrayIterator($this->baggage);

src/Span/Span.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Jaeger\Tag\OutOfScopeTag;
99
use Jaeger\Thrift\Log;
1010
use Jaeger\Thrift\Tag;
11-
use Jaeger\Tracer\TracerInterface;
11+
use Jaeger\Tracer\FinishableInterface;
1212

1313
class Span extends \Jaeger\Thrift\Span implements SpanInterface
1414
{
@@ -17,7 +17,7 @@ class Span extends \Jaeger\Thrift\Span implements SpanInterface
1717
private $context;
1818

1919
public function __construct(
20-
TracerInterface $tracer,
20+
FinishableInterface $tracer,
2121
SpanContext $context,
2222
string $operationName,
2323
int $startTime,
@@ -33,7 +33,6 @@ public function __construct(
3333
$this->flags = $context->getFlags();
3434
$this->operationName = $operationName;
3535
$this->startTime = $startTime;
36-
3736
$this->tags = $tags;
3837
$this->logs = $logs;
3938
parent::__construct();
@@ -42,14 +41,11 @@ public function __construct(
4241
public function __destruct()
4342
{
4443
if (null !== $this->duration) {
45-
return $this;
44+
return;
4645
}
4746
$this->tags[] = new ErrorTag();
4847
$this->tags[] = new OutOfScopeTag();
49-
5048
$this->tracer->finish($this);
51-
52-
return $this;
5349
}
5450

5551
public function getContext(): ?SpanContext
@@ -59,7 +55,7 @@ public function getContext(): ?SpanContext
5955

6056
public function isSampled(): bool
6157
{
62-
return (bool)($this->flags & 1);
58+
return $this->context->isSampled();
6359
}
6460

6561
public function start(int $startTimeUsec): SpanInterface
@@ -71,10 +67,8 @@ public function start(int $startTimeUsec): SpanInterface
7167

7268
public function finish(int $durationUsec = 0): SpanInterface
7369
{
74-
if (0 === $durationUsec) {
75-
$durationUsec = (int)(microtime(true) * 1000000) - $this->startTime;
76-
}
77-
$this->duration = $durationUsec;
70+
$this->duration = $durationUsec ?: (microtime(true) * 1000000) - $this->startTime;
71+
$this->tracer->finish($this, -1);
7872

7973
return $this;
8074
}

src/Span/SpanAwareInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Jaeger\Span;
5+
6+
interface SpanAwareInterface
7+
{
8+
public function getSpan(): ?SpanInterface;
9+
}

src/Span/SpanManagerInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Jaeger\Span;
5+
6+
use Jaeger\Span\Context\ContextAwareInterface;
7+
use Jaeger\Tracer\InjectableInterface;
8+
use Jaeger\Tracer\ResettableInterface;
9+
10+
interface SpanManagerInterface extends ContextAwareInterface,
11+
InjectableInterface,
12+
ResettableInterface,
13+
SpanAwareInterface
14+
{
15+
public function new(SpanInterface $span);
16+
17+
public function finish(SpanInterface $span): ?SpanInterface;
18+
}

0 commit comments

Comments
 (0)