Class: OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader
- Inherits:
-
MetricReader
- Object
- MetricReader
- OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader
- Defined in:
- lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb
Overview
PeriodicMetricReader provides a minimal example implementation.
Instance Attribute Summary
Attributes inherited from MetricReader
Instance Method Summary collapse
- #force_flush(timeout: nil) ⇒ Object
-
#initialize(export_interval_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_INTERVAL', 60_000)), export_timeout_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_TIMEOUT', 30_000)), exporter: nil) ⇒ Object
constructor
Returns a new instance of the PeriodicMetricReader.
- #shutdown(timeout: nil) ⇒ Object
Methods inherited from MetricReader
Constructor Details
#initialize(export_interval_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_INTERVAL', 60_000)), export_timeout_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_TIMEOUT', 30_000)), exporter: nil) ⇒ Object
Returns a new instance of the OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 25 def initialize(export_interval_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_INTERVAL', 60_000)), export_timeout_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_TIMEOUT', 30_000)), exporter: nil) super() @export_interval = export_interval_millis / 1000.0 @export_timeout = export_timeout_millis / 1000.0 @exporter = exporter @thread = nil @continue = false @mutex = Mutex.new @export_mutex = Mutex.new start end |
Instance Method Details
#force_flush(timeout: nil) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 55 def force_flush(timeout: nil) export(timeout: timeout) Export::SUCCESS rescue StandardError Export::FAILURE end |
#shutdown(timeout: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 41 def shutdown(timeout: nil) thread = lock do @continue = false # force termination in next iteration @thread end thread&.join(@export_interval) @exporter.force_flush if @exporter.respond_to?(:force_flush) @exporter.shutdown Export::SUCCESS rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: 'Fail to shutdown PeriodicMetricReader.') Export::FAILURE end |