1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Telemetry; |
6
|
|
|
|
7
|
|
|
use Spiral\Core\BinderInterface; |
8
|
|
|
use Spiral\Core\Container; |
9
|
|
|
use Spiral\Core\ContainerScope; |
10
|
|
|
use Spiral\Core\InvokerInterface; |
11
|
|
|
use Spiral\Core\ScopeInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @internal The component is under development. |
15
|
|
|
* Something may be changed in the future. We will stable it soon. |
16
|
|
|
* Feedback is welcome {@link https://github.com/spiral/framework/discussions/822}. |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractTracer implements TracerInterface |
19
|
|
|
{ |
20
|
626 |
|
public function __construct( |
21
|
|
|
private readonly ?ScopeInterface $scope = new Container(), |
22
|
626 |
|
) {} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @throws \Throwable |
26
|
|
|
*/ |
27
|
177 |
|
final protected function runScope(SpanInterface $span, callable $callback): mixed |
28
|
|
|
{ |
29
|
177 |
|
$container = ContainerScope::getContainer(); |
30
|
177 |
|
if ($container === null) { |
31
|
112 |
|
return $this->scope->runScope([ |
|
|
|
|
32
|
112 |
|
SpanInterface::class => $span, |
33
|
112 |
|
TracerInterface::class => $this, |
34
|
112 |
|
], static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback)); |
35
|
|
|
} |
36
|
|
|
|
37
|
125 |
|
if ($container instanceof Container) { |
38
|
124 |
|
$invoker = $container; |
39
|
124 |
|
$binder = $container; |
40
|
|
|
} else { |
41
|
|
|
/** @var InvokerInterface $invoker */ |
42
|
1 |
|
$invoker = $container->get(InvokerInterface::class); |
43
|
|
|
/** @var BinderInterface $binder */ |
44
|
1 |
|
$binder = $container->get(BinderInterface::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
try { |
48
|
125 |
|
$prevSpan = $container->get(SpanInterface::class); |
49
|
65 |
|
} catch (\Throwable) { |
50
|
65 |
|
$prevSpan = null; |
51
|
|
|
} |
52
|
|
|
|
53
|
125 |
|
$binder->bindSingleton(SpanInterface::class, $span); |
54
|
|
|
if ($prevSpan === null) { |
55
|
125 |
|
$binder->bindSingleton(TracerInterface::class, $this, true); |
|
|
|
|
56
|
|
|
} |
57
|
125 |
|
|
58
|
65 |
|
try { |
59
|
125 |
|
return $invoker->invoke($callback); |
60
|
|
|
} finally { |
61
|
|
|
if ($prevSpan === null) { |
62
|
|
|
$binder->removeBinding(SpanInterface::class); |
63
|
|
|
$binder->removeBinding(TracerInterface::class); |
64
|
|
|
} else { |
65
|
|
|
$binder->bindSingleton(SpanInterface::class, $prevSpan); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.