Skip to content

Commit

Permalink
Only apply sample_rate to errors/messages (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Dec 18, 2023
1 parent 478371b commit cb2734f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,11 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco
$event->setEnvironment($this->options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT);
}

$isTransaction = EventType::transaction() === $event->getType();
$isEvent = EventType::event() === $event->getType();
$sampleRate = $this->options->getSampleRate();

if (!$isTransaction && $sampleRate < 1 && mt_rand(1, 100) / 100.0 > $sampleRate) {
// only sample with the `sample_rate` on errors/messages
if ($isEvent && $sampleRate < 1 && mt_rand(1, 100) / 100.0 > $sampleRate) {
$this->logger->info('The event will be discarded because it has been sampled.', ['event' => $event]);

return null;
Expand Down

0 comments on commit cb2734f

Please sign in to comment.