MediaWiki master
ProbabilisticSampler.php
Go to the documentation of this file.
1<?php
2namespace Wikimedia\Telemetry;
3
4use Wikimedia\Assert\Assert;
5
18 private int $percentChance;
19
20 public function __construct( int $percentChance ) {
21 Assert::parameter(
22 $percentChance >= 0 && $percentChance <= 100,
23 '$percentChance',
24 'must be between 0 and 100 inclusive'
25 );
26 $this->percentChance = $percentChance;
27 }
28
30 public function shouldSample( ?SpanContext $parentSpanContext ): bool {
31 if ( $parentSpanContext !== null ) {
32 return $parentSpanContext->isSampled();
33 }
34
35 return mt_rand( 1, 100 ) <= $this->percentChance;
36 }
37}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
A SamplerInterface implementation that samples a given percentage of root spans, while respecting sam...
shouldSample(?SpanContext $parentSpanContext)
Determine whether a newly created span should be sampled based on its parent span data....
Data transfer object holding data associated with a given span.
Interface for OTEL span samplers.