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

Conversation

percygrunwald
Copy link
Contributor

@percygrunwald percygrunwald commented Nov 22, 2024

It's currently possible to have a Counter with a Float value, but this fails to export because the NumberDataPoint is always assumed to be an Integer for the purposes of ProtoBuf encoding. The .proto for a NumberDataPoint allows for a float value in the as_double key, so there should be no reason that we should not be able to support Float Counters.

This commit adds support for Float values in NumberDataPoint, which in turn adds support for Float Counters. I also updated the documentation in the structs for both NumberDataPoint.value and HistogramDataPoint.sum to match the expected type based on the .proto.

Adds a test to confirm that the metrics_exporter handles both Integer and Float values for a NumberDataPoint.

Noting the error message output without this change:

irb(main):004:0> E, [2024-11-22T11:29:40.853932 #1] ERROR -- : OpenTelemetry error: unexpected error in OTLP::MetricsExporter#encode - Non-integral floating point value assigned to integer field 'as_int' (given Float). - /home/percy/co/manage/vendor/bundle/ruby/3.1.0/gems/opentelemetry-exporter-otlp-metrics-0.2.0/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb:287:in `initialize'

It's currently possible to have a `Counter` with a `Float` value, but
this fails to export because the `NumberDataPoint` is always assumed to
be an `Integer` for the purposes of ProtoBuf encoding. The `.proto` for
a `NumberDataPoint` allows for a float value in the `as_double` key, so
there should be no reason that we should not be able to support `Float`
`Counter`s.

This commit adds support for `Float` values in `NumberDataPoint`, which
in turn adds support for `Float` `Counter`s. I also updated the
documentation in the structs for both `NumberDataPoint.value` and
`HistogramDataPoint.sum` to match the expected type based on the
`.proto`.

Adds a test to confirm that the metrics_exporter handles both `Integer`
and `Float` values for a `NumberDataPoint`.
Copy link

linux-foundation-easycla bot commented Nov 22, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@arielvalentin arielvalentin changed the title Fix: handle float value in NumberDataPoint fix: handle float value in NumberDataPoint Nov 22, 2024
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @percygrunwald! This is a great catch.

…m_data_point.rb

Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com>
@kaylareopelle kaylareopelle merged commit f338d01 into open-telemetry:main Dec 2, 2024
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants