Sha256: d8dcf9ef5506c98124d8b44afe5134341f70f873c8268671d3443e200a0bc2fb

Contents?: true

Size: 1011 Bytes

Versions: 4

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module SDK
    module Metrics
      module Export
        # The InMemoryMetricPullExporter behaves as a Metric Reader and Exporter.
        # To be used for testing purposes, not production.
        class InMemoryMetricPullExporter < MetricReader
          attr_reader :metric_snapshots

          def initialize
            super
            @metric_snapshots = []
            @mutex = Mutex.new
          end

          def pull
            export(collect)
          end

          def export(metrics, timeout: nil)
            @mutex.synchronize do
              @metric_snapshots.concat(Array(metrics))
            end
            SUCCESS
          end

          def reset
            @mutex.synchronize do
              @metric_snapshots.clear
            end
          end

          def shutdown
            SUCCESS
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opentelemetry-metrics-sdk-0.5.0 lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb
opentelemetry-metrics-sdk-0.4.1 lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb
opentelemetry-metrics-sdk-0.4.0 lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb
opentelemetry-metrics-sdk-0.3.0 lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb