opentelemetry-metrics-sdk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68999276f28a3e390725b6aebabc70a8846818e93fa9d6520f09c7992376bbbf
4
- data.tar.gz: 923878943342c36c768458f3f46fa34275faaf739a5257ca2d61a0bb46eccf5e
3
+ metadata.gz: ce5f31c7463140b3dee9d8209ded3c831964b3b6a0edff4837ec5308481d6fc3
4
+ data.tar.gz: 4c900df8d7e8eb7f8c783ad73c11136a0931d21f447c75daaa254a51653e8cb2
5
5
  SHA512:
6
- metadata.gz: 4f8a1bf6946c7a1bc27955369fa540dfb1ca481b393a5e1bfd4eb9c1957b0ed404fa6c9007dbc4af0314bcbcf8eb2dfdb5ef76d838d24a87ef635016c78238ea
7
- data.tar.gz: e487825f271ba21fe3f491cbd497635d22cd224c3ba370b6de93b22367deb2bce11867db0d60a7860152a3cf255152c922ba6c452c5f8c9a01d5563ee8733025
6
+ metadata.gz: 84702ecb88071fa4d30803cdc7e71656643eb73593a4783d98fef7d1350955d03c7a3b17e5a50a61e3cc10726eb25dd6e234170ea979347c42893fb0f18abd15
7
+ data.tar.gz: 6072767e9f13652e20e376971f8c327ef52b8ef2a8d0e149819574cc5caaae0addb4d313b583e894a3c71b06ddd2bf264c030bca58a41309a359895cc0b5f8eb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-metrics-sdk
2
2
 
3
+ ### v0.2.0 / 2024-08-27
4
+
5
+ * ADDED: Add basic periodic exporting metric_reader
6
+
3
7
  ### v0.1.0 / 2024-07-31
4
8
 
5
9
  Initial release.
@@ -23,7 +23,7 @@ module OpenTelemetry
23
23
  export(collect)
24
24
  end
25
25
 
26
- def export(metrics)
26
+ def export(metrics, timeout: nil)
27
27
  @mutex.synchronize do
28
28
  @metric_snapshots << metrics
29
29
  end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module SDK
9
+ module Metrics
10
+ module Export
11
+ # PeriodicMetricReader provides a minimal example implementation.
12
+ class PeriodicMetricReader < MetricReader
13
+ # Returns a new instance of the {PeriodicMetricReader}.
14
+ #
15
+ # @param [Integer] export_interval_millis the maximum interval time.
16
+ # Defaults to the value of the OTEL_METRIC_EXPORT_INTERVAL environment
17
+ # variable, if set, or 60_000.
18
+ # @param [Integer] export_timeout_millis the maximum export timeout.
19
+ # Defaults to the value of the OTEL_METRIC_EXPORT_TIMEOUT environment
20
+ # variable, if set, or 30_000.
21
+ # @param [MetricReader] exporter the (duck type) MetricReader to where the
22
+ # recorded metrics are pushed after certain interval.
23
+ #
24
+ # @return a new instance of the {PeriodicMetricReader}.
25
+ def initialize(export_interval_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_INTERVAL', 60_000)),
26
+ export_timeout_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_TIMEOUT', 30_000)),
27
+ exporter: nil)
28
+ super()
29
+
30
+ @export_interval = export_interval_millis / 1000.0
31
+ @export_timeout = export_timeout_millis / 1000.0
32
+ @exporter = exporter
33
+ @thread = nil
34
+ @continue = false
35
+ @mutex = Mutex.new
36
+ @export_mutex = Mutex.new
37
+
38
+ start
39
+ end
40
+
41
+ def shutdown(timeout: nil)
42
+ thread = lock do
43
+ @continue = false # force termination in next iteration
44
+ @thread
45
+ end
46
+ thread&.join(@export_interval)
47
+ @exporter.force_flush if @exporter.respond_to?(:force_flush)
48
+ @exporter.shutdown
49
+ Export::SUCCESS
50
+ rescue StandardError => e
51
+ OpenTelemetry.handle_error(exception: e, message: 'Fail to shutdown PeriodicMetricReader.')
52
+ Export::FAILURE
53
+ end
54
+
55
+ def force_flush(timeout: nil)
56
+ export(timeout: timeout)
57
+ Export::SUCCESS
58
+ rescue StandardError
59
+ Export::FAILURE
60
+ end
61
+
62
+ private
63
+
64
+ def start
65
+ @continue = true
66
+ if @exporter.nil?
67
+ OpenTelemetry.logger.warn 'Missing exporter in PeriodicMetricReader.'
68
+ elsif @thread&.alive?
69
+ OpenTelemetry.logger.warn 'PeriodicMetricReader is still running. Please shutdown it if it needs to restart.'
70
+ else
71
+ @thread = Thread.new do
72
+ while @continue
73
+ sleep(@export_interval)
74
+ begin
75
+ Timeout.timeout(@export_timeout) do
76
+ export(timeout: @export_timeout)
77
+ end
78
+ rescue Timeout::Error => e
79
+ OpenTelemetry.handle_error(exception: e, message: 'PeriodicMetricReader timeout.')
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ def export(timeout: nil)
87
+ @export_mutex.synchronize do
88
+ collected_metrics = collect
89
+ @exporter.export(collected_metrics, timeout: timeout || @export_timeout) unless collected_metrics.empty?
90
+ end
91
+ end
92
+
93
+ def lock(&block)
94
+ @mutex.synchronize(&block)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -26,3 +26,4 @@ end
26
26
  require 'opentelemetry/sdk/metrics/export/metric_reader'
27
27
  require 'opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter'
28
28
  require 'opentelemetry/sdk/metrics/export/console_metric_pull_exporter'
29
+ require 'opentelemetry/sdk/metrics/export/periodic_metric_reader'
@@ -28,7 +28,7 @@ module OpenTelemetry
28
28
 
29
29
  # @api private
30
30
  def add_metric_reader(metric_reader)
31
- @instrument_registry.each do |_n, instrument|
31
+ @instrument_registry.each_value do |instrument|
32
32
  instrument.register_with_new_metric_store(metric_reader.metric_store)
33
33
  end
34
34
  end
@@ -8,7 +8,7 @@ module OpenTelemetry
8
8
  module SDK
9
9
  module Metrics
10
10
  # Current OpenTelemetry metrics sdk version
11
- VERSION = '0.1.0'
11
+ VERSION = '0.2.0'
12
12
  end
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-metrics-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.51.0
145
+ version: '1.65'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.51.0
152
+ version: '1.65'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -215,6 +215,7 @@ files:
215
215
  - lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb
216
216
  - lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb
217
217
  - lib/opentelemetry/sdk/metrics/export/metric_reader.rb
218
+ - lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb
218
219
  - lib/opentelemetry/sdk/metrics/instrument.rb
219
220
  - lib/opentelemetry/sdk/metrics/instrument/counter.rb
220
221
  - lib/opentelemetry/sdk/metrics/instrument/histogram.rb
@@ -234,10 +235,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
234
235
  licenses:
235
236
  - Apache-2.0
236
237
  metadata:
237
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-sdk/v0.1.0/file.CHANGELOG.html
238
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-sdk/v0.2.0/file.CHANGELOG.html
238
239
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/metrics_sdk
239
240
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
240
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-sdk/v0.1.0
241
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-sdk/v0.2.0
241
242
  post_install_message:
242
243
  rdoc_options: []
243
244
  require_paths: