@@ -154,7 +154,13 @@ public function setBootedTimestamp(?float $timestamp = null): void
154
154
155
155
private function startTransaction (Request $ request , HubInterface $ sentry ): void
156
156
{
157
- $ requestStartTime = $ request ->server ('REQUEST_TIME_FLOAT ' , microtime (true ));
157
+ // Try $_SERVER['REQUEST_TIME_FLOAT'] then LARAVEL_START and fallback to microtime(true) if neither are defined
158
+ $ requestStartTime = $ request ->server (
159
+ 'REQUEST_TIME_FLOAT ' ,
160
+ defined ('LARAVEL_START ' )
161
+ ? LARAVEL_START
162
+ : microtime (true )
163
+ );
158
164
159
165
$ context = continueTrace (
160
166
$ request ->header ('sentry-trace ' , '' ),
@@ -175,17 +181,16 @@ private function startTransaction(Request $request, HubInterface $sentry): void
175
181
176
182
$ transaction = $ sentry ->startTransaction ($ context );
177
183
178
- // If this transaction is not sampled, don't set it either and stop doing work from this point on
184
+ // If this transaction is not sampled, we can stop here to prevent doing work for nothing
179
185
if (!$ transaction ->getSampled ()) {
180
186
return ;
181
187
}
182
188
183
189
$ this ->transaction = $ transaction ;
184
190
185
- // Setting the Transaction on the Hub
186
191
SentrySdk::getCurrentHub ()->setSpan ($ this ->transaction );
187
192
188
- $ bootstrapSpan = $ this ->addAppBootstrapSpan ($ request );
193
+ $ bootstrapSpan = $ this ->addAppBootstrapSpan ();
189
194
190
195
$ appContextStart = new SpanContext ;
191
196
$ appContextStart ->setOp ('middleware.handle ' );
@@ -196,21 +201,15 @@ private function startTransaction(Request $request, HubInterface $sentry): void
196
201
SentrySdk::getCurrentHub ()->setSpan ($ this ->appSpan );
197
202
}
198
203
199
- private function addAppBootstrapSpan (Request $ request ): ?Span
204
+ private function addAppBootstrapSpan (): ?Span
200
205
{
201
206
if ($ this ->bootedTimestamp === null ) {
202
207
return null ;
203
208
}
204
209
205
- $ laravelStartTime = defined ('LARAVEL_START ' ) ? LARAVEL_START : $ request ->server ('REQUEST_TIME_FLOAT ' );
206
-
207
- if ($ laravelStartTime === null ) {
208
- return null ;
209
- }
210
-
211
210
$ spanContextStart = new SpanContext ;
212
211
$ spanContextStart ->setOp ('app.bootstrap ' );
213
- $ spanContextStart ->setStartTimestamp ($ laravelStartTime );
212
+ $ spanContextStart ->setStartTimestamp ($ this -> transaction -> getStartTimestamp () );
214
213
$ spanContextStart ->setEndTimestamp ($ this ->bootedTimestamp );
215
214
216
215
$ span = $ this ->transaction ->startChild ($ spanContextStart );
@@ -232,9 +231,9 @@ private function addBootDetailTimeSpans(Span $bootstrap): void
232
231
return ;
233
232
}
234
233
235
- $ autoload = new SpanContext () ;
234
+ $ autoload = new SpanContext ;
236
235
$ autoload ->setOp ('app.php.autoload ' );
237
- $ autoload ->setStartTimestamp ($ bootstrap ->getStartTimestamp ());
236
+ $ autoload ->setStartTimestamp ($ this -> transaction ->getStartTimestamp ());
238
237
$ autoload ->setEndTimestamp (SENTRY_AUTOLOAD );
239
238
240
239
$ bootstrap ->startChild ($ autoload );
0 commit comments