relay_event_schema/protocol/contexts/
nel.rs

1use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, Value};
2
3use crate::processor::ProcessValue;
4use crate::protocol::{IpAddr, NetworkReportPhases};
5
6/// Contains NEL report information.
7///
8/// Network Error Logging (NEL) is a browser feature that allows reporting of failed network
9/// requests from the client side. See the following resources for more information:
10///
11/// - [W3C Editor's Draft](https://w3c.github.io/network-error-logging/)
12/// - [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Network_Error_Logging)
13#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
14pub struct NelContext {
15    /// If request failed, the type of its network error. If request succeeded, "ok".
16    pub error_type: Annotated<String>,
17    /// Server IP where the requests was sent to.
18    #[metastructure(pii = "maybe")]
19    pub server_ip: Annotated<IpAddr>,
20    /// The number of milliseconds between the start of the resource fetch and when it was aborted by the user agent.
21    pub elapsed_time: Annotated<u64>,
22    /// If request failed, the phase of its network error. If request succeeded, "application".
23    pub phase: Annotated<NetworkReportPhases>,
24    /// The sampling rate.
25    pub sampling_fraction: Annotated<f64>,
26    /// For forward compatibility.
27    #[metastructure(additional_properties, pii = "maybe")]
28    pub other: Object<Value>,
29}
30
31impl super::DefaultContext for NelContext {
32    fn default_key() -> &'static str {
33        "nel"
34    }
35
36    fn from_context(context: super::Context) -> Option<Self> {
37        match context {
38            super::Context::Nel(c) => Some(*c),
39            _ => None,
40        }
41    }
42
43    fn cast(context: &super::Context) -> Option<&Self> {
44        match context {
45            super::Context::Nel(c) => Some(c),
46            _ => None,
47        }
48    }
49
50    fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
51        match context {
52            super::Context::Nel(c) => Some(c),
53            _ => None,
54        }
55    }
56
57    fn into_context(self) -> super::Context {
58        super::Context::Nel(Box::new(self))
59    }
60}