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

Precision loss on time_unix_nano #2643

Closed
legendecas opened this issue Nov 25, 2021 · 2 comments · Fixed by #4062
Closed

Precision loss on time_unix_nano #2643

legendecas opened this issue Nov 25, 2021 · 2 comments · Fixed by #4062
Labels
bug Something isn't working never-stale priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Comments

@legendecas
Copy link
Member

legendecas commented Nov 25, 2021

What version of OpenTelemetry are you using?

v1.0.1

What version of Node are you using?

v14.18.1

Please provide the code you used to set up the OpenTelemetry SDK

const core = require('@opentelemetry/core');
const time = core.hrTime();
BigInt(core.hrTimeToNanoseconds(it)) === (BigInt(it[0]) + BigInt(it[1])); // false

core.hrTimeToNanoseconds is used in otlp exporters heavily, yet it is losing precisions on converting the value to nanoseconds. In otlp proto, time_unix_nano is defined to be fixed64 (i.e. integer with 64-bit size), and it is not representable in JavaScript numbers since it can only keep integer precision up to 2^54 -1.

What did you expect to see?

Provides a precision lossless conversion.

BigInt is a quite new language feature, we'd like to support as many browsers as possible. So it might be needed to represent int64 with third-party libraries. Also, the protobuf used in otlp exporters is bound to long.js, not sure if we should adopt it too.

@legendecas legendecas added the bug Something isn't working label Nov 25, 2021
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jan 31, 2022
@github-actions
Copy link

This issue was closed because it has been stale for 14 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working never-stale priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect
Projects
None yet
2 participants