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
-
#after_fork ⇒ Object
Restarts the periodic export thread after a process fork.
-
#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
Exporterthat 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, aggregation_cardinality_limit: 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
#collect, #register_meter_provider
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, aggregation_cardinality_limit: 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 41 |
# 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, aggregation_cardinality_limit: nil) super(aggregation_cardinality_limit: aggregation_cardinality_limit) @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
#after_fork ⇒ Object
Restarts the periodic export thread after a process fork.
83 84 85 86 87 88 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 83 def after_fork @exporter.reset if @exporter.respond_to?(:reset) collect # move past previously reported metrics from parent process @thread = nil start end |
#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
93 94 95 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 93 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.
75 76 77 78 79 80 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 75 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb', line 49 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 |