TraceIdRatioBasedSampler
in package
implements
SamplerInterface
uses
LogsMessagesTrait
This implementation of the SamplerInterface records with given probability.
Example:
use OpenTelemetry\API\Trace\TraceIdRatioBasedSampler;
$sampler = new TraceIdRatioBasedSampler(0.01);
Table of Contents
Interfaces
- SamplerInterface
- This interface is used to organize sampling logic.
Properties
- $probability : float
- $tv : string
- $warnedAsChild : bool
Methods
- __construct() : mixed
- getDescription() : string
- Returns the sampler name or short description with the configuration.
- shouldSample() : SamplingResult
- Warns once per instance when used as a child sampler.
- logDebug() : void
- logError() : void
- logInfo() : void
- logNotice() : void
- logWarning() : void
- doLog() : void
- Logging is best effort: a failing log writer (for example an error handler that throws on `trigger_error`) must not break the code that is being observed.
- shouldLog() : bool
Properties
$probability read-only
private
float
$probability
$tv read-only
private
string
$tv
$warnedAsChild
private
bool
$warnedAsChild
= false
Methods
__construct()
public
__construct(float $probability[, int<1, 14> $precision = 4 ]) : mixed
Parameters
- $probability : float
-
Probability float value between 0.0 and 1.0.
- $precision : int<1, 14> = 4
-
threshold precision in hexadecimal digits
getDescription()
Returns the sampler name or short description with the configuration.
public
getDescription() : string
This may be displayed on debug pages or in the logs. Example: "TraceIdRatioBased{0.000100}"
Attributes
- #[Override]
Return values
stringshouldSample()
Warns once per instance when used as a child sampler.
public
shouldSample(ContextInterface $parentContext, string $traceId, string $spanName, int $spanKind, AttributesInterface $attributes, array<string|int, mixed> $links) : SamplingResult
Parameters
- $parentContext : ContextInterface
-
Context with parent Span. The Span's SpanContext may be invalid to indicate a root span.
- $traceId : string
-
TraceId of the Span to be created. It can be different from the TraceId in the SpanContext. Typically in situations when the Span to be created starts a new Trace.
- $spanName : string
-
Name of the Span to be created.
- $spanKind : int
-
Span kind.
- $attributes : AttributesInterface
-
Initial set of Attributes for the Span being constructed.
- $links : array<string|int, mixed>
-
Collection of links that will be associated with the Span to be created. Typically, useful for batch operations. @see https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#links-between-spans
Tags
Attributes
- #[Override]
Return values
SamplingResultlogDebug()
protected
static logDebug(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
logError()
protected
static logError(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
logInfo()
protected
static logInfo(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
logNotice()
protected
static logNotice(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
logWarning()
protected
static logWarning(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
doLog()
Logging is best effort: a failing log writer (for example an error handler that throws on `trigger_error`) must not break the code that is being observed.
private
static doLog(string $level, string $message, array<string|int, mixed> $context) : void
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed>
shouldLog()
private
static shouldLog(string $level) : bool
Parameters
- $level : string