Skip to content

Commit 621d208

Browse files
committed
Abstract active span management
1 parent bf1873e commit 621d208

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

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+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
namespace Jaeger\Span;
55

6-
use Jaeger\Span\Context\ContextAwareInterface;
76
use Jaeger\Span\Context\SpanContext;
87
use Jaeger\Tracer\InjectableInterface;
98
use Jaeger\Tracer\ResettableInterface;
109

11-
class SpanManager implements InjectableInterface, ContextAwareInterface, ResettableInterface
10+
class StackSpanManager implements SpanManagerInterface
1211
{
1312
private $stack;
1413

@@ -64,12 +63,12 @@ public function getSpan(): ?SpanInterface
6463
return $this->stack->count() ? $this->stack->top() : null;
6564
}
6665

67-
public function push(SpanInterface $span): void
66+
public function new(SpanInterface $span): void
6867
{
6968
$this->stack->push($span);
7069
}
7170

72-
public function pop(): ?SpanInterface
71+
public function finish(SpanInterface $span): ?SpanInterface
7372
{
7473
return $this->stack->count() ? $this->stack->pop() : null;
7574
}

src/Tracer/Tracer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Jaeger\Span\Context\SpanContext;
99
use Jaeger\Span\Factory\SpanFactoryInterface;
1010
use Jaeger\Span\SpanInterface;
11-
use Jaeger\Span\SpanManager;
11+
use Jaeger\Span\SpanManagerInterface;
1212

1313
class Tracer implements
1414
TracerInterface,
@@ -26,7 +26,7 @@ class Tracer implements
2626

2727
private $client;
2828

29-
public function __construct(SpanManager $manager, SpanFactoryInterface $factory, ClientInterface $client)
29+
public function __construct(SpanManagerInterface $manager, SpanFactoryInterface $factory, ClientInterface $client)
3030
{
3131
$this->manager = $manager;
3232
$this->factory = $factory;
@@ -83,7 +83,7 @@ public function getClient(): ClientInterface
8383
public function debug(string $operationName, array $tags = []): SpanInterface
8484
{
8585
$span = $this->factory->parent($this, $operationName, str_shuffle('01234567890abcdef'), $tags);
86-
$this->manager->push($span);
86+
$this->manager->new($span);
8787

8888
return $span;
8989
}
@@ -95,7 +95,7 @@ public function start(string $operationName, array $tags = [], SpanContext $user
9595
} else {
9696
$span = $this->factory->child($this, $operationName, $context, $tags);
9797
}
98-
$this->manager->push($span);
98+
$this->manager->new($span);
9999

100100
return $span;
101101
}
@@ -112,7 +112,7 @@ public function finish(SpanInterface $span, int $duration = 0): void
112112

113113
return;
114114
}
115-
$this->manager->pop();
115+
$this->manager->finish($span);
116116
if (false === $span->isSampled()) {
117117
return;
118118
}

0 commit comments

Comments
 (0)