summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Metrics/Exemplar/FilteredReservoir.php
blob: 0e4f243571e9538d4b61908a2f1fa724eb506035 (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
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Metrics\Exemplar;

use OpenTelemetry\Context\ContextInterface;
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;

/**
 * The exemplar spec is not yet stable, and can change at any time.
 * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#exemplar
 */
final class FilteredReservoir implements ExemplarReservoirInterface
{
    private ExemplarReservoirInterface $reservoir;
    private ExemplarFilterInterface $filter;

    public function __construct(ExemplarReservoirInterface $reservoir, ExemplarFilterInterface $filter)
    {
        $this->reservoir = $reservoir;
        $this->filter = $filter;
    }

    public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void
    {
        if ($this->filter->accepts($value, $attributes, $context, $timestamp)) {
            $this->reservoir->offer($index, $value, $attributes, $context, $timestamp);
        }
    }

    public function collect(array $dataPointAttributes): array
    {
        return $this->reservoir->collect($dataPointAttributes);
    }
}