-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRequestSpanOptionsFactory.php
57 lines (49 loc) · 1.64 KB
/
RequestSpanOptionsFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Auxmoney\OpentracingBundle\Factory;
use Auxmoney\OpentracingBundle\Internal\Utility;
use PackageVersions\Versions;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Kernel;
final class RequestSpanOptionsFactory implements SpanOptionsFactory
{
private Utility $utility;
private string $kernelDebug;
private string $kernelEnvironment;
private string $hostName;
public function __construct(
Utility $utility,
string $kernelDebug,
string $kernelEnvironment,
string $hostName
) {
$this->utility = $utility;
$this->kernelDebug = $kernelDebug;
$this->kernelEnvironment = $kernelEnvironment;
$this->hostName = $hostName;
}
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function createSpanOptions(Request $request = null): array
{
$options = [
'tags' => [
'kernel.debug' => $this->kernelDebug ? 'true' : 'false',
'kernel.environment' => $this->kernelEnvironment,
'symfony.version' => Kernel::VERSION,
'opentracing.version' => Versions::getVersion('auxmoney/opentracing-bundle-core'),
'pod/host' => $this->hostName,
'php.version' => PHP_VERSION,
]
];
if ($request) {
$externalSpanContext = $this->utility->extractSpanContext($request->headers->all());
if ($externalSpanContext) {
$options['child_of'] = $externalSpanContext;
}
}
return $options;
}
}