1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* OpenTracing::Tracer |
4
|
|
|
* User: moyo |
5
|
|
|
* Date: 23/11/2017 |
6
|
|
|
* Time: 10:38 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Carno\Tracing\Standard; |
10
|
|
|
|
11
|
|
|
use Carno\Tracing\Chips\RootInitializer; |
12
|
|
|
use Carno\Tracing\Contracts\Platform; |
13
|
|
|
use Carno\Tracing\Contracts\Vars\FMT; |
14
|
|
|
use Carno\Tracing\Exception\UnsupportedCarrierInstance; |
15
|
|
|
use OpenTracing\Exceptions\SpanContextNotFound; |
16
|
|
|
use OpenTracing\Exceptions\UnsupportedFormat; |
17
|
|
|
use OpenTracing\Span as OpenSpan; |
18
|
|
|
use OpenTracing\SpanContext; |
19
|
|
|
use OpenTracing\SpanOptions; |
20
|
|
|
use OpenTracing\Tracer as TracerAPI; |
21
|
|
|
use Psr\Http\Message\MessageInterface; |
|
|
|
|
22
|
|
|
|
23
|
|
|
class Tracer implements TracerAPI |
24
|
|
|
{ |
25
|
|
|
use RootInitializer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Platform |
29
|
|
|
*/ |
30
|
|
|
private $platform = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Tracer constructor. |
34
|
|
|
* @param Platform $platform |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Platform $platform) |
37
|
|
|
{ |
38
|
|
|
$this->platform = $platform; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $operationName |
43
|
|
|
* @param SpanOptions $options |
44
|
|
|
* @return OpenSpan |
45
|
|
|
*/ |
46
|
|
|
public function startSpan($operationName, $options = null) : OpenSpan |
47
|
|
|
{ |
48
|
|
|
$context = null; |
49
|
|
|
$startTime = null; |
50
|
|
|
|
51
|
|
|
if ($options) { |
52
|
|
|
$startTime = $options->getStartTime(); |
53
|
|
|
$references = $options->getReferences(); |
54
|
|
|
if ($references) { |
|
|
|
|
55
|
|
|
$context = (reset($references))->getContext(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$span = new Span( |
60
|
|
|
$this->platform->serializer(), |
61
|
|
|
$this->platform->transporter(), |
62
|
|
|
$context ?? $this->newContext(), |
63
|
|
|
$startTime |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$span->overwriteOperationName($operationName); |
67
|
|
|
|
68
|
|
|
if ($options) { |
69
|
|
|
$span->setTags($options->getTags()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $span; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param SpanContext $spanContext |
77
|
|
|
* @param string $format |
78
|
|
|
* @param mixed $carrier |
79
|
|
|
*/ |
80
|
|
|
public function inject(SpanContext $spanContext, $format, &$carrier) : void |
81
|
|
|
{ |
82
|
|
|
switch ($format) { |
83
|
|
|
case FMT::HTTP_HEADERS: |
84
|
|
|
if ($carrier instanceof MessageInterface) { |
85
|
|
|
$this->platform->carrier()->http($carrier)->fusedContext($spanContext); |
86
|
|
|
} else { |
87
|
|
|
throw UnsupportedCarrierInstance::for(gettype($carrier)); |
88
|
|
|
} |
89
|
|
|
break; |
90
|
|
|
default: |
91
|
|
|
throw UnsupportedFormat::forFormat($format); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $format |
97
|
|
|
* @param mixed $carrier |
98
|
|
|
* @return SpanContext |
99
|
|
|
*/ |
100
|
|
|
public function extract($format, $carrier) : SpanContext |
101
|
|
|
{ |
102
|
|
|
switch ($format) { |
103
|
|
|
case FMT::PREV_CTX: |
104
|
|
|
return $this->platform->carrier()->ctx($carrier)->fusedContext(); |
105
|
|
|
case FMT::HTTP_HEADERS: |
106
|
|
|
if ($carrier instanceof MessageInterface) { |
107
|
|
|
return $this->platform->carrier()->http($carrier)->fusedContext(); |
108
|
|
|
} |
109
|
|
|
throw SpanContextNotFound::create(); |
110
|
|
|
default: |
111
|
|
|
throw UnsupportedFormat::forFormat($format); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* flush to some collector |
117
|
|
|
*/ |
118
|
|
|
public function flush() : void |
119
|
|
|
{ |
120
|
|
|
$this->platform->transporter()->flushing(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths