| Total Complexity | 10 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 7 | class Tracer |
||
| 8 | { |
||
| 9 | private $active; |
||
| 10 | private $spans = []; |
||
| 11 | private $tail = []; |
||
| 12 | |||
| 13 | 12 | public function __construct(SpanContext $context = null) |
|
| 14 | { |
||
| 15 | 12 | $context = $context ?: SpanContext::generate(); |
|
| 16 | 12 | $this->active = $this->generateSpanInstance('tracer', $context); |
|
| 17 | 12 | } |
|
| 18 | |||
| 19 | 12 | public function getActiveSpan(): Span |
|
| 25 | } |
||
| 26 | |||
| 27 | 9 | public function setActive(Span $span): Span |
|
| 28 | { |
||
| 29 | 9 | $this->tail[] = $this->active; |
|
| 30 | 9 | return $this->active = $span; |
|
| 31 | } |
||
| 32 | |||
| 33 | 9 | public function createSpan(string $name): Span |
|
| 34 | { |
||
| 35 | 9 | $parent = $this->getActiveSpan()->getSpanContext(); |
|
| 36 | 9 | $context = SpanContext::fork($parent->getTraceId()); |
|
| 37 | 9 | $span = $this->generateSpanInstance($name, $context); |
|
| 38 | 9 | return $this->setActive($span); |
|
| 39 | } |
||
| 40 | |||
| 41 | 2 | public function getSpans(): array |
|
| 44 | } |
||
| 45 | |||
| 46 | 12 | private function generateSpanInstance($name, SpanContext $context): Span |
|
| 55 | } |
||
| 56 | } |
||
| 57 |