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 77use Sentry \Tracing \Transaction ;
88use Sentry \Tracing \TransactionContext ;
99use Symfony \Component \HttpFoundation \Request ;
10- use Symfony \Component \HttpKernel \Event \FinishRequestEvent ;
1110
1211/**
1312 * This event listener acts on the master requests and starts a transaction
@@ -44,16 +43,12 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
4443
4544 /**
4645 * 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 .
4847 *
49- * @param FinishRequestEvent $event The event
48+ * @param RequestListenerTerminateEvent $event The event
5049 */
51- public function handleKernelFinishRequestEvent ( FinishRequestEvent $ event ): void
50+ public function handleKernelTerminateEvent ( RequestListenerTerminateEvent $ event ): void
5251 {
53- if (!$ event ->isMasterRequest ()) {
54- return ;
55- }
56-
5752 $ transaction = $ this ->hub ->getTransaction ();
5853
5954 if (null === $ transaction ) {
Original file line number Diff line number Diff line change 5858 <argument type =" service" id =" Sentry\State\HubInterface" />
5959
6060 <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" />
6261 <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" />
6363 </service >
6464
6565 <service id =" Sentry\SentryBundle\EventListener\TracingSubRequestListener" class =" Sentry\SentryBundle\EventListener\TracingSubRequestListener" >
Original file line number Diff line number Diff line change 1010use Sentry \Options ;
1111use Sentry \SentryBundle \EventListener \RequestListenerRequestEvent ;
1212use Sentry \SentryBundle \EventListener \RequestListenerResponseEvent ;
13+ use Sentry \SentryBundle \EventListener \RequestListenerTerminateEvent ;
1314use Sentry \SentryBundle \EventListener \TracingRequestListener ;
1415use Sentry \State \HubInterface ;
1516use Sentry \Tracing \SpanId ;
@@ -371,4 +372,37 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH
371372 new Response ()
372373 ));
373374 }
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+ }
374408}
You can’t perform that action at this time.
0 commit comments