Skip to content

Commit

Permalink
Merge branch 'master' into feat/ingest-sample-rates
Browse files Browse the repository at this point in the history
* master:
  fix(server): Normalize user reports during ingestion (#903)
  • Loading branch information
jan-auer committed Jan 13, 2021
2 parents 34bea03 + a2af6ec commit 9e779e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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 @@ -385,7 +385,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 @@ -395,21 +398,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

0 comments on commit 9e779e6

Please sign in to comment.