Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Normalize user reports during ingestion #903

Merged
merged 4 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
**Internal**:

- Extract crashpad annotations into contexts. ([#892](https://github.com/getsentry/relay/pull/892))
- Normalize user reports during ingestion and create empty fields. ([#903](https://github.com/getsentry/relay/pull/903))

## 20.12.1

Expand Down
30 changes: 23 additions & 7 deletions relay-server/src/actors/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ impl EventProcessor {
if changed {
let json_string = match serde_json::to_string(&session) {
Ok(json) => json,
Err(_) => return false,
Err(err) => {
relay_log::error!("failed to serialize session: {}", LogError(&err));
return false;
}
};

item.set_payload(ContentType::Json, json_string);
Expand All @@ -388,21 +391,34 @@ impl EventProcessor {
});
}

/// Validates all user report/feedback items in the envelope, if any.
/// Validates and normalizes all user report items in the envelope.
///
/// User feedback items are removed from the envelope if they contain invalid JSON or if the
/// JSON violates the schema (basic type validation).
/// JSON violates the schema (basic type validation). Otherwise, their normalized representation
/// is written back into the item.
fn process_user_reports(&self, state: &mut ProcessEnvelopeState) {
state.envelope.retain_items(|item| {
if item.ty() != ItemType::UserReport {
return true;
};

if let Err(error) = serde_json::from_slice::<UserReport>(&item.payload()) {
relay_log::error!("failed to store user report: {}", LogError(&error));
return false;
}
let report = match serde_json::from_slice::<UserReport>(&item.payload()) {
Ok(session) => session,
Err(error) => {
relay_log::error!("failed to store user report: {}", LogError(&error));
return false;
}
};

let json_string = match serde_json::to_string(&report) {
Ok(json) => json,
Err(err) => {
relay_log::error!("failed to serialize user report: {}", LogError(&err));
return false;
}
};

item.set_payload(ContentType::Json, json_string);
true
});
}
Expand Down