Skip to content

feat(nel): Update attributes & human readable messages - #4874

Merged
armenzg merged 33 commits into
masterfrom
nel/attributes/armenzg
Jul 3, 2025
Merged

feat(nel): Update attributes & human readable messages#4874
armenzg merged 33 commits into
masterfrom
nel/attributes/armenzg

Conversation

@armenzg

@armenzg armenzg commented Jun 27, 2025

Copy link
Copy Markdown
Member

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

/// 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
Copy Markdown
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
Copy Markdown
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.

Comment thread relay-event-normalization/src/normalize/nel.rs
@armenzg
armenzg requested a review from Dav1dde June 27, 2025 16:24
@armenzg

armenzg commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

bugbot run

@Dav1dde Dav1dde left a comment

Copy link
Copy Markdown
Member

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.

Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
@armenzg

armenzg commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

bugbot run

@armenzg armenzg left a comment

Copy link
Copy Markdown
Member Author

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.

Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs
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
Copy Markdown
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
Copy Markdown
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 thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
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
Copy Markdown
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.

Comment thread relay-event-normalization/src/normalize/nel.rs
Comment thread tests/integration/test_nel.py
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

@Dav1dde Dav1dde left a comment

Copy link
Copy Markdown
Member

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.

Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
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
Copy Markdown
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 thread relay-event-normalization/src/normalize/nel.rs
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread relay-event-normalization/src/normalize/nel.rs Outdated
Comment thread tests/integration/test_nel.py
Comment thread CHANGELOG.md Outdated
@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
@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
armenzg added a commit to getsentry/sentry-conventions that referenced this pull request Jul 8, 2025
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