@@ -65,6 +65,9 @@ public function testHandleKernelRequestEvent(Options $options, Request $request,
6565 $ this ->hub ->expects ($ this ->once ())
6666 ->method ('startTransaction ' )
6767 ->with ($ this ->callback (function (TransactionContext $ context ) use ($ expectedTransactionContext ): bool {
68+ // This value is random when the metadata is constructed, thus we set it to a fixed expected value since we don't care for the value here
69+ $ context ->getMetadata ()->setSampleRand (0.1337 );
70+
6871 $ this ->assertEquals ($ expectedTransactionContext , $ context );
6972
7073 return true ;
@@ -108,6 +111,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
108111 'net.host.name ' => 'www.example.com ' ,
109112 ]);
110113 $ transactionContext ->getMetadata ()->setDynamicSamplingContext ($ samplingContext );
114+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
111115
112116 yield 'request.headers.sentry-trace EXISTS ' => [
113117 new Options (),
@@ -146,6 +150,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
146150 'net.host.name ' => 'www.example.com ' ,
147151 ]);
148152 $ transactionContext ->getMetadata ()->setDynamicSamplingContext ($ samplingContext );
153+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
149154
150155 yield 'request.headers.traceparent EXISTS ' => [
151156 new Options (),
@@ -184,6 +189,8 @@ public function handleKernelRequestEventDataProvider(): \Generator
184189 'net.host.name ' => 'www.example.com ' ,
185190 ]);
186191 $ transactionContext ->getMetadata ()->setDynamicSamplingContext ($ samplingContext );
192+ $ transactionContext ->getMetadata ()->setParentSamplingRate (1.0 );
193+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
187194
188195 yield 'request.headers.sentry-trace and headers.baggage EXISTS ' => [
189196 new Options (),
@@ -216,6 +223,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
216223 'route ' => '<unknown> ' ,
217224 'net.host.name ' => 'www.example.com ' ,
218225 ]);
226+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
219227
220228 $ request = Request::create ('http://www.example.com ' );
221229 $ request ->server ->remove ('REQUEST_TIME_FLOAT ' );
@@ -240,6 +248,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
240248 'route ' => '<unknown> ' ,
241249 'net.host.ip ' => '127.0.0.1 ' ,
242250 ]);
251+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
243252
244253 yield 'request.server.HOST IS IPV4 ' => [
245254 new Options (),
@@ -272,6 +281,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
272281 'route ' => 'app_homepage ' ,
273282 'net.host.name ' => 'www.example.com ' ,
274283 ]);
284+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
275285
276286 yield 'request.attributes.route IS STRING ' => [
277287 new Options (),
@@ -297,6 +307,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
297307 'route ' => '/path ' ,
298308 'net.host.name ' => 'www.example.com ' ,
299309 ]);
310+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
300311
301312 yield 'request.attributes.route IS INSTANCEOF Symfony\Component\Routing\Route ' => [
302313 new Options (),
@@ -322,6 +333,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
322333 'route ' => 'App \\Controller::indexAction ' ,
323334 'net.host.name ' => 'www.example.com ' ,
324335 ]);
336+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
325337
326338 yield 'request.attributes._controller IS STRING ' => [
327339 new Options (),
@@ -347,6 +359,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
347359 'route ' => 'App \\Controller::indexAction ' ,
348360 'net.host.name ' => 'www.example.com ' ,
349361 ]);
362+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
350363
351364 yield 'request.attributes._controller IS CALLABLE (1) ' => [
352365 new Options (),
@@ -372,6 +385,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
372385 'route ' => 'class@anonymous::indexAction ' ,
373386 'net.host.name ' => 'www.example.com ' ,
374387 ]);
388+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
375389
376390 yield 'request.attributes._controller IS CALLABLE (2) ' => [
377391 new Options (),
@@ -397,6 +411,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
397411 'route ' => '<unknown> ' ,
398412 'net.host.name ' => 'www.example.com ' ,
399413 ]);
414+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
400415
401416 yield 'request.attributes._controller IS ARRAY and NOT VALID CALLABLE ' => [
402417 new Options (),
@@ -423,6 +438,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
423438 'net.host.name ' => 'www.example.com ' ,
424439 'net.peer.ip ' => '127.0.0.1 ' ,
425440 ]);
441+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
426442
427443 yield 'request.server.REMOTE_ADDR EXISTS and client.options.send_default_pii = TRUE ' => [
428444 new Options (['send_default_pii ' => true ]),
@@ -446,6 +462,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
446462 'route ' => '<unknown> ' ,
447463 'net.host.name ' => '' ,
448464 ]);
465+ $ transactionContext ->getMetadata ()->setSampleRand (0.1337 );
449466
450467 yield 'request.server.SERVER_PROTOCOL NOT EXISTS ' => [
451468 new Options (),
0 commit comments