Skip to content

Commit

Permalink
[Bug]: span tags of type int64 may lose precision #3958 PR No 2 (#4034)
Browse files Browse the repository at this point in the history
### Avoid value precision loss

Signed-off-by: Shubham Sawaiker
[[email protected]](mailto:[email protected])


  ###  Which problem is this PR solving?

-   Resolves:  #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 : #4023

Signed-off-by: Shubham Sawaiker <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
shubbham1215 and dependabot[bot] authored Nov 9, 2022
1 parent 252d198 commit 717c375
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions model/converter/json/fixtures/domain_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"vType": "FLOAT64",
"vFloat64": 72.5
},
{
"key": "javascript_limit",
"vType": "INT64",
"vInt64": 9223372036854775222
},
{
"key": "blob",
"vType": "BINARY",
Expand Down
5 changes: 5 additions & 0 deletions model/converter/json/fixtures/ui_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"type": "float64",
"value": 72.5
},
{
"key": "javascript_limit",
"type": "int64",
"value": "9223372036854775222"
},
{
"key": "blob",
"type": "binary",
Expand Down
9 changes: 9 additions & 0 deletions model/converter/json/from_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 717c375

Please sign in to comment.