5
5
use Illuminate \Database \Events \QueryExecuted ;
6
6
use Illuminate \Support \Collection ;
7
7
use Illuminate \Support \ServiceProvider ;
8
+ use Illuminate \Support \Str ;
9
+ use Illuminate \Support \Arr ;
8
10
use PhilKra \Agent ;
9
11
use PhilKra \ElasticApmLaravel \Apm \SpanCollection ;
10
12
use PhilKra \ElasticApmLaravel \Apm \Transaction ;
@@ -102,7 +104,7 @@ protected function getAppConfig(): array
102
104
protected function stripVendorTraces (Collection $ stackTrace ): Collection
103
105
{
104
106
return collect ($ stackTrace )->filter (function ($ trace ) {
105
- return !starts_with ( array_get ( $ trace , 'file ' ), [
107
+ return !Str:: startsWith ((Arr:: get ( $ trace , 'file ' ) ), [
106
108
base_path () . '/vendor ' ,
107
109
]);
108
110
});
@@ -118,29 +120,29 @@ protected function getSourceCode(array $stackTrace): Collection
118
120
return collect ([]);
119
121
}
120
122
121
- if (empty (array_get ($ stackTrace , 'file ' ))) {
123
+ if (empty (Arr:: get ($ stackTrace , 'file ' ))) {
122
124
return collect ([]);
123
125
}
124
126
125
- $ fileLines = file (array_get ($ stackTrace , 'file ' ));
127
+ $ fileLines = file (Arr:: get ($ stackTrace , 'file ' ));
126
128
return collect ($ fileLines )->filter (function ($ code , $ line ) use ($ stackTrace ) {
127
129
//file starts counting from 0, debug_stacktrace from 1
128
- $ stackTraceLine = array_get ($ stackTrace , 'line ' ) - 1 ;
130
+ $ stackTraceLine = Arr:: get ($ stackTrace , 'line ' ) - 1 ;
129
131
130
132
$ lineStart = $ stackTraceLine - 5 ;
131
133
$ lineStop = $ stackTraceLine + 5 ;
132
134
133
135
return $ line >= $ lineStart && $ line <= $ lineStop ;
134
136
})->groupBy (function ($ code , $ line ) use ($ stackTrace ) {
135
- if ($ line < array_get ($ stackTrace , 'line ' )) {
137
+ if ($ line < Arr:: get ($ stackTrace , 'line ' )) {
136
138
return 'pre_context ' ;
137
139
}
138
140
139
- if ($ line == array_get ($ stackTrace , 'line ' )) {
141
+ if ($ line == Arr:: get ($ stackTrace , 'line ' )) {
140
142
return 'context_line ' ;
141
143
}
142
144
143
- if ($ line > array_get ($ stackTrace , 'line ' )) {
145
+ if ($ line > Arr:: get ($ stackTrace , 'line ' )) {
144
146
return 'post_context ' ;
145
147
}
146
148
@@ -167,11 +169,11 @@ protected function listenForQueries()
167
169
$ sourceCode = $ this ->getSourceCode ($ trace );
168
170
169
171
return [
170
- 'function ' => array_get ($ trace , 'function ' ) . array_get ($ trace , 'type ' ) . array_get ($ trace ,
172
+ 'function ' => Arr:: get ($ trace , 'function ' ) . Arr:: get ($ trace , 'type ' ) . Arr:: get ($ trace ,
171
173
'function ' ),
172
- 'abs_path ' => array_get ($ trace , 'file ' ),
173
- 'filename ' => basename (array_get ($ trace , 'file ' )),
174
- 'lineno ' => array_get ($ trace , 'line ' , 0 ),
174
+ 'abs_path ' => Arr:: get ($ trace , 'file ' ),
175
+ 'filename ' => basename (Arr:: get ($ trace , 'file ' )),
176
+ 'lineno ' => Arr:: get ($ trace , 'line ' , 0 ),
175
177
'library_frame ' => false ,
176
178
'vars ' => $ vars ?? null ,
177
179
'pre_context ' => optional ($ sourceCode ->get ('pre_context ' ))->toArray (),
0 commit comments