To ensure compatibility with the OpenTelemetry backend, follow these rules when emitting metrics:
Floating-point numbers
Do not mix floating-point and non-floating-point numbers for the same metric name. If a metric uses floating-point values, ensure all subsequent calls for that metric name also use floating-point types.
// Correct: consistent use of f64
info!(monotonic_counter.foo = 1_f64);
info!(monotonic_counter.foo = 1.1);
Integers
Positive and negative integers can be mixed freely. The instrumentation assumes i64 by default. If you provide a u64, the layer will attempt to cast it to i64 internally.
Warning: If a u64 is provided that exceeds i64::MAX, the metric will be dropped and an error will be printed to stderr to prevent overflow issues in the OpenTelemetry backend.
// The subscriber receives an i64
info!(counter.baz = 1);
info!(counter.baz = -1);
// The subscriber receives a u64, but casts it to i64 internally
info!(counter.baz = 1_u64);
// This will be dropped and print an error to stderr:
info!(counter.baz = (i64::MAX as u64) + 1);