File tree Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Original file line number Diff line number Diff line change 7
7
use Sentry \Tracing \Transaction ;
8
8
use Sentry \Tracing \TransactionContext ;
9
9
use Symfony \Component \HttpFoundation \Request ;
10
- use Symfony \Component \HttpKernel \Event \FinishRequestEvent ;
11
10
12
11
/**
13
12
* This event listener acts on the master requests and starts a transaction
@@ -44,16 +43,12 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
44
43
45
44
/**
46
45
* This method is called for each request handled by the framework and
47
- * ends the tracing.
46
+ * ends the tracing on terminate after the client received the response .
48
47
*
49
- * @param FinishRequestEvent $event The event
48
+ * @param RequestListenerTerminateEvent $event The event
50
49
*/
51
- public function handleKernelFinishRequestEvent ( FinishRequestEvent $ event ): void
50
+ public function handleKernelTerminateEvent ( RequestListenerTerminateEvent $ event ): void
52
51
{
53
- if (!$ event ->isMasterRequest ()) {
54
- return ;
55
- }
56
-
57
52
$ transaction = $ this ->hub ->getTransaction ();
58
53
59
54
if (null === $ transaction ) {
Original file line number Diff line number Diff line change 58
58
<argument type =" service" id =" Sentry\State\HubInterface" />
59
59
60
60
<tag name =" kernel.event_listener" event =" kernel.request" method =" handleKernelRequestEvent" priority =" 4" />
61
- <tag name =" kernel.event_listener" event =" kernel.finish_request" method =" handleKernelFinishRequestEvent" priority =" 5" />
62
61
<tag name =" kernel.event_listener" event =" kernel.response" method =" handleKernelResponseEvent" priority =" 15" />
62
+ <tag name =" kernel.event_listener" event =" kernel.terminate" method =" handleKernelTerminateEvent" priority =" 5" />
63
63
</service >
64
64
65
65
<service id =" Sentry\SentryBundle\EventListener\TracingSubRequestListener" class =" Sentry\SentryBundle\EventListener\TracingSubRequestListener" >
Original file line number Diff line number Diff line change 10
10
use Sentry \Options ;
11
11
use Sentry \SentryBundle \EventListener \RequestListenerRequestEvent ;
12
12
use Sentry \SentryBundle \EventListener \RequestListenerResponseEvent ;
13
+ use Sentry \SentryBundle \EventListener \RequestListenerTerminateEvent ;
13
14
use Sentry \SentryBundle \EventListener \TracingRequestListener ;
14
15
use Sentry \State \HubInterface ;
15
16
use Sentry \Tracing \SpanId ;
@@ -371,4 +372,37 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH
371
372
new Response ()
372
373
));
373
374
}
375
+
376
+ /**
377
+ * @group time-sensitive
378
+ */
379
+ public function testHandleKernelTerminateEvent (): void
380
+ {
381
+ $ transaction = new Transaction (new TransactionContext ());
382
+
383
+ $ this ->hub ->expects ($ this ->once ())
384
+ ->method ('getTransaction ' )
385
+ ->willReturn ($ transaction );
386
+
387
+ $ this ->listener ->handleKernelTerminateEvent (new RequestListenerTerminateEvent (
388
+ $ this ->createMock (HttpKernelInterface::class),
389
+ new Request (),
390
+ new Response ()
391
+ ));
392
+
393
+ $ this ->assertSame (microtime (true ), $ transaction ->getEndTimestamp ());
394
+ }
395
+
396
+ public function testHandleKernelTerminateEventDoesNothingIfNoTransactionIsSetOnHub (): void
397
+ {
398
+ $ this ->hub ->expects ($ this ->once ())
399
+ ->method ('getTransaction ' )
400
+ ->willReturn (null );
401
+
402
+ $ this ->listener ->handleKernelTerminateEvent (new RequestListenerTerminateEvent (
403
+ $ this ->createMock (HttpKernelInterface::class),
404
+ new Request (),
405
+ new Response ()
406
+ ));
407
+ }
374
408
}
You can’t perform that action at this time.
0 commit comments