Skip to content

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Jun 27, 2025

This updates the initial set of attributes plus it imports the human-readable messages from the Sentry repository.

This updates the initial log attribues plus it imports the human-readable messages from the Sentry repository.
@armenzg armenzg self-assigned this Jun 27, 2025
@@ -6,28 +6,222 @@ use relay_event_schema::protocol::{
};
use relay_protocol::Annotated;

/// Mapping of NEL error types to their human-readable descriptions
/// Based on W3C Network Error Logging specification and Chromium-specific extensions
static NEL_CULPRITS: &[(&str, &str)] = &[
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

),
(
"http.error",
"The user agent successfully received a response, but it had a {} status code",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error takes a status code. See helper functions on handling this case.

@armenzg armenzg requested a review from Dav1dde June 27, 2025 16:24
@armenzg
Copy link
Member Author

armenzg commented Jun 27, 2025

bugbot run

Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick review, as I don't have more time right now.

@armenzg
Copy link
Member Author

armenzg commented Jun 27, 2025

bugbot run

Copy link
Member Author

@armenzg armenzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now in better shape. I still want to keep it as a draft.

let body = raw_report.body.into_value()?;

// Extract the error type string to avoid borrowing issues later
let error_type = body.ty.as_str().unwrap_or("unknown");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dav1dde What is a good strategy for when the reports may not have the data shape that we expect?
Should we return Sentry errors so we can investigate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a possibility, we can create an error and add the raw json as attachment, if we return an error from this function we just have to slightly change the caller side and you'd get that error.

See relay-server/src/services/processing/nel.rs

Comment on lines +282 to +310
use super::*;
use chrono::{DateTime, Utc};
use relay_event_schema::protocol::{BodyRaw, IpAddr, NetworkReportPhases};
use relay_protocol::{Annotated, SerializableAnnotated};

#[test]
fn test_create_message() {
// Test cases for create_message
struct CreateMessageCase {
error_type: &'static str,
status_code: Option<u16>,
expected: &'static str,
}

let message_cases = vec![
CreateMessageCase {
error_type: "dns.unreachable",
status_code: None,
expected: "DNS server is unreachable",
},
// This tests the status code replacement in the message
CreateMessageCase {
error_type: "http.error",
status_code: Some(404),
expected: "The user agent successfully received a response, but it had a 404 status code",
},
// Unknown errors do not get a human-friendly message, but the error type is preserved
CreateMessageCase {
error_type: "http.some_new_error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test test_create_message is well-structured, but consider adding edge cases like: empty error_type, very large status codes, and error_type with special characters. Also, test the case where status_code is provided for non-http.error types to ensure it's ignored correctly.

armenzg and others added 2 commits June 30, 2025 14:47
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
@getsentry getsentry deleted a comment from seer-by-sentry bot Jul 1, 2025
@armenzg armenzg force-pushed the nel/attributes/armenzg branch from aab68c4 to bcb7d10 Compare July 1, 2025 00:30
Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits and just Rust things 👍

All the docs I suggested changes on are to follow our little internal style guide, but that usually lines up in general with Rust best practices.

let body = raw_report.body.into_value()?;

// Extract the error type string to avoid borrowing issues later
let error_type = body.ty.as_str().unwrap_or("unknown");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a possibility, we can create an error and add the raw json as attachment, if we return an error from this function we just have to slightly change the caller side and you'd get that error.

See relay-server/src/services/processing/nel.rs

@armenzg armenzg requested a review from Dav1dde July 2, 2025 13:12
@armenzg armenzg enabled auto-merge July 3, 2025 12:25
@armenzg armenzg added this pull request to the merge queue Jul 3, 2025
Merged via the queue into master with commit 3b840f6 Jul 3, 2025
28 checks passed
@armenzg armenzg deleted the nel/attributes/armenzg branch July 3, 2025 12:49
armenzg added a commit to getsentry/sentry-conventions that referenced this pull request Jul 7, 2025
The changes are reflecting the discussions from [this document](https://www.notion.so/sentry/Browser-Reports-Attribute-21e8b10e4b5d8045a7fdc936c814ed70) and follow-up to [this Relay PR](getsentry/relay#4874).
armenzg added a commit to getsentry/sentry-conventions that referenced this pull request Jul 8, 2025
The changes are reflecting the discussions from [this document](https://www.notion.so/sentry/Browser-Reports-Attribute-21e8b10e4b5d8045a7fdc936c814ed70) and follow-up to [this Relay PR](getsentry/relay#4874).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants