summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php
blob: 4939a534116aeb1536003cec5f790ef201f7fc25 (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
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Metrics\MetricFactory;

use OpenTelemetry\SDK\Metrics\Data\Metric;
use OpenTelemetry\SDK\Metrics\MetricSourceInterface;

/**
 * @internal
 */
final class StreamMetricSource implements MetricSourceInterface
{
    private StreamMetricSourceProvider $provider;
    private int $reader;
    public function __construct(StreamMetricSourceProvider $provider, int $reader)
    {
        $this->provider = $provider;
        $this->reader = $reader;
    }

    public function collectionTimestamp(): int
    {
        return $this->provider->stream->timestamp();
    }

    public function collect(): Metric
    {
        return new Metric(
            $this->provider->instrumentationLibrary,
            $this->provider->resource,
            $this->provider->view->name,
            $this->provider->view->unit,
            $this->provider->view->description,
            $this->provider->stream->collect($this->reader),
        );
    }

    public function __destruct()
    {
        $this->provider->stream->unregister($this->reader);
    }
}