opentelemetry-exporter-otlp-metrics 0.1.0 → 0.2.1

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: '07981d7af4b22bf63c108726564e1228d26a38ebfe4d82060d5f0cd6b202d484'
4
- data.tar.gz: '086c5ecfb4473308fad530a5394e863b62406cb3fb37348315b159fcb307197a'
3
+ metadata.gz: eb4e38af9863bebfb371938af848fe59a23ba93fdd43ab1481e0564683a777b1
4
+ data.tar.gz: f395bd341c56a3dcf1c98ece2b062ce53f91d69e3cf49fc68ae7fccc5e19ec1e
5
5
  SHA512:
6
- metadata.gz: 112e0f8a4739e9833a12e35a509cee5564e9386400083990e68f5b45b1a23bb508a0b5d8e27e6419d55b70e82ae547f1c92fe5fe0a76c8c60291f8b42676dd77
7
- data.tar.gz: 9dff4b4213c48a870f91b14664a9397df34bd34e51957243b4a07720cb790c2900cc984562ec2034fa55cc5e50e12007d333e04272fa804694ef04399b7b9d01
6
+ metadata.gz: cc477ced1291504d8c497dea4168a77b8aff5c440cfa204425a4da2f99563a6d4d17e6438d3f08b538e383f826225733b98d1c4f57ba4dd2678827d2b514052e
7
+ data.tar.gz: a08feee08447528c752dacf8eb9853737a63fa6baa4e744a13851c254bd5c989d7c23ed48273a99c07dccad515859eb982b304544018a4eaed8c00db70820d5e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-exporter-otlp-metrics
2
2
 
3
+ ### v0.2.1 / 2024-12-04
4
+
5
+ * FIXED: Handle float value in NumberDataPoint
6
+
7
+ ### v0.2.0 / 2024-11-20
8
+
9
+ * ADDED: Add basic metrics view
10
+ * FIXED: Remove Metrics OTLP exporter `Util#measure_request_duration` and duplicate files
11
+ * FIXED: Add mTLS for metrics exporter
12
+
3
13
  ### v0.1.0 / 2024-08-27
4
14
 
5
15
  Initial release.
data/README.md CHANGED
@@ -18,6 +18,41 @@ Generally, *libraries* that produce telemetry data should avoid depending direct
18
18
 
19
19
  This gem supports the [v0.20.0 release][otel-proto-release] of OTLP.
20
20
 
21
+ ## Prerequisite
22
+
23
+ The exporter-oltp-metrics depends on two gems that have not been officially released: opentelemetry-metrics-sdk and opentelemetry-metrics-api.
24
+
25
+ Within the .gemspec file, these gems are not listed as dependencies. However, for users who need utilize this metrics exporter, they must first install and load these two gems before they can use the exporter.
26
+
27
+ To facilitate this, there are couple recommended approaches:
28
+
29
+ ### 1. Download the source code
30
+
31
+ 1. Download the [opentelemetry-ruby](https://github.com/open-telemetry/opentelemetry-ruby).
32
+ 2. Navigate to subfolder, then build the [metrics_sdk](https://github.com/open-telemetry/opentelemetry-ruby/tree/main/metrics_sdk) and [metrics_api](https://github.com/open-telemetry/opentelemetry-ruby/tree/main/metrics_api).
33
+ 3. Execute `gem build *.gemspec`.
34
+ 4. Lastly, install the built gem into the system.
35
+
36
+ ### 2. Using `path:` option in Gemfile with downloaded source code
37
+
38
+ git clone [opentelemetry-ruby](https://github.com/open-telemetry/opentelemetry-ruby) first, then use Gemfile
39
+
40
+ ```ruby
41
+ # Gemfile
42
+ source 'https://rubygems.org'
43
+ gem 'opentelemetry-metrics-api', path: "opentelemetry-ruby/metrics_api"
44
+ gem 'opentelemetry-metrics-sdk', path: "opentelemetry-ruby/metrics_sdk"
45
+ ```
46
+
47
+ ### 3. Using `git:` option in Gemfile
48
+
49
+ ```ruby
50
+ # Gemfile
51
+ source 'https://rubygems.org'
52
+ gem 'opentelemetry-metrics-api', git: "https://github.com/open-telemetry/opentelemetry-ruby", glob: 'metrics_api/*.gemspec'
53
+ gem 'opentelemetry-metrics-sdk', git: "https://github.com/open-telemetry/opentelemetry-ruby", glob: 'metrics_sdk/*.gemspec'
54
+ ```
55
+
21
56
  ## How do I get started?
22
57
 
23
58
  Install the gem using:
@@ -67,15 +102,15 @@ The collector exporter can be configured explicitly in code, or via environment
67
102
  | ------------------- | -------------------------------------------- | ----------------------------------- |
68
103
  | `endpoint:` | `OTEL_EXPORTER_OTLP_ENDPOINT` | `"http://localhost:4318/v1/metrics"` |
69
104
  | `certificate_file: `| `OTEL_EXPORTER_OTLP_CERTIFICATE` | |
105
+ | `client_certificate_file: `| `OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE` | |
106
+ | `client_key_file:` | `OTEL_EXPORTER_OTLP_CLIENT_KEY` | |
70
107
  | `headers:` | `OTEL_EXPORTER_OTLP_HEADERS` | |
71
108
  | `compression:` | `OTEL_EXPORTER_OTLP_COMPRESSION` | `"gzip"` |
72
109
  | `timeout:` | `OTEL_EXPORTER_OTLP_TIMEOUT` | `10` |
73
- | `ssl_verify_mode:` | `OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER` or | `OpenSSL::SSL:VERIFY_PEER` |
74
- | | `OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE` | |
110
+ | `ssl_verify_mode:` | `OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER` or `OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE` | `OpenSSL::SSL:VERIFY_PEER` |
75
111
 
76
112
  `ssl_verify_mode:` parameter values should be flags for server certificate verification: `OpenSSL::SSL:VERIFY_PEER` and `OpenSSL::SSL:VERIFY_NONE` are acceptable. These values can also be set using the appropriately named environment variables as shown where `VERIFY_PEER` will take precedence over `VERIFY_NONE`. Please see [the Net::HTTP docs](https://ruby-doc.org/stdlib-2.7.6/libdoc/net/http/rdoc/Net/HTTP.html#verify_mode) for more information about these flags.
77
113
 
78
-
79
114
  ## How can I get involved?
80
115
 
81
116
  The `opentelemetry-exporter-otlp-metrics` gem source is [on github][repo-github], along with related gems including `opentelemetry-metrics-sdk`.
@@ -26,7 +26,7 @@ module OpenTelemetry
26
26
  module OTLP
27
27
  module Metrics
28
28
  # An OpenTelemetry metrics exporter that sends metrics over HTTP as Protobuf encoded OTLP ExportMetricsServiceRequest.
29
- class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader # rubocop:disable Metrics/ClassLength
29
+ class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader
30
30
  include Util
31
31
 
32
32
  attr_reader :metric_snapshots
@@ -47,6 +47,8 @@ module OpenTelemetry
47
47
 
48
48
  def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/metrics'),
49
49
  certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'),
50
+ client_certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE'),
51
+ client_key_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY', 'OTEL_EXPORTER_OTLP_CLIENT_KEY'),
50
52
  ssl_verify_mode: MetricsExporter.ssl_verify_mode,
51
53
  headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS', default: {}),
52
54
  compression: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION', default: 'gzip'),
@@ -63,7 +65,7 @@ module OpenTelemetry
63
65
  URI(endpoint)
64
66
  end
65
67
 
66
- @http = http_connection(@uri, ssl_verify_mode, certificate_file)
68
+ @http = http_connection(@uri, ssl_verify_mode, certificate_file, client_certificate_file, client_key_file)
67
69
 
68
70
  @path = @uri.path
69
71
  @headers = prepare_headers(headers)
@@ -87,7 +89,7 @@ module OpenTelemetry
87
89
  end
88
90
  end
89
91
 
90
- def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
92
+ def send_bytes(bytes, timeout:)
91
93
  return FAILURE if bytes.nil?
92
94
 
93
95
  request = Net::HTTP::Post.new(@path)
@@ -115,7 +117,7 @@ module OpenTelemetry
115
117
  @http.read_timeout = remaining_timeout
116
118
  @http.write_timeout = remaining_timeout
117
119
  @http.start unless @http.started?
118
- response = measure_request_duration { @http.request(request) }
120
+ response = @http.request(request)
119
121
  case response
120
122
  when Net::HTTPOK
121
123
  response.body # Read and discard body
@@ -181,7 +183,7 @@ module OpenTelemetry
181
183
  @http.write_timeout = @timeout
182
184
  end
183
185
 
184
- def encode(metrics_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
186
+ def encode(metrics_data)
185
187
  Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.encode(
186
188
  Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.new(
187
189
  resource_metrics: metrics_data
@@ -215,7 +217,7 @@ module OpenTelemetry
215
217
  # current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram
216
218
  #
217
219
  # metrics [MetricData]
218
- def as_otlp_metrics(metrics) # rubocop:disable Metrics/MethodLength
220
+ def as_otlp_metrics(metrics)
219
221
  case metrics.instrument_kind
220
222
  when :observable_gauge
221
223
  Opentelemetry::Proto::Metrics::V1::Metric.new(
@@ -282,13 +284,20 @@ module OpenTelemetry
282
284
  end
283
285
 
284
286
  def number_data_point(ndp)
285
- Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(
287
+ args = {
286
288
  attributes: ndp.attributes.map { |k, v| as_otlp_key_value(k, v) },
287
- as_int: ndp.value,
288
289
  start_time_unix_nano: ndp.start_time_unix_nano,
289
290
  time_unix_nano: ndp.time_unix_nano,
290
291
  exemplars: ndp.exemplars # exemplars not implemented yet from metrics sdk
291
- )
292
+ }
293
+
294
+ if ndp.value.is_a?(Float)
295
+ args[:as_double] = ndp.value
296
+ else
297
+ args[:as_int] = ndp.value
298
+ end
299
+
300
+ Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(**args)
292
301
  end
293
302
 
294
303
  # may not need this
@@ -15,11 +15,13 @@ module OpenTelemetry
15
15
  ERROR_MESSAGE_INVALID_HEADERS = 'headers must be a String with comma-separated URL Encoded UTF-8 k=v pairs or a Hash'
16
16
  DEFAULT_USER_AGENT = "OTel-OTLP-MetricsExporter-Ruby/#{OpenTelemetry::Exporter::OTLP::Metrics::VERSION} Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}/#{RUBY_ENGINE_VERSION})".freeze
17
17
 
18
- def http_connection(uri, ssl_verify_mode, certificate_file)
18
+ def http_connection(uri, ssl_verify_mode, certificate_file, client_certificate_file, client_key_file)
19
19
  http = Net::HTTP.new(uri.host, uri.port)
20
20
  http.use_ssl = uri.scheme == 'https'
21
21
  http.verify_mode = ssl_verify_mode
22
22
  http.ca_file = certificate_file unless certificate_file.nil?
23
+ http.cert = OpenSSL::X509::Certificate.new(File.read(client_certificate_file)) unless client_certificate_file.nil?
24
+ http.key = OpenSSL::PKey::RSA.new(File.read(client_key_file)) unless client_key_file.nil?
23
25
  http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT
24
26
  http
25
27
  end
@@ -67,16 +69,6 @@ module OpenTelemetry
67
69
  headers
68
70
  end
69
71
 
70
- def measure_request_duration
71
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
72
- begin
73
- yield
74
- ensure
75
- stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
76
- 1000.0 * (stop - start)
77
- end
78
- end
79
-
80
72
  def parse_headers(raw)
81
73
  entries = raw.split(',')
82
74
  raise ArgumentError, ERROR_MESSAGE_INVALID_HEADERS if entries.empty?
@@ -97,7 +89,7 @@ module OpenTelemetry
97
89
  end
98
90
  end
99
91
 
100
- def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
92
+ def backoff?(retry_count:, reason:, retry_after: nil)
101
93
  return false if retry_count > RETRY_COUNT
102
94
 
103
95
  sleep_interval = nil
@@ -9,7 +9,7 @@ module OpenTelemetry
9
9
  module OTLP
10
10
  module Metrics
11
11
  ## Current OpenTelemetry OTLP exporter version
12
- VERSION = '0.1.0'
12
+ VERSION = '0.2.1'
13
13
  end
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-exporter-otlp-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
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-08-28 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: googleapis-common-protos-types
@@ -324,10 +324,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
324
324
  licenses:
325
325
  - Apache-2.0
326
326
  metadata:
327
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-exporter-otlp-metrics/v0.1.0/file.CHANGELOG.html
327
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-exporter-otlp-metrics/v0.2.1/file.CHANGELOG.html
328
328
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/exporter/otlp-metrics
329
329
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
330
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-exporter-otlp-metrics/v0.1.0
330
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-exporter-otlp-metrics/v0.2.1
331
331
  post_install_message:
332
332
  rdoc_options: []
333
333
  require_paths: