# frozen_string_literal: true # Copyright The OpenTelemetry Authors # # SPDX-License-Identifier: Apache-2.0 module OpenTelemetry module SDK module Metrics module State # @api private # # The MetricStream class provides SDK internal functionality that is not a part of the # public API. class MetricStream attr_reader :name, :description, :unit, :instrument_kind, :instrumentation_scope, :data_points def initialize( name, description, unit, instrument_kind, meter_provider, instrumentation_scope, aggregation ) @name = name @description = description @unit = unit @instrument_kind = instrument_kind @meter_provider = meter_provider @instrumentation_scope = instrumentation_scope @aggregation = aggregation @mutex = Mutex.new end def collect(start_time, end_time) @mutex.synchronize do MetricData.new( @name, @description, @unit, @instrument_kind, @meter_provider.resource, @instrumentation_scope, @aggregation.collect(start_time, end_time), @aggregation.aggregation_temporality, start_time, end_time ) end end def update(value, attributes) @mutex.synchronize { @aggregation.update(value, attributes) } end def to_s instrument_info = String.new instrument_info << "name=#{@name}" instrument_info << " description=#{@description}" if @description instrument_info << " unit=#{@unit}" if @unit @data_points.map do |attributes, value| metric_stream_string = String.new metric_stream_string << instrument_info metric_stream_string << " attributes=#{attributes}" if attributes metric_stream_string << " #{value}" metric_stream_string end.join("\n") end end end end end end