diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa8c2d65b..3ede9c1fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Extract op and description while converting opentelemetry spans to sentry spans. ([#3287](https://github.com/getsentry/relay/pull/3287)) - Drop `event_id` and `remote_addr` from all outcomes. ([#3319](https://github.com/getsentry/relay/pull/3319)) - Support for AI token metrics ([#3250](https://github.com/getsentry/relay/pull/3250)) +- Accept integers in `event.user.username`. ([#3328](https://github.com/getsentry/relay/pull/3328)) **Internal**: diff --git a/relay-event-normalization/src/event.rs b/relay-event-normalization/src/event.rs index d292503723..0d2c9bcaab 100644 --- a/relay-event-normalization/src/event.rs +++ b/relay-event-normalization/src/event.rs @@ -2973,7 +2973,7 @@ mod tests { Annotated::new(map) }); assert_eq!(user.other, Object::new()); - assert_eq!(user.username, Annotated::new("john".to_string())); + assert_eq!(user.username, Annotated::new("john".to_string().into())); assert_eq!(user.sentry_user, Annotated::new("id:123456".to_string())); } diff --git a/relay-event-normalization/src/normalize/utils.rs b/relay-event-normalization/src/normalize/utils.rs index cc7a86c772..aabc4bb9b5 100644 --- a/relay-event-normalization/src/normalize/utils.rs +++ b/relay-event-normalization/src/normalize/utils.rs @@ -205,7 +205,7 @@ mod tests { // has to be changed. Though it is probably not a good idea! let user = User { id: Annotated::new("ident".to_owned().into()), - username: Annotated::new("username".to_owned()), + username: Annotated::new("username".to_owned().into()), email: Annotated::new("email".to_owned()), ip_address: Annotated::new("127.0.0.1".parse().unwrap()), ..User::default() @@ -214,7 +214,7 @@ mod tests { assert_eq!(get_event_user_tag(&user).unwrap(), "id:ident"); let user = User { - username: Annotated::new("username".to_owned()), + username: Annotated::new("username".to_owned().into()), email: Annotated::new("email".to_owned()), ip_address: Annotated::new("127.0.0.1".parse().unwrap()), ..User::default() diff --git a/relay-event-schema/src/protocol/user.rs b/relay-event-schema/src/protocol/user.rs index 6738f827ba..88263fa9c0 100644 --- a/relay-event-schema/src/protocol/user.rs +++ b/relay-event-schema/src/protocol/user.rs @@ -62,7 +62,7 @@ pub struct User { /// Username of the user. #[metastructure(pii = "true", max_chars = 128, skip_serialization = "empty")] - pub username: Annotated, + pub username: Annotated, /// Human readable name of the user. #[metastructure(pii = "true", max_chars = 128, skip_serialization = "empty")] @@ -163,7 +163,7 @@ mod tests { email: Annotated::new("mail@example.org".to_string()), ip_address: Annotated::new(IpAddr::auto()), name: Annotated::new("John Doe".to_string()), - username: Annotated::new("john_doe".to_string()), + username: Annotated::new(LenientString("john_doe".to_owned())), geo: Annotated::empty(), segment: Annotated::new("vip".to_string()), data: { @@ -202,6 +202,19 @@ mod tests { assert_eq!(output, user.to_json().unwrap()); } + #[test] + fn test_user_lenient_username() { + let input = r#"{"username":42}"#; + let output = r#"{"username":"42"}"#; + let user = Annotated::new(User { + username: Annotated::new("42".to_string().into()), + ..User::default() + }); + + assert_eq!(user, Annotated::from_json(input).unwrap()); + assert_eq!(output, user.to_json().unwrap()); + } + #[test] fn test_user_invalid_id() { let json = r#"{"id":[]}"#; diff --git a/relay-pii/src/snapshots/relay_pii__processor__tests__scrub_original_value.snap b/relay-pii/src/snapshots/relay_pii__processor__tests__scrub_original_value.snap index 8a4421213b..9fad3a9cb8 100644 --- a/relay-pii/src/snapshots/relay_pii__processor__tests__scrub_original_value.snap +++ b/relay-pii/src/snapshots/relay_pii__processor__tests__scrub_original_value.snap @@ -47,7 +47,9 @@ Event { ), }, username: Annotated( - "hey man [ip]", + LenientString( + "hey man [ip]", + ), Meta { remarks: [ Remark { diff --git a/relay-server/src/utils/unreal.rs b/relay-server/src/utils/unreal.rs index ac6e62283c..03990a62dc 100644 --- a/relay-server/src/utils/unreal.rs +++ b/relay-server/src/utils/unreal.rs @@ -196,7 +196,7 @@ fn merge_unreal_context(event: &mut Event, context: Unreal4Context) { .user .get_or_insert_with(User::default) .username - .set_value(Some(username)); + .set_value(Some(username.into())); } let contexts = event.contexts.get_or_insert_with(Contexts::default);