Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Laravel 6 support #68

Merged
merged 2 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2019-09-30 (6.0.1) devngl
* Laravel 6 support.

2019-02-27 (5.7.6) mpetrunic
* Fix Lumen compatibility issues

Expand Down
24 changes: 13 additions & 11 deletions src/Providers/ElasticApmServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
use PhilKra\Agent;
use PhilKra\ElasticApmLaravel\Apm\SpanCollection;
use PhilKra\ElasticApmLaravel\Apm\Transaction;
Expand Down Expand Up @@ -102,7 +104,7 @@ protected function getAppConfig(): array
protected function stripVendorTraces(Collection $stackTrace): Collection
{
return collect($stackTrace)->filter(function ($trace) {
return !starts_with(array_get($trace, 'file'), [
return !Str::startsWith((Arr::get($trace, 'file')), [
base_path() . '/vendor',
]);
});
Expand All @@ -118,29 +120,29 @@ protected function getSourceCode(array $stackTrace): Collection
return collect([]);
}

if (empty(array_get($stackTrace, 'file'))) {
if (empty(Arr::get($stackTrace, 'file'))) {
return collect([]);
}

$fileLines = file(array_get($stackTrace, 'file'));
$fileLines = file(Arr::get($stackTrace, 'file'));
return collect($fileLines)->filter(function ($code, $line) use ($stackTrace) {
//file starts counting from 0, debug_stacktrace from 1
$stackTraceLine = array_get($stackTrace, 'line') - 1;
$stackTraceLine = Arr::get($stackTrace, 'line') - 1;

$lineStart = $stackTraceLine - 5;
$lineStop = $stackTraceLine + 5;

return $line >= $lineStart && $line <= $lineStop;
})->groupBy(function ($code, $line) use ($stackTrace) {
if ($line < array_get($stackTrace, 'line')) {
if ($line < Arr::get($stackTrace, 'line')) {
return 'pre_context';
}

if ($line == array_get($stackTrace, 'line')) {
if ($line == Arr::get($stackTrace, 'line')) {
return 'context_line';
}

if ($line > array_get($stackTrace, 'line')) {
if ($line > Arr::get($stackTrace, 'line')) {
return 'post_context';
}

Expand All @@ -167,11 +169,11 @@ protected function listenForQueries()
$sourceCode = $this->getSourceCode($trace);

return [
'function' => array_get($trace, 'function') . array_get($trace, 'type') . array_get($trace,
'function' => Arr::get($trace, 'function') . Arr::get($trace, 'type') . Arr::get($trace,
'function'),
'abs_path' => array_get($trace, 'file'),
'filename' => basename(array_get($trace, 'file')),
'lineno' => array_get($trace, 'line', 0),
'abs_path' => Arr::get($trace, 'file'),
'filename' => basename(Arr::get($trace, 'file')),
'lineno' => Arr::get($trace, 'line', 0),
'library_frame' => false,
'vars' => $vars ?? null,
'pre_context' => optional($sourceCode->get('pre_context'))->toArray(),
Expand Down