|
20 | 20 | use Sentry\Severity; |
21 | 21 | use Sentry\State\Hub; |
22 | 22 | use Sentry\State\Scope; |
| 23 | +use Sentry\Tracing\DynamicSamplingContext; |
23 | 24 | use Sentry\Tracing\PropagationContext; |
24 | 25 | use Sentry\Tracing\SamplingContext; |
25 | 26 | use Sentry\Tracing\TransactionContext; |
| 27 | +use Sentry\Tracing\TransactionMetadata; |
26 | 28 | use Sentry\Util\SentryUid; |
27 | 29 |
|
28 | 30 | final class HubTest extends TestCase |
@@ -805,6 +807,27 @@ public function testStartTransactionWithCustomSamplingContext(): void |
805 | 807 | $hub->startTransaction(new TransactionContext(), $customSamplingContext); |
806 | 808 | } |
807 | 809 |
|
| 810 | + public function testStartTransactionUpdatesTheDscSampleRate(): void |
| 811 | + { |
| 812 | + $client = $this->createMock(ClientInterface::class); |
| 813 | + $client->expects($this->once()) |
| 814 | + ->method('getOptions') |
| 815 | + ->willReturn(new Options([ |
| 816 | + 'traces_sampler' => function (SamplingContext $samplingContext): float { |
| 817 | + return 1.0; |
| 818 | + }, |
| 819 | + ])); |
| 820 | + |
| 821 | + $hub = new Hub($client); |
| 822 | + |
| 823 | + $dsc = DynamicSamplingContext::fromHeader('sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public'); |
| 824 | + $transactionMetaData = new TransactionMetadata(null, $dsc); |
| 825 | + $transactionContext = new TransactionContext(TransactionContext::DEFAULT_NAME, null, $transactionMetaData); |
| 826 | + |
| 827 | + $transaction = $hub->startTransaction($transactionContext); |
| 828 | + $this->assertSame('1', $transaction->getMetadata()->getDynamicSamplingContext()->get('sample_rate')); |
| 829 | + } |
| 830 | + |
808 | 831 | public function testGetTransactionReturnsInstanceSetOnTheScopeIfTransactionIsNotSampled(): void |
809 | 832 | { |
810 | 833 | $client = $this->createMock(ClientInterface::class); |
|
0 commit comments