opentelemetry-exporter-otlp-common 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d69383317fdedb9fd724b1213f6264766b63634dac6f43539a3a365197dcbaa4
|
|
4
|
+
data.tar.gz: 9d4f4162d6c206b631387971bfeae6b83abe1a527be2d4d1f1b2a4e76297f425
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e28c569f0acca4d775ac06402976594efc41bfca065e63af14aa3f214f49c889600ab693f7bf75e4b3f14c06a8975ff91af5c15a421eb4b084d97a1c3376ff4
|
|
7
|
+
data.tar.gz: 8673024f651c69fc9c1997bb397c7c61221137ad0b15c62ec6e434c087412e98cc9412ebd1768434d7dba372f888558f4551e4d316eef183ec9076ed7d6f3e67
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Release History: opentelemetry-exporter-otlp-common
|
|
2
2
|
|
|
3
|
+
### v0.4.0 / 2026-10-13
|
|
4
|
+
|
|
5
|
+
* ADDED: Use centralized otlp log encoding (#2434)
|
|
6
|
+
* ADDED: Use centralized otlp metric encoding (#2435)
|
|
7
|
+
|
|
8
|
+
### v0.3.0 / 2026-09-29
|
|
9
|
+
|
|
10
|
+
* ADDED: Move otlp exporter uri builder to common (#2240)
|
|
11
|
+
* FIXED: Normalize UTF-8 attribute strings (#2259)
|
|
12
|
+
|
|
3
13
|
### v0.2.0 / 2026-09-03
|
|
4
14
|
|
|
5
15
|
* ADDED: Support InstrumentationScope, and update OTLP proto to 0.18.0 (#1345)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright The OpenTelemetry Authors
|
|
4
|
+
#
|
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
|
|
7
|
+
require 'opentelemetry/common'
|
|
8
|
+
|
|
9
|
+
module OpenTelemetry
|
|
10
|
+
module Exporter
|
|
11
|
+
module OTLP
|
|
12
|
+
module Common
|
|
13
|
+
# Contains common utilities used by the otlp exporters
|
|
14
|
+
module Utilities
|
|
15
|
+
extend self
|
|
16
|
+
|
|
17
|
+
# Builds a url using the endpoint defined and if not present uses the configured sources
|
|
18
|
+
def build_uri(endpoint, path = '', primary_src = '', secondary_src = 'OTEL_EXPORTER_OTLP_ENDPOINT', default = 'http://localhost:4318/')
|
|
19
|
+
endpoint ||= ENV.fetch(primary_src, nil)
|
|
20
|
+
raise ArgumentError, "invalid url for OTLPExporter #{endpoint} set via #{primary_src}" unless endpoint.nil? || OpenTelemetry::Common::Utilities.valid_url?(endpoint)
|
|
21
|
+
|
|
22
|
+
if endpoint.nil?
|
|
23
|
+
endpoint = ENV.fetch(secondary_src, default)
|
|
24
|
+
raise ArgumentError, "invalid url for OTLPExporter #{endpoint} set via #{secondary_src}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint)
|
|
25
|
+
|
|
26
|
+
endpoint += '/' unless endpoint.end_with?('/')
|
|
27
|
+
URI.join(endpoint, path)
|
|
28
|
+
else
|
|
29
|
+
URI(endpoint)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -5,13 +5,19 @@
|
|
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
|
|
7
7
|
require 'opentelemetry'
|
|
8
|
+
require 'opentelemetry/common'
|
|
9
|
+
require 'opentelemetry/exporter/otlp/common/utilities'
|
|
8
10
|
require 'opentelemetry/exporter/otlp/common/version'
|
|
9
11
|
|
|
10
12
|
require 'google/rpc/status_pb'
|
|
11
13
|
|
|
12
14
|
require 'opentelemetry/proto/common/v1/common_pb'
|
|
13
15
|
require 'opentelemetry/proto/resource/v1/resource_pb'
|
|
16
|
+
require 'opentelemetry/proto/logs/v1/logs_pb'
|
|
17
|
+
require 'opentelemetry/proto/metrics/v1/metrics_pb'
|
|
14
18
|
require 'opentelemetry/proto/trace/v1/trace_pb'
|
|
19
|
+
require 'opentelemetry/proto/collector/logs/v1/logs_service_pb'
|
|
20
|
+
require 'opentelemetry/proto/collector/metrics/v1/metrics_service_pb'
|
|
15
21
|
require 'opentelemetry/proto/collector/trace/v1/trace_service_pb'
|
|
16
22
|
|
|
17
23
|
module OpenTelemetry
|
|
@@ -21,6 +27,100 @@ module OpenTelemetry
|
|
|
21
27
|
module Common # rubocop:disable Metrics/ModuleLength
|
|
22
28
|
extend self
|
|
23
29
|
|
|
30
|
+
# As encoded elsr (ExportLogsServiceRequest)
|
|
31
|
+
#
|
|
32
|
+
# @param [Enumerable<OpenTelemetry::SDK::Logs::LogRecordData>] log_record_data
|
|
33
|
+
# the list of recorded {OpenTelemetry::SDK::Logs::LogRecordData} structs to
|
|
34
|
+
# be encoded.
|
|
35
|
+
#
|
|
36
|
+
# @return [String] returns an encoded ELSR of the provided log record data
|
|
37
|
+
def as_encoded_elsr(log_record_data)
|
|
38
|
+
Opentelemetry::Proto::Collector::Logs::V1::ExportLogsServiceRequest.encode(as_elsr(log_record_data))
|
|
39
|
+
rescue StandardError => e
|
|
40
|
+
OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Common#as_encoded_elsr')
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# As elsr (ExportLogsServiceRequest)
|
|
45
|
+
#
|
|
46
|
+
# @param [Enumerable<OpenTelemetry::SDK::Logs::LogRecordData>] log_record_data
|
|
47
|
+
# the list of recorded {OpenTelemetry::SDK::Logs::LogRecordData} structs to
|
|
48
|
+
# be encoded.
|
|
49
|
+
#
|
|
50
|
+
# @return [Opentelemetry::Proto::Collector::Logs::V1::ExportLogsServiceRequest]
|
|
51
|
+
# returns an ELSR of the provided log record data
|
|
52
|
+
def as_elsr(log_record_data)
|
|
53
|
+
Opentelemetry::Proto::Collector::Logs::V1::ExportLogsServiceRequest.new(
|
|
54
|
+
resource_logs: log_record_data
|
|
55
|
+
.group_by(&:resource)
|
|
56
|
+
.map do |resource, log_record_datas|
|
|
57
|
+
Opentelemetry::Proto::Logs::V1::ResourceLogs.new(
|
|
58
|
+
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
|
|
59
|
+
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
|
|
60
|
+
),
|
|
61
|
+
scope_logs: log_record_datas
|
|
62
|
+
.group_by(&:instrumentation_scope)
|
|
63
|
+
.map do |il, lrd|
|
|
64
|
+
Opentelemetry::Proto::Logs::V1::ScopeLogs.new(
|
|
65
|
+
scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
|
|
66
|
+
name: il.name,
|
|
67
|
+
version: il.version
|
|
68
|
+
),
|
|
69
|
+
log_records: lrd.map { |lr| as_otlp_log_record(lr) }
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# As encoded emsr (ExportMetricsServiceRequest)
|
|
78
|
+
#
|
|
79
|
+
# @param [Enumerable<OpenTelemetry::SDK::Metrics::MetricData>] metrics_data the
|
|
80
|
+
# list of recorded {OpenTelemetry::SDK::Metrics::MetricData} structs to be
|
|
81
|
+
# encoded.
|
|
82
|
+
#
|
|
83
|
+
# @return [String] returns an encoded EMSR of the provided metrics data
|
|
84
|
+
def as_encoded_emsr(metrics_data)
|
|
85
|
+
Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.encode(as_emsr(metrics_data))
|
|
86
|
+
rescue StandardError => e
|
|
87
|
+
OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Common#as_encoded_emsr')
|
|
88
|
+
nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# As emsr (ExportMetricsServiceRequest)
|
|
92
|
+
#
|
|
93
|
+
# @param [Enumerable<OpenTelemetry::SDK::Metrics::MetricData>] metrics_data the
|
|
94
|
+
# list of recorded {OpenTelemetry::SDK::Metrics::MetricData} structs to be
|
|
95
|
+
# encoded.
|
|
96
|
+
#
|
|
97
|
+
# @return [Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest]
|
|
98
|
+
# returns an EMSR of the provided metrics data
|
|
99
|
+
def as_emsr(metrics_data)
|
|
100
|
+
Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.new(
|
|
101
|
+
resource_metrics: metrics_data
|
|
102
|
+
.group_by(&:resource)
|
|
103
|
+
.map do |resource, scope_metrics|
|
|
104
|
+
Opentelemetry::Proto::Metrics::V1::ResourceMetrics.new(
|
|
105
|
+
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
|
|
106
|
+
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
|
|
107
|
+
),
|
|
108
|
+
scope_metrics: scope_metrics
|
|
109
|
+
.group_by(&:instrumentation_scope)
|
|
110
|
+
.map do |instrumentation_scope, metrics|
|
|
111
|
+
Opentelemetry::Proto::Metrics::V1::ScopeMetrics.new(
|
|
112
|
+
scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
|
|
113
|
+
name: instrumentation_scope.name,
|
|
114
|
+
version: instrumentation_scope.version
|
|
115
|
+
),
|
|
116
|
+
metrics: metrics.map { |sd| as_otlp_metrics(sd) }
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
)
|
|
122
|
+
end
|
|
123
|
+
|
|
24
124
|
# As encoded etsr (ExportTraceServiceRequest)
|
|
25
125
|
#
|
|
26
126
|
# @param [Enumerable<OpenTelemetry::SDK::Trace::SpanData>] span_data the
|
|
@@ -70,7 +170,51 @@ module OpenTelemetry
|
|
|
70
170
|
|
|
71
171
|
private
|
|
72
172
|
|
|
73
|
-
def
|
|
173
|
+
def as_otlp_log_record(log_record_data)
|
|
174
|
+
Opentelemetry::Proto::Logs::V1::LogRecord.new(
|
|
175
|
+
time_unix_nano: log_record_data.timestamp,
|
|
176
|
+
observed_time_unix_nano: log_record_data.observed_timestamp,
|
|
177
|
+
severity_number: log_record_data.severity_number,
|
|
178
|
+
severity_text: log_record_data.severity_text,
|
|
179
|
+
body: as_otlp_any_value(log_record_data.body),
|
|
180
|
+
attributes: log_record_data.attributes&.map { |k, v| as_otlp_key_value(k, v) },
|
|
181
|
+
dropped_attributes_count: log_record_data.dropped_attributes_count,
|
|
182
|
+
event_name: log_record_data.event_name,
|
|
183
|
+
flags: log_record_data.trace_flags.instance_variable_get(:@flags),
|
|
184
|
+
trace_id: log_record_data.trace_id,
|
|
185
|
+
span_id: log_record_data.span_id
|
|
186
|
+
)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# metrics_pb has following type of data: :gauge, :sum, :histogram, :exponential_histogram, :summary
|
|
190
|
+
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram, :gauge -> :gauge
|
|
191
|
+
#
|
|
192
|
+
# metrics [MetricData]
|
|
193
|
+
def as_otlp_metrics(metrics)
|
|
194
|
+
case metrics.instrument_kind
|
|
195
|
+
when :observable_gauge, :gauge
|
|
196
|
+
Opentelemetry::Proto::Metrics::V1::Metric.new(
|
|
197
|
+
name: metrics.name,
|
|
198
|
+
description: metrics.description,
|
|
199
|
+
unit: metrics.unit,
|
|
200
|
+
gauge: gauge_data_point(metrics)
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
when :counter, :up_down_counter, :observable_counter, :observable_up_down_counter
|
|
204
|
+
Opentelemetry::Proto::Metrics::V1::Metric.new(
|
|
205
|
+
name: metrics.name,
|
|
206
|
+
description: metrics.description,
|
|
207
|
+
unit: metrics.unit,
|
|
208
|
+
sum: sum_data_point(metrics)
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
when :histogram
|
|
212
|
+
histogram_data_point(metrics)
|
|
213
|
+
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def as_otlp_span(span_data) # rubocop:disable Metrics/MethodLength
|
|
74
218
|
Opentelemetry::Proto::Trace::V1::Span.new(
|
|
75
219
|
trace_id: span_data.trace_id,
|
|
76
220
|
span_id: span_data.span_id,
|
|
@@ -96,8 +240,9 @@ module OpenTelemetry
|
|
|
96
240
|
trace_id: link.span_context.trace_id,
|
|
97
241
|
span_id: link.span_context.span_id,
|
|
98
242
|
trace_state: link.span_context.tracestate.to_s,
|
|
99
|
-
attributes: link.attributes&.map { |k, v| as_otlp_key_value(k, v) }
|
|
243
|
+
attributes: link.attributes&.map { |k, v| as_otlp_key_value(k, v) },
|
|
100
244
|
# TODO: track dropped_attributes_count in Span#trim_links
|
|
245
|
+
flags: build_span_flags(link.span_context.remote?, link.span_context.trace_flags)
|
|
101
246
|
)
|
|
102
247
|
end,
|
|
103
248
|
dropped_links_count: span_data.total_recorded_links - span_data.links&.size.to_i,
|
|
@@ -106,10 +251,179 @@ module OpenTelemetry
|
|
|
106
251
|
code: as_otlp_status_code(status.code),
|
|
107
252
|
message: status.description
|
|
108
253
|
)
|
|
254
|
+
end,
|
|
255
|
+
flags: build_span_flags(span_data.parent_span_is_remote, span_data.trace_flags)
|
|
256
|
+
)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Converts an SDK aggregation temporality symbol to its OTLP proto enum value.
|
|
260
|
+
def as_otlp_aggregation_temporality(type)
|
|
261
|
+
case type
|
|
262
|
+
when :delta then Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA
|
|
263
|
+
when :cumulative then Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE
|
|
264
|
+
else Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_UNSPECIFIED
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Builds an OTLP Metric for gauge data points.
|
|
269
|
+
def gauge_data_point(metrics)
|
|
270
|
+
Opentelemetry::Proto::Metrics::V1::Gauge.new(
|
|
271
|
+
data_points: metrics.data_points.map do |ndp|
|
|
272
|
+
number_data_point(ndp)
|
|
109
273
|
end
|
|
110
274
|
)
|
|
111
275
|
end
|
|
112
276
|
|
|
277
|
+
# Builds an OTLP Metric for either histogram or exponential histogram data points.
|
|
278
|
+
def histogram_data_point(metrics) # rubocop:disable Metrics/MethodLength
|
|
279
|
+
return if metrics.data_points.empty?
|
|
280
|
+
|
|
281
|
+
if metrics.data_points.first.instance_of?(OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogramDataPoint)
|
|
282
|
+
Opentelemetry::Proto::Metrics::V1::Metric.new(
|
|
283
|
+
name: metrics.name,
|
|
284
|
+
description: metrics.description,
|
|
285
|
+
unit: metrics.unit,
|
|
286
|
+
exponential_histogram: Opentelemetry::Proto::Metrics::V1::ExponentialHistogram.new(
|
|
287
|
+
aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality),
|
|
288
|
+
data_points: metrics.data_points.map do |ehdp|
|
|
289
|
+
exponential_histogram_data_point(ehdp)
|
|
290
|
+
end
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
elsif metrics.data_points.first.instance_of?(OpenTelemetry::SDK::Metrics::Aggregation::HistogramDataPoint)
|
|
294
|
+
Opentelemetry::Proto::Metrics::V1::Metric.new(
|
|
295
|
+
name: metrics.name,
|
|
296
|
+
description: metrics.description,
|
|
297
|
+
unit: metrics.unit,
|
|
298
|
+
histogram: Opentelemetry::Proto::Metrics::V1::Histogram.new(
|
|
299
|
+
aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality),
|
|
300
|
+
data_points: metrics.data_points.map do |hdp|
|
|
301
|
+
explicit_histogram_data_point(hdp)
|
|
302
|
+
end
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Converts a {HistogramDataPoint} to its OTLP proto representation.
|
|
309
|
+
def explicit_histogram_data_point(hdp)
|
|
310
|
+
Opentelemetry::Proto::Metrics::V1::HistogramDataPoint.new(
|
|
311
|
+
attributes: hdp.attributes.map { |k, v| as_otlp_key_value(k, v) },
|
|
312
|
+
start_time_unix_nano: hdp.start_time_unix_nano,
|
|
313
|
+
time_unix_nano: hdp.time_unix_nano,
|
|
314
|
+
count: hdp.count,
|
|
315
|
+
sum: hdp.sum,
|
|
316
|
+
bucket_counts: hdp.bucket_counts,
|
|
317
|
+
explicit_bounds: hdp.explicit_bounds,
|
|
318
|
+
exemplars: as_otlp_exemplars(hdp.exemplars),
|
|
319
|
+
min: hdp.min,
|
|
320
|
+
max: hdp.max,
|
|
321
|
+
flags: hdp.flags
|
|
322
|
+
)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# Converts an {ExponentialHistogramDataPoint} to its OTLP proto representation.
|
|
326
|
+
def exponential_histogram_data_point(ehdp)
|
|
327
|
+
Opentelemetry::Proto::Metrics::V1::ExponentialHistogramDataPoint.new(
|
|
328
|
+
attributes: ehdp.attributes.map { |k, v| as_otlp_key_value(k, v) },
|
|
329
|
+
start_time_unix_nano: ehdp.start_time_unix_nano,
|
|
330
|
+
time_unix_nano: ehdp.time_unix_nano,
|
|
331
|
+
count: ehdp.count,
|
|
332
|
+
sum: ehdp.sum,
|
|
333
|
+
scale: ehdp.scale,
|
|
334
|
+
zero_count: ehdp.zero_count,
|
|
335
|
+
positive: Opentelemetry::Proto::Metrics::V1::ExponentialHistogramDataPoint::Buckets.new(
|
|
336
|
+
offset: ehdp.positive.offset,
|
|
337
|
+
bucket_counts: ehdp.positive.counts
|
|
338
|
+
),
|
|
339
|
+
negative: Opentelemetry::Proto::Metrics::V1::ExponentialHistogramDataPoint::Buckets.new(
|
|
340
|
+
offset: ehdp.negative.offset,
|
|
341
|
+
bucket_counts: ehdp.negative.counts
|
|
342
|
+
),
|
|
343
|
+
flags: ehdp.flags,
|
|
344
|
+
exemplars: as_otlp_exemplars(ehdp.exemplars),
|
|
345
|
+
min: ehdp.min,
|
|
346
|
+
max: ehdp.max,
|
|
347
|
+
zero_threshold: ehdp.zero_threshold
|
|
348
|
+
)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# Builds an OTLP Metric for sum data points.
|
|
352
|
+
def sum_data_point(metrics)
|
|
353
|
+
Opentelemetry::Proto::Metrics::V1::Sum.new(
|
|
354
|
+
aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality),
|
|
355
|
+
data_points: metrics.data_points.map do |ndp|
|
|
356
|
+
number_data_point(ndp)
|
|
357
|
+
end,
|
|
358
|
+
is_monotonic: metrics.is_monotonic
|
|
359
|
+
)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# Converts a {NumberDataPoint} to its OTLP proto representation.
|
|
363
|
+
def number_data_point(ndp)
|
|
364
|
+
args = {
|
|
365
|
+
attributes: ndp.attributes.map { |k, v| as_otlp_key_value(k, v) },
|
|
366
|
+
start_time_unix_nano: ndp.start_time_unix_nano,
|
|
367
|
+
time_unix_nano: ndp.time_unix_nano,
|
|
368
|
+
exemplars: as_otlp_exemplars(ndp.exemplars),
|
|
369
|
+
flags: ndp.flags
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if ndp.value.is_a?(Float)
|
|
373
|
+
args[:as_double] = ndp.value
|
|
374
|
+
else
|
|
375
|
+
args[:as_int] = ndp.value
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(**args)
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# Converts a list of SDK exemplars to their OTLP proto representation.
|
|
382
|
+
def as_otlp_exemplars(exemplars)
|
|
383
|
+
exemplars&.map { |ex| as_otlp_exemplar(ex) } || []
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Converts a single SDK exemplar to its OTLP proto representation.
|
|
387
|
+
def as_otlp_exemplar(exemplar)
|
|
388
|
+
args = {
|
|
389
|
+
time_unix_nano: exemplar.time_unix_nano,
|
|
390
|
+
span_id: exemplar.span_id,
|
|
391
|
+
trace_id: exemplar.trace_id
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
# Add filtered_attributes if present
|
|
395
|
+
args[:filtered_attributes] = exemplar.filtered_attributes.map { |k, v| as_otlp_key_value(k, v) } if exemplar.filtered_attributes
|
|
396
|
+
|
|
397
|
+
# Set value based on type
|
|
398
|
+
if exemplar.value.is_a?(Float)
|
|
399
|
+
args[:as_double] = exemplar.value
|
|
400
|
+
else
|
|
401
|
+
args[:as_int] = exemplar.value
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
Opentelemetry::Proto::Metrics::V1::Exemplar.new(**args)
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# Builds span flags based on whether the parent span context is remote.
|
|
408
|
+
# This follows the OTLP specification for span flags.
|
|
409
|
+
def build_span_flags(parent_span_is_remote, base_flags)
|
|
410
|
+
# Extract integer value from TraceFlags object if needed
|
|
411
|
+
# Derive the low 8-bit W3C trace flags using the public API.
|
|
412
|
+
base_flags_int =
|
|
413
|
+
if base_flags.sampled?
|
|
414
|
+
1
|
|
415
|
+
else
|
|
416
|
+
0
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
has_remote_mask = Opentelemetry::Proto::Trace::V1::SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK
|
|
420
|
+
is_remote_mask = Opentelemetry::Proto::Trace::V1::SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK
|
|
421
|
+
|
|
422
|
+
flags = base_flags_int | has_remote_mask
|
|
423
|
+
flags |= is_remote_mask if parent_span_is_remote
|
|
424
|
+
flags
|
|
425
|
+
end
|
|
426
|
+
|
|
113
427
|
def as_otlp_status_code(code)
|
|
114
428
|
case code
|
|
115
429
|
when OpenTelemetry::Trace::Status::OK then Opentelemetry::Proto::Trace::V1::Status::StatusCode::STATUS_CODE_OK
|
|
@@ -130,9 +444,10 @@ module OpenTelemetry
|
|
|
130
444
|
end
|
|
131
445
|
|
|
132
446
|
def as_otlp_key_value(key, value)
|
|
447
|
+
key = OpenTelemetry::Common::Utilities.utf8_encode(key, placeholder: 'Encoding Error')
|
|
133
448
|
Opentelemetry::Proto::Common::V1::KeyValue.new(key: key, value: as_otlp_any_value(value))
|
|
134
449
|
rescue Encoding::UndefinedConversionError => e
|
|
135
|
-
encoded_value = value.encode('UTF-8', invalid: :replace, undef: :replace, replace: '�')
|
|
450
|
+
encoded_value = value.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '�')
|
|
136
451
|
OpenTelemetry.handle_error(exception: e, message: "encoding error for key #{key} and value #{encoded_value}")
|
|
137
452
|
Opentelemetry::Proto::Common::V1::KeyValue.new(key: key, value: as_otlp_any_value('Encoding Error'))
|
|
138
453
|
end
|
|
@@ -141,7 +456,7 @@ module OpenTelemetry
|
|
|
141
456
|
result = Opentelemetry::Proto::Common::V1::AnyValue.new
|
|
142
457
|
case value
|
|
143
458
|
when String
|
|
144
|
-
result.string_value = value
|
|
459
|
+
result.string_value = OpenTelemetry::Common::Utilities.utf8_encode(value, placeholder: value)
|
|
145
460
|
when Integer
|
|
146
461
|
result.int_value = value
|
|
147
462
|
when Float
|
|
@@ -151,6 +466,9 @@ module OpenTelemetry
|
|
|
151
466
|
when Array
|
|
152
467
|
values = value.map { |element| as_otlp_any_value(element) }
|
|
153
468
|
result.array_value = Opentelemetry::Proto::Common::V1::ArrayValue.new(values: values)
|
|
469
|
+
when Hash
|
|
470
|
+
values = value.map { |k, v| as_otlp_key_value(k, v) }
|
|
471
|
+
result.kvlist_value = Opentelemetry::Proto::Common::V1::KeyValueList.new(values: values)
|
|
154
472
|
end
|
|
155
473
|
result
|
|
156
474
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentelemetry-exporter-otlp-common
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
@@ -51,6 +51,20 @@ dependencies:
|
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '1.1'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: opentelemetry-common
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0.20'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0.20'
|
|
54
68
|
description: Common functionality for the OTLP exporters
|
|
55
69
|
email:
|
|
56
70
|
- cncf-opentelemetry-contributors@lists.cncf.io
|
|
@@ -64,6 +78,7 @@ files:
|
|
|
64
78
|
- README.md
|
|
65
79
|
- lib/opentelemetry-exporter-otlp-common.rb
|
|
66
80
|
- lib/opentelemetry/exporter/otlp/common.rb
|
|
81
|
+
- lib/opentelemetry/exporter/otlp/common/utilities.rb
|
|
67
82
|
- lib/opentelemetry/exporter/otlp/common/version.rb
|
|
68
83
|
- lib/opentelemetry/proto/collector/logs/v1/logs_service_pb.rb
|
|
69
84
|
- lib/opentelemetry/proto/collector/metrics/v1/metrics_service_pb.rb
|
|
@@ -77,10 +92,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
|
77
92
|
licenses:
|
|
78
93
|
- Apache-2.0
|
|
79
94
|
metadata:
|
|
80
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-exporter-otlp-common/0.
|
|
81
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-exporter-otlp-common/v0.
|
|
95
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-exporter-otlp-common/0.4.0/file/CHANGELOG.md
|
|
96
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-exporter-otlp-common/v0.4.0/exporter/otlp-common
|
|
82
97
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
|
83
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-exporter-otlp-common/0.
|
|
98
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-exporter-otlp-common/0.4.0
|
|
84
99
|
rdoc_options: []
|
|
85
100
|
require_paths:
|
|
86
101
|
- lib
|
|
@@ -95,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
95
110
|
- !ruby/object:Gem::Version
|
|
96
111
|
version: '0'
|
|
97
112
|
requirements: []
|
|
98
|
-
rubygems_version: 4.0.
|
|
113
|
+
rubygems_version: 4.0.20
|
|
99
114
|
specification_version: 4
|
|
100
115
|
summary: Common functionality for the OTLP exporters
|
|
101
116
|
test_files: []
|