/
ViewEngineDecorator.php
59 lines (43 loc) · 1.37 KB
/
ViewEngineDecorator.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
58
59
<?php
namespace Sentry\Laravel\Tracing;
use Illuminate\Contracts\View\Engine;
use Illuminate\View\Factory;
use Sentry\Laravel\Integration;
use Sentry\SentrySdk;
use Sentry\Tracing\SpanContext;
final class ViewEngineDecorator implements Engine
{
public const SHARED_KEY = '__sentry_tracing_view_name';
/** @var Engine */
private $engine;
/** @var Factory */
private $viewFactory;
public function __construct(Engine $engine, Factory $viewFactory)
{
$this->engine = $engine;
$this->viewFactory = $viewFactory;
}
/**
* {@inheritdoc}
*/
public function get($path, array $data = []): string
{
$parentSpan = Integration::currentTracingSpan();
if ($parentSpan === null) {
return $this->engine->get($path, $data);
}
$context = new SpanContext();
$context->setOp('view.render');
$context->setDescription($this->viewFactory->shared(self::SHARED_KEY, basename($path)));
$span = $parentSpan->startChild($context);
SentrySdk::getCurrentHub()->setSpan($span);
$result = $this->engine->get($path, $data);
$span->finish();
SentrySdk::getCurrentHub()->setSpan($parentSpan);
return $result;
}
public function __call($name, $arguments)
{
return call_user_func_array([$this->engine, $name], $arguments);
}
}