Skip to content

Commit f7c20bc

Browse files
authored
Merge branch 'master' into patch-1
2 parents fd16785 + dbdbac4 commit f7c20bc

9 files changed

Lines changed: 43 additions & 15 deletions

File tree

src/ErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,9 @@ private function handleException(\Throwable $exception): void
458458
* @param string $file The filename the backtrace was raised in
459459
* @param int $line The line number the backtrace was raised at
460460
*
461-
* @return array<int, mixed>
462-
*
463461
* @psalm-param list<StacktraceFrame> $backtrace
462+
*
463+
* @return array<int, mixed>
464464
*/
465465
private function cleanBacktraceFromErrorHandlerFrames(array $backtrace, string $file, int $line): array
466466
{

src/Event.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,12 @@ public function setSdkMetadata(string $name, $data): self
892892
/**
893893
* Gets the SDK metadata.
894894
*
895-
* @return mixed
896-
*
897895
* @psalm-template T of string|null
898896
*
899897
* @psalm-param T $name
900898
*
899+
* @return mixed
900+
*
901901
* @psalm-return (T is string ? mixed : array<string, mixed>|null)
902902
*/
903903
public function getSdkMetadata(?string $name = null)

src/FrameBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ private function isFrameInApp(string $file, ?string $functionName): bool
158158
*
159159
* @param array<string, mixed> $backtraceFrame The frame data
160160
*
161-
* @return array<string, mixed>
162-
*
163161
* @psalm-param StacktraceFrame $backtraceFrame
162+
*
163+
* @return array<string, mixed>
164164
*/
165165
private function getFunctionArguments(array $backtraceFrame): array
166166
{

src/Monolog/BreadcrumbHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ final class BreadcrumbHandler extends AbstractProcessingHandler
2626
private $hub;
2727

2828
/**
29-
* @phpstan-param int|string|Level|LogLevel::* $level
30-
*
3129
* @param HubInterface $hub The hub to which errors are reported
3230
* @param int|string $level The minimum logging level at which this
3331
* handler will be triggered
3432
* @param bool $bubble Whether the messages that are handled can
3533
* bubble up the stack or not
34+
*
35+
* @phpstan-param int|string|Level|LogLevel::* $level
3636
*/
3737
public function __construct(HubInterface $hub, $level = Logger::DEBUG, bool $bubble = true)
3838
{

src/State/Hub.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ public function startTransaction(TransactionContext $context, array $customSampl
276276

277277
if ($tracesSampler !== null) {
278278
$sampleRate = $tracesSampler($samplingContext);
279-
280279
$sampleSource = 'config:traces_sampler';
281280
} else {
282281
$parentSampleRate = $context->getMetadata()->getParentSamplingRate();
@@ -302,6 +301,12 @@ public function startTransaction(TransactionContext $context, array $customSampl
302301

303302
$transaction->getMetadata()->setSamplingRate($sampleRate);
304303

304+
// Always overwrite the sample_rate in the DSC
305+
$dynamicSamplingContext = $context->getMetadata()->getDynamicSamplingContext();
306+
if ($dynamicSamplingContext !== null) {
307+
$dynamicSamplingContext->set('sample_rate', (string) $sampleRate, true);
308+
}
309+
305310
if ($sampleRate === 0.0) {
306311
$transaction->setSampled(false);
307312

src/State/HubInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public function popScope(): bool;
5151
*
5252
* @param callable $callback The callback to be executed
5353
*
54-
* @return mixed|void The callback's return value, upon successful execution
55-
*
5654
* @psalm-template T
5755
*
5856
* @psalm-param callable(Scope): T $callback
5957
*
58+
* @return mixed|void The callback's return value, upon successful execution
59+
*
6060
* @psalm-return T
6161
*/
6262
public function withScope(callable $callback);

src/Tracing/DynamicSamplingContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ private function __construct()
4040
* @param string $key the list member key
4141
* @param string $value the list member value
4242
*/
43-
public function set(string $key, string $value): self
43+
public function set(string $key, string $value, bool $forceOverwrite = false): self
4444
{
45-
if ($this->isFrozen) {
45+
if ($this->isFrozen && !$forceOverwrite) {
4646
return $this;
4747
}
4848

src/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ function configureScope(callable $callback): void
201201
*
202202
* @param callable $callback The callback to be executed
203203
*
204-
* @return mixed|void The callback's return value, upon successful execution
205-
*
206204
* @psalm-template T
207205
*
208206
* @psalm-param callable(Scope): T $callback
209207
*
208+
* @return mixed|void The callback's return value, upon successful execution
209+
*
210210
* @psalm-return T
211211
*/
212212
function withScope(callable $callback)

tests/State/HubTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
use Sentry\Severity;
2121
use Sentry\State\Hub;
2222
use Sentry\State\Scope;
23+
use Sentry\Tracing\DynamicSamplingContext;
2324
use Sentry\Tracing\PropagationContext;
2425
use Sentry\Tracing\SamplingContext;
2526
use Sentry\Tracing\TransactionContext;
27+
use Sentry\Tracing\TransactionMetadata;
2628
use Sentry\Util\SentryUid;
2729

2830
final class HubTest extends TestCase
@@ -805,6 +807,27 @@ public function testStartTransactionWithCustomSamplingContext(): void
805807
$hub->startTransaction(new TransactionContext(), $customSamplingContext);
806808
}
807809

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+
808831
public function testGetTransactionReturnsInstanceSetOnTheScopeIfTransactionIsNotSampled(): void
809832
{
810833
$client = $this->createMock(ClientInterface::class);

0 commit comments

Comments
 (0)