-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathResolvesEventOrigin.php
50 lines (38 loc) · 1.41 KB
/
ResolvesEventOrigin.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
<?php
namespace Sentry\Laravel\Features\Concerns;
use Illuminate\Contracts\Container\Container;
use Sentry\Laravel\Tracing\BacktraceHelper;
trait ResolvesEventOrigin
{
protected function container(): Container
{
return app();
}
protected function resolveEventOrigin(): ?array
{
$backtraceHelper = $this->makeBacktraceHelper();
// We limit the backtrace to 20 frames to prevent too much overhead and we'd reasonable expect the origin to be within the first 20 frames
$firstAppFrame = $backtraceHelper->findFirstInAppFrameForBacktrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20));
if ($firstAppFrame === null) {
return null;
}
$filePath = $backtraceHelper->getOriginalViewPathForFrameOfCompiledViewPath($firstAppFrame) ?? $firstAppFrame->getFile();
return [
'code.filepath' => $filePath,
'code.function' => $firstAppFrame->getFunctionName(),
'code.lineno' => $firstAppFrame->getLine(),
];
}
protected function resolveEventOriginAsString(): ?string
{
$origin = $this->resolveEventOrigin();
if ($origin === null) {
return null;
}
return "{$origin['code.filepath']}:{$origin['code.lineno']}";
}
private function makeBacktraceHelper(): BacktraceHelper
{
return $this->container()->make(BacktraceHelper::class);
}
}