Skip to content

Commit 333b14e

Browse files
authored
fix(logs): stringify u64 attributes greater than i64::MAX (#846)
1 parent 0957716 commit 333b14e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- fix(logs): stringify u64 attributes greater than `i64::MAX` (#846) by @lcian
8+
39
## 0.40.0
410

511
### Breaking changes

sentry-types/src/protocol/v7.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,10 @@ impl Serialize for LogAttribute {
22172217
if let Some(i) = n.as_i64() {
22182218
state.serialize_field("value", &i)?;
22192219
state.serialize_field("type", "integer")?;
2220+
} else if let Some(u) = n.as_u64() {
2221+
// Converting to a f64 could lead to precision loss
2222+
state.serialize_field("value", &u.to_string())?;
2223+
state.serialize_field("type", "string")?;
22202224
} else if let Some(f) = n.as_f64() {
22212225
state.serialize_field("value", &f)?;
22222226
state.serialize_field("type", "double")?;

sentry-types/tests/test_protocol_v7.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,12 @@ mod test_logs {
15361536
(3.1.into(), r#"{"value":3.1,"type":"double"}"#),
15371537
("lol".into(), r#"{"value":"lol","type":"string"}"#),
15381538
(false.into(), r#"{"value":false,"type":"boolean"}"#),
1539-
// Special case
1539+
// Special cases
15401540
(Value::Null.into(), r#"{"value":"null","type":"string"}"#),
1541+
(
1542+
(u64::MAX - 1).into(),
1543+
r#"{"value":"18446744073709551614","type":"string"}"#,
1544+
),
15411545
// Unsupported types (for now)
15421546
(
15431547
json!(r#"[1,2,3,4]"#).into(),

0 commit comments

Comments
 (0)