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
-
#alive? ⇒ Boolean
Check both @thread and @continue object to determine if current PeriodicMetricReader is still alive.
-
#force_flush(timeout: nil) ⇒ Integer
Export all metrics to the configured
Exporter
that have not yet been exported. -
#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) ⇒ Integer
Shuts the @thread down and set @continue to false; it will block until the shutdown thread is finished.
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 40 |
# 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 @condition = ConditionVariable.new @export_mutex = Mutex.new start end |
Instance Method Details
#alive? ⇒ Boolean
Check both @thread and @continue object to determine if current PeriodicMetricReader is still alive. If one of them is true/alive, then PeriodicMetricReader is determined as alive
84 85 86 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 84 def alive? @continue || @thread.alive? end |
#force_flush(timeout: nil) ⇒ Integer
Export all metrics to the configured Exporter
that have not yet been exported.
This method should only be called in cases where it is absolutely necessary, such as when using some FaaS providers that may suspend the process after an invocation, but before the PeriodicMetricReader
exports the completed metrics.
74 75 76 77 78 79 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 74 def force_flush(timeout: nil) export(timeout:) Export::SUCCESS rescue StandardError Export::FAILURE end |
#shutdown(timeout: nil) ⇒ Integer
Shuts the @thread down and set @continue to false; it will block until the shutdown thread is finished.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 48 def shutdown(timeout: nil) thread = lock do @continue = false # force termination in next iteration @condition.signal @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 |