From da07ee0b2e70e3eef9920d8e85a72d1c6149ce32 Mon Sep 17 00:00:00 2001 From: rsergeychik Date: Mon, 22 Jul 2024 18:18:14 +0700 Subject: [PATCH] fix float32 zapcore field converter --- otelzap/conv.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/otelzap/conv.go b/otelzap/conv.go index fd88fc0..41406ba 100644 --- a/otelzap/conv.go +++ b/otelzap/conv.go @@ -50,9 +50,12 @@ func appendField(kvs []log.KeyValue, f zapcore.Field) []log.KeyValue { zapcore.UintptrType: return append(kvs, log.Int64(f.Key, f.Integer)) - case zapcore.Float32Type, zapcore.Float64Type: + case zapcore.Float64Type: num := math.Float64frombits(uint64(f.Integer)) return append(kvs, log.Float64(f.Key, num)) + case zapcore.Float32Type: + num := math.Float32frombits(uint32(f.Integer)) + return append(kvs, log.Float64(f.Key, float64(num))) case zapcore.Complex64Type: str := strconv.FormatComplex(complex128(f.Interface.(complex64)), 'E', -1, 64)