Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle float value in NumberDataPoint #1767

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,20 @@ def histogram_data_point(hdp)
end

def number_data_point(ndp)
Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(
args = {
attributes: ndp.attributes.map { |k, v| as_otlp_key_value(k, v) },
as_int: ndp.value,
start_time_unix_nano: ndp.start_time_unix_nano,
time_unix_nano: ndp.time_unix_nano,
exemplars: ndp.exemplars # exemplars not implemented yet from metrics sdk
)
}

if ndp.value.is_a?(Float)
args[:as_double] = ndp.value
else
args[:as_int] = ndp.value
end

Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(**args)
end

# may not need this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@
OpenTelemetry.logger = logger
end

it 'is able to encode NumberDataPoint with Integer or Float value' do
stub_request(:post, 'http://localhost:4318/v1/metrics').to_return(status: 200)

[1, 0.1234].each do |value|
ndp = OpenTelemetry::SDK::Metrics::Aggregation::NumberDataPoint.new
ndp.attributes = { 'a' => 'b' }
ndp.start_time_unix_nano = 0
ndp.time_unix_nano = 0
ndp.value = value

metrics_data = create_metrics_data(data_points: [ndp])

result = exporter.export([metrics_data])
_(result).must_equal(METRICS_SUCCESS)
end
end

it 'logs rpc.Status on bad request' do
log_stream = StringIO.new
logger = OpenTelemetry.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Aggregation
:start_time_unix_nano, # Integer nanoseconds since Epoch
:time_unix_nano, # Integer nanoseconds since Epoch
:count, # Integer count is the number of values in the population. Must be non-negative.
:sum, # Integer sum of the values in the population. If count is zero then this field then this field must be zero
:sum, # Float sum of the values in the population. If count is zero then this field then this field must be zero
percygrunwald marked this conversation as resolved.
Show resolved Hide resolved
:bucket_counts, # optional Array[Integer] field contains the count values of histogram for each bucket.
:explicit_bounds, # Array[Float] specifies buckets with explicitly defined bounds for values.
:exemplars, # optional List of exemplars collected from measurements that were used to form the data point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Aggregation
NumberDataPoint = Struct.new(:attributes, # Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
:start_time_unix_nano, # Integer nanoseconds since Epoch
:time_unix_nano, # Integer nanoseconds since Epoch
:value, # Integer
:value, # Numeric
:exemplars) # optional List of exemplars collected from measurements that were used to form the data point
end
end
Expand Down
Loading