From 717c3756c8c3c8f3e4ba077744e6b7838cfaf9a9 Mon Sep 17 00:00:00 2001 From: Shubham Sawaiker <39957099+shubbham1215@users.noreply.github.com> Date: Thu, 10 Nov 2022 02:08:08 +0530 Subject: [PATCH] [Bug]: span tags of type int64 may lose precision #3958 PR No 2 (#4034) ### Avoid value precision loss Signed-off-by: Shubham Sawaiker [sawaikershubham@gmail.com](mailto:sawaikershubham@gmail.com) ### Which problem is this PR solving? - Resolves: https://github.com/jaegertracing/jaeger/issues/3958 ### Short description of the changes - avoid display value precision loss in case of value overflow Number.MAX_VALUE Previous PR was made from main branch because of which CI jobs were failing. First PR link : https://github.com/jaegertracing/jaeger/pull/4023 Signed-off-by: Shubham Sawaiker Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- model/converter/json/fixtures/domain_01.json | 5 +++++ model/converter/json/fixtures/ui_01.json | 5 +++++ model/converter/json/from_domain.go | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/model/converter/json/fixtures/domain_01.json b/model/converter/json/fixtures/domain_01.json index 581d3ffc23c..0193d43f842 100644 --- a/model/converter/json/fixtures/domain_01.json +++ b/model/converter/json/fixtures/domain_01.json @@ -57,6 +57,11 @@ "vType": "FLOAT64", "vFloat64": 72.5 }, + { + "key": "javascript_limit", + "vType": "INT64", + "vInt64": 9223372036854775222 + }, { "key": "blob", "vType": "BINARY", diff --git a/model/converter/json/fixtures/ui_01.json b/model/converter/json/fixtures/ui_01.json index 06a61ddb6c7..7cc55463d36 100644 --- a/model/converter/json/fixtures/ui_01.json +++ b/model/converter/json/fixtures/ui_01.json @@ -62,6 +62,11 @@ "type": "float64", "value": 72.5 }, + { + "key": "javascript_limit", + "type": "int64", + "value": "9223372036854775222" + }, { "key": "blob", "type": "binary", diff --git a/model/converter/json/from_domain.go b/model/converter/json/from_domain.go index 2786b63a6bc..26c2e47d6f0 100644 --- a/model/converter/json/from_domain.go +++ b/model/converter/json/from_domain.go @@ -16,12 +16,18 @@ package json import ( + "fmt" "strings" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/model/json" ) +const ( + jsMaxSafeInteger = int64(1)<<53 - 1 + jsMinSafeInteger = -jsMaxSafeInteger +) + // FromDomain converts model.Trace into json.Trace format. // It assumes that the domain model is valid, namely that all enums // have valid values, so that it does not need to check for errors. @@ -122,6 +128,9 @@ func (fd fromDomain) convertKeyValues(keyValues model.KeyValues) []json.KeyValue value = kv.Bool() case model.Int64Type: value = kv.Int64() + if kv.Int64() > jsMaxSafeInteger || kv.Int64() < jsMinSafeInteger { + value = fmt.Sprintf("%d", value) + } case model.Float64Type: value = kv.Float64() case model.BinaryType: