blob: df61d1aee57a2a22eaed0fa4389ad723e811499d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
declare(strict_types=1);
namespace OpenTelemetry\SDK\Trace\Sampler;
use OpenTelemetry\Context\ContextInterface;
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
use OpenTelemetry\SDK\Trace\SamplerInterface;
use OpenTelemetry\SDK\Trace\SamplingResult;
use OpenTelemetry\SDK\Trace\Span;
/**
* This implementation of the SamplerInterface always records.
* Example:
* ```
* use OpenTelemetry\Sdk\Trace\AlwaysOnSampler;
* $sampler = new AlwaysOnSampler();
* ```
*/
class AlwaysOnSampler implements SamplerInterface
{
/**
* Returns true because we always want to sample.
* {@inheritdoc}
*/
public function shouldSample(
ContextInterface $parentContext,
string $traceId,
string $spanName,
int $spanKind,
AttributesInterface $attributes,
array $links
): SamplingResult {
$parentSpan = Span::fromContext($parentContext);
$parentSpanContext = $parentSpan->getContext();
$traceState = $parentSpanContext->getTraceState();
return new SamplingResult(
SamplingResult::RECORD_AND_SAMPLE,
[],
$traceState
);
}
public function getDescription(): string
{
return 'AlwaysOnSampler';
}
}
|