Skip to content

Commit 7e7bf58

Browse files
committed
add more tests
1 parent 96fe163 commit 7e7bf58

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/Tracing/DynamicSamplingContextTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function testFromHeader(
2828
?string $expectedSampleRate,
2929
?string $expectedRelease,
3030
?string $expectedEnvironment,
31-
?string $expectedTransaction
31+
?string $expectedTransaction,
32+
?string $expectedSampleRand,
3233
): void {
3334
$samplingContext = DynamicSamplingContext::fromHeader($header);
3435

@@ -38,6 +39,7 @@ public function testFromHeader(
3839
$this->assertSame($expectedRelease, $samplingContext->get('release'));
3940
$this->assertSame($expectedEnvironment, $samplingContext->get('environment'));
4041
$this->assertSame($expectedTransaction, $samplingContext->get('transaction'));
42+
$this->assertSame($expectedSampleRand, $samplingContext->get('sample_rand'));
4143
}
4244

4345
public static function fromHeaderDataProvider(): \Generator
@@ -51,6 +53,7 @@ public static function fromHeaderDataProvider(): \Generator
5153
null,
5254
null,
5355
null,
56+
null,
5457
];
5558

5659
yield [
@@ -61,16 +64,18 @@ public static function fromHeaderDataProvider(): \Generator
6164
null,
6265
null,
6366
null,
67+
null,
6468
];
6569

6670
yield [
67-
'sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1,sentry-release=1.0.0,sentry-environment=test,sentry-user_segment=my_segment,sentry-transaction=<unlabeled transaction>',
71+
'sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1,sentry-release=1.0.0,sentry-environment=test,sentry-user_segment=my_segment,sentry-transaction=<unlabeled transaction>,sentry-sample_rand=0.5',
6872
'd49d9bf66f13450b81f65bc51cf49c03',
6973
'public',
7074
'1',
7175
'1.0.0',
7276
'test',
7377
'<unlabeled transaction>',
78+
'0.5',
7479
];
7580
}
7681

@@ -92,6 +97,7 @@ public function testFromTransaction(): void
9297

9398
$transaction = new Transaction($transactionContext, $hub);
9499
$transaction->getMetadata()->setSamplingRate(1.0);
100+
$transaction->getMetadata()->setSampleRand(0.5);
95101

96102
$samplingContext = DynamicSamplingContext::fromTransaction($transaction, $hub);
97103

@@ -101,6 +107,7 @@ public function testFromTransaction(): void
101107
$this->assertSame('public', $samplingContext->get('public_key'));
102108
$this->assertSame('1.0.0', $samplingContext->get('release'));
103109
$this->assertSame('test', $samplingContext->get('environment'));
110+
$this->assertSame('0.5', $samplingContext->get('sample_rand'));
104111
$this->assertTrue($samplingContext->isFrozen());
105112
}
106113

@@ -130,6 +137,7 @@ public function testFromOptions(): void
130137

131138
$propagationContext = PropagationContext::fromDefaults();
132139
$propagationContext->setTraceId(new TraceId('21160e9b836d479f81611368b2aa3d2c'));
140+
$propagationContext->setSampleRand(0.5);
133141

134142
$scope = new Scope();
135143
$scope->setPropagationContext($propagationContext);
@@ -141,6 +149,7 @@ public function testFromOptions(): void
141149
$this->assertSame('public', $samplingContext->get('public_key'));
142150
$this->assertSame('1.0.0', $samplingContext->get('release'));
143151
$this->assertSame('test', $samplingContext->get('environment'));
152+
$this->assertSame('0.5', $samplingContext->get('sample_rand'));
144153
$this->assertTrue($samplingContext->isFrozen());
145154
}
146155

0 commit comments

Comments
 (0)