Skip to content

Commit b24aea5

Browse files
authored
Merge branch 'master' into monolog-logs-handler
2 parents 2f1dc4a + db21532 commit b24aea5

8 files changed

Lines changed: 72 additions & 16 deletions

src/ErrorHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ final class ErrorHandler
153153
private function __construct()
154154
{
155155
$this->exceptionReflection = new \ReflectionProperty(\Exception::class, 'trace');
156-
$this->exceptionReflection->setAccessible(true);
156+
if (\PHP_VERSION_ID < 80100) {
157+
$this->exceptionReflection->setAccessible(true);
158+
}
157159
}
158160

159161
/**

src/Tracing/PropagationContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private static function parseTraceparentAndBaggage(string $traceparent, string $
231231
$context->sampleRand = round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (float) $samplingContext->get('sample_rate'), 6);
232232
} else {
233233
// [rate, 1)
234-
$context->sampleRand = round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (1 - (float) $samplingContext->get('sample_rate')) + (float) $samplingContext->get('sample-rate'), 6);
234+
$context->sampleRand = round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (1 - (float) $samplingContext->get('sample_rate')) + (float) $samplingContext->get('sample_rate'), 6);
235235
}
236236
} elseif ($context->parentSampled !== null) {
237237
// [0, 1)

src/Tracing/TransactionContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private static function parseTraceAndBaggage(string $sentryTrace, string $baggag
196196
$context->getMetadata()->setSampleRand(round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (float) $samplingContext->get('sample_rate'), 6));
197197
} else {
198198
// [rate, 1)
199-
$context->getMetadata()->setSampleRand(round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (1 - (float) $samplingContext->get('sample_rate')) + (float) $samplingContext->get('sample-rate'), 6));
199+
$context->getMetadata()->setSampleRand(round(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * (1 - (float) $samplingContext->get('sample_rate')) + (float) $samplingContext->get('sample_rate'), 6));
200200
}
201201
} elseif ($context->parentSampled !== null) {
202202
// [0, 1)

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* capture_silenced_errors?: bool,
3030
* context_lines?: int|null,
3131
* default_integrations?: bool,
32-
* dsn?: string|bool|null|Dsn,
32+
* dsn?: string|bool|Dsn|null,
3333
* enable_logs?: bool,
3434
* environment?: string|null,
3535
* error_types?: int|null,

tests/FrameBuilderTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,16 @@ public function testGetFunctionArgumentsWithVariadicParameters(): void
300300

301301
$reflectionClass = new \ReflectionClass($frameBuilder);
302302
$getFunctionArgumentsMethod = $reflectionClass->getMethod('getFunctionArguments');
303-
$getFunctionArgumentsMethod->setAccessible(true);
303+
if (\PHP_VERSION_ID < 80100) {
304+
$getFunctionArgumentsMethod->setAccessible(true);
305+
}
304306

305307
$reflectionFunction = new \ReflectionFunction($testFunction);
306308

307309
$getFunctionArgumentValuesMethod = $reflectionClass->getMethod('getFunctionArgumentValues');
308-
$getFunctionArgumentValuesMethod->setAccessible(true);
310+
if (\PHP_VERSION_ID < 80100) {
311+
$getFunctionArgumentValuesMethod->setAccessible(true);
312+
}
309313

310314
$result = $getFunctionArgumentValuesMethod->invoke($frameBuilder, $reflectionFunction, $backtraceFrame['args']);
311315

@@ -331,7 +335,9 @@ public function testGetFunctionArgumentsWithOnlyVariadicParameters(): void
331335

332336
$reflectionClass = new \ReflectionClass($frameBuilder);
333337
$getFunctionArgumentValuesMethod = $reflectionClass->getMethod('getFunctionArgumentValues');
334-
$getFunctionArgumentValuesMethod->setAccessible(true);
338+
if (\PHP_VERSION_ID < 80100) {
339+
$getFunctionArgumentValuesMethod->setAccessible(true);
340+
}
335341

336342
$reflectionFunction = new \ReflectionFunction($testFunction);
337343

@@ -356,7 +362,9 @@ public function testGetFunctionArgumentsWithEmptyVariadicParameters(): void
356362

357363
$reflectionClass = new \ReflectionClass($frameBuilder);
358364
$getFunctionArgumentValuesMethod = $reflectionClass->getMethod('getFunctionArgumentValues');
359-
$getFunctionArgumentValuesMethod->setAccessible(true);
365+
if (\PHP_VERSION_ID < 80100) {
366+
$getFunctionArgumentValuesMethod->setAccessible(true);
367+
}
360368

361369
$reflectionFunction = new \ReflectionFunction($testFunction);
362370

@@ -383,7 +391,9 @@ public function testGetFunctionArgumentsWithNullValues(): void
383391

384392
$reflectionClass = new \ReflectionClass($frameBuilder);
385393
$getFunctionArgumentValuesMethod = $reflectionClass->getMethod('getFunctionArgumentValues');
386-
$getFunctionArgumentValuesMethod->setAccessible(true);
394+
if (\PHP_VERSION_ID < 80100) {
395+
$getFunctionArgumentValuesMethod->setAccessible(true);
396+
}
387397

388398
$reflectionFunction = new \ReflectionFunction($testFunction);
389399

@@ -418,7 +428,9 @@ public function testGetFunctionArgumentsWithGapsInBacktraceArrayIndices(): void
418428

419429
$reflectionClass = new \ReflectionClass($frameBuilder);
420430
$getFunctionArgumentValuesMethod = $reflectionClass->getMethod('getFunctionArgumentValues');
421-
$getFunctionArgumentValuesMethod->setAccessible(true);
431+
if (\PHP_VERSION_ID < 80100) {
432+
$getFunctionArgumentValuesMethod->setAccessible(true);
433+
}
422434

423435
$reflectionFunction = new \ReflectionFunction($testFunction);
424436

tests/SentrySdkExtension.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,30 @@ final class SentrySdkExtension implements BeforeTestHookInterface
1414
public function executeBeforeTest(string $test): void
1515
{
1616
$reflectionProperty = new \ReflectionProperty(SentrySdk::class, 'currentHub');
17-
$reflectionProperty->setAccessible(true);
17+
if (\PHP_VERSION_ID < 80100) {
18+
$reflectionProperty->setAccessible(true);
19+
}
1820
$reflectionProperty->setValue(null, null);
19-
$reflectionProperty->setAccessible(false);
21+
if (\PHP_VERSION_ID < 80100) {
22+
$reflectionProperty->setAccessible(false);
23+
}
2024

2125
$reflectionProperty = new \ReflectionProperty(Scope::class, 'globalEventProcessors');
22-
$reflectionProperty->setAccessible(true);
26+
if (\PHP_VERSION_ID < 80100) {
27+
$reflectionProperty->setAccessible(true);
28+
}
2329
$reflectionProperty->setValue(null, []);
24-
$reflectionProperty->setAccessible(false);
30+
if (\PHP_VERSION_ID < 80100) {
31+
$reflectionProperty->setAccessible(false);
32+
}
2533

2634
$reflectionProperty = new \ReflectionProperty(IntegrationRegistry::class, 'integrations');
27-
$reflectionProperty->setAccessible(true);
35+
if (\PHP_VERSION_ID < 80100) {
36+
$reflectionProperty->setAccessible(true);
37+
}
2838
$reflectionProperty->setValue(IntegrationRegistry::getInstance(), []);
29-
$reflectionProperty->setAccessible(false);
39+
if (\PHP_VERSION_ID < 80100) {
40+
$reflectionProperty->setAccessible(false);
41+
}
3042
}
3143
}

tests/Tracing/PropagationContextTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ public function testGetTraceContext()
136136
], $propagationContext->getTraceContext());
137137
}
138138

139+
public function testSampleRandRangeWhenParentNotSampledAndSampleRateProvided(): void
140+
{
141+
$propagationContext = PropagationContext::fromHeaders(
142+
'566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-0',
143+
'sentry-sample_rate=0.4'
144+
);
145+
146+
$sampleRand = $propagationContext->getSampleRand();
147+
148+
$this->assertNotNull($sampleRand);
149+
// Should be within [rate, 1) and rounded to 6 decimals
150+
$this->assertGreaterThanOrEqual(0.4, $sampleRand);
151+
$this->assertLessThanOrEqual(0.999999, $sampleRand);
152+
}
153+
139154
/**
140155
* @dataProvider gettersAndSettersDataProvider
141156
*/

tests/Tracing/TransactionContextTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,19 @@ public static function tracingDataProvider(): iterable
137137
true,
138138
];
139139
}
140+
141+
public function testSampleRandRangeWhenParentNotSampledAndSampleRateProvided(): void
142+
{
143+
$context = TransactionContext::fromHeaders(
144+
'566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-0',
145+
'sentry-sample_rate=0.4'
146+
);
147+
148+
$sampleRand = $context->getMetadata()->getSampleRand();
149+
150+
$this->assertNotNull($sampleRand);
151+
// Should be within [rate, 1) and rounded to 6 decimals
152+
$this->assertGreaterThanOrEqual(0.4, $sampleRand);
153+
$this->assertLessThanOrEqual(0.999999, $sampleRand);
154+
}
140155
}

0 commit comments

Comments
 (0)