1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Client requests tracing |
4
|
|
|
* User: moyo |
5
|
|
|
* Date: 24/11/2017 |
6
|
|
|
* Time: 4:48 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Carno\HRPC\Client\Handlers; |
10
|
|
|
|
11
|
|
|
use Carno\Chain\Layered; |
12
|
|
|
use Carno\Coroutine\Context; |
13
|
|
|
use Carno\HRPC\Client\Chips\ErrorsClassify; |
14
|
|
|
use Carno\HRPC\Client\Contracts\TRC; |
15
|
|
|
use Carno\HRPC\Client\Selector; |
16
|
|
|
use Carno\HTTP\Client; |
17
|
|
|
use Carno\HTTP\Standard\Helper as PSRHelper; |
18
|
|
|
use Carno\HTTP\Standard\Request as HRequest; |
19
|
|
|
use Carno\RPC\Protocol\Request as RRequest; |
20
|
|
|
use Carno\RPC\Protocol\Response as RResponse; |
21
|
|
|
use Carno\Tracing\Contracts\Platform; |
|
|
|
|
22
|
|
|
use Carno\Tracing\Contracts\Vars\EXT; |
|
|
|
|
23
|
|
|
use Carno\Tracing\Contracts\Vars\FMT; |
|
|
|
|
24
|
|
|
use Carno\Tracing\Contracts\Vars\TAG; |
|
|
|
|
25
|
|
|
use Carno\Tracing\Standard\Endpoint; |
|
|
|
|
26
|
|
|
use Carno\Tracing\Utils\SpansCreator; |
|
|
|
|
27
|
|
|
use Carno\Tracing\Utils\SpansLinker; |
|
|
|
|
28
|
|
|
use Throwable; |
29
|
|
|
|
30
|
|
|
class TracedRequesting implements Layered |
31
|
|
|
{ |
32
|
|
|
use ErrorsClassify; |
33
|
|
|
|
34
|
|
|
use SpansCreator; |
35
|
|
|
use SpansLinker; |
36
|
|
|
|
37
|
|
|
use PSRHelper; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Platform |
41
|
|
|
*/ |
42
|
|
|
private $platform = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* ClientRequesting constructor. |
46
|
|
|
* @param Platform $platform |
47
|
|
|
*/ |
48
|
|
|
public function __construct(Platform $platform) |
49
|
|
|
{ |
50
|
|
|
$this->platform = $platform; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param RRequest $request |
55
|
|
|
* @param Context $ctx |
56
|
|
|
* @return RRequest |
57
|
|
|
*/ |
58
|
|
|
public function inbound($request, Context $ctx) : RRequest |
59
|
|
|
{ |
60
|
|
|
/** |
61
|
|
|
* @var Client $cli |
62
|
|
|
*/ |
63
|
|
|
$cli = $request->getExtra(Selector::CLI); |
64
|
|
|
|
65
|
|
|
$http = new HRequest(); |
66
|
|
|
|
67
|
|
|
$this->newSpan( |
68
|
|
|
$ctx, |
69
|
|
|
sprintf('%s.%s', $request->service(), $request->method()), |
70
|
|
|
[ |
71
|
|
|
TAG::SPAN_KIND => TAG::SPAN_KIND_RPC_CLIENT, |
72
|
|
|
EXT::REMOTE_ENDPOINT => new Endpoint($request->server(), $cli->restricted()), |
73
|
|
|
TAG::ROUTE_TAGS => implode(',', $request->getTags()), |
74
|
|
|
TRC::TAG_CLI_APT => get_class($cli), |
75
|
|
|
], |
76
|
|
|
[], |
77
|
|
|
FMT::HTTP_HEADERS, |
78
|
|
|
$http, |
79
|
|
|
$this->linkedCTX($this->rootCTX($ctx)), |
80
|
|
|
$this->platform |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$headers = $this->getHeaderLines($http); |
84
|
|
|
|
85
|
|
|
$request->opsExtra('h-headers', static function (&$exists) use ($headers) { |
86
|
|
|
$exists = array_merge($exists, $headers); |
87
|
|
|
}); |
88
|
|
|
|
89
|
|
|
return $request; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param RResponse $response |
94
|
|
|
* @param Context $ctx |
95
|
|
|
* @return RResponse |
96
|
|
|
*/ |
97
|
|
|
public function outbound($response, Context $ctx) : RResponse |
98
|
|
|
{ |
99
|
|
|
$this->closeSpan($ctx); |
100
|
|
|
|
101
|
|
|
return $response; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param Throwable $e |
106
|
|
|
* @param Context $ctx |
107
|
|
|
* @throws Throwable |
108
|
|
|
*/ |
109
|
|
|
public function exception(Throwable $e, Context $ctx) : void |
110
|
|
|
{ |
111
|
|
|
$this->isGenericException($e, true) ? $this->closeSpan($ctx) : $this->errorSpan($ctx, $e); |
112
|
|
|
|
113
|
|
|
throw $e; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
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