summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php')
-rw-r--r--vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php
new file mode 100644
index 000000000..4939a5341
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php
@@ -0,0 +1,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);
+ }
+}