relay_event_schema/protocol/contexts/
reprocessing.rs

1use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, Value};
2
3use crate::processor::ProcessValue;
4
5/// Auxilliary data that Sentry attaches for reprocessed events.
6// This context is explicitly typed out such that we can disable datascrubbing for it, and for
7// documentation. We need to disble datascrubbing because it can retract information from the
8// context that is necessary for basic operation, or worse, mangle it such that the Snuba consumer
9// crashes: https://github.com/getsentry/snuba/pull/1896/
10#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
11pub struct ReprocessingContext {
12    /// The issue ID that this event originally belonged to.
13    #[metastructure(pii = "false")]
14    pub original_issue_id: Annotated<u64>,
15
16    #[metastructure(pii = "false")]
17    pub original_primary_hash: Annotated<String>,
18
19    /// Additional arbitrary fields for forwards compatibility.
20    #[metastructure(additional_properties, retain = true, pii = "false")]
21    pub other: Object<Value>,
22}
23
24impl super::DefaultContext for ReprocessingContext {
25    fn default_key() -> &'static str {
26        "reprocessing"
27    }
28
29    fn from_context(context: super::Context) -> Option<Self> {
30        match context {
31            super::Context::Reprocessing(c) => Some(*c),
32            _ => None,
33        }
34    }
35
36    fn cast(context: &super::Context) -> Option<&Self> {
37        match context {
38            super::Context::Reprocessing(c) => Some(c),
39            _ => None,
40        }
41    }
42
43    fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
44        match context {
45            super::Context::Reprocessing(c) => Some(c),
46            _ => None,
47        }
48    }
49
50    fn into_context(self) -> super::Context {
51        super::Context::Reprocessing(Box::new(self))
52    }
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58    use crate::protocol::Context;
59
60    #[test]
61    fn test_reprocessing_context_roundtrip() {
62        let json = r#"{
63  "original_issue_id": 123,
64  "original_primary_hash": "9f3ee8ff49e6ca0a2bee80d76fee8f0c",
65  "random": "stuff",
66  "type": "reprocessing"
67}"#;
68        let context = Annotated::new(Context::Reprocessing(Box::new(ReprocessingContext {
69            original_issue_id: Annotated::new(123),
70            original_primary_hash: Annotated::new("9f3ee8ff49e6ca0a2bee80d76fee8f0c".to_string()),
71            other: {
72                let mut map = Object::new();
73                map.insert(
74                    "random".to_string(),
75                    Annotated::new(Value::String("stuff".to_string())),
76                );
77                map
78            },
79        })));
80
81        assert_eq!(context, Annotated::from_json(json).unwrap());
82        assert_eq!(json, context.to_json_pretty().unwrap());
83    }
84}