relay_server/services/processor/
attachment.rs

1//! Attachments processor code.
2#[cfg(feature = "processing")]
3use {
4    crate::{
5        envelope::AttachmentType,
6        managed::TypedEnvelope,
7        services::processor::{ErrorGroup, EventFullyNormalized},
8        utils,
9    },
10    relay_event_schema::protocol::{Event, Metrics},
11    relay_protocol::Annotated,
12};
13
14/// Adds processing placeholders for special attachments.
15///
16/// If special attachments are present in the envelope, this adds placeholder payloads to the
17/// event. This indicates to the pipeline that the event needs special processing.
18///
19/// If the event payload was empty before, it is created.
20#[cfg(feature = "processing")]
21pub fn create_placeholders(
22    managed_envelope: &mut TypedEnvelope<ErrorGroup>,
23    event: &mut Annotated<Event>,
24    metrics: &mut Metrics,
25) -> Option<EventFullyNormalized> {
26    let envelope = managed_envelope.envelope();
27    let minidump_attachment =
28        envelope.get_item_by(|item| item.attachment_type() == Some(&AttachmentType::Minidump));
29    let apple_crash_report_attachment = envelope
30        .get_item_by(|item| item.attachment_type() == Some(&AttachmentType::AppleCrashReport));
31
32    if let Some(item) = minidump_attachment {
33        let event = event.get_or_insert_with(Event::default);
34        metrics.bytes_ingested_event_minidump = Annotated::new(item.len() as u64);
35        utils::process_minidump(event, &item.payload());
36        return Some(EventFullyNormalized(false));
37    } else if let Some(item) = apple_crash_report_attachment {
38        let event = event.get_or_insert_with(Event::default);
39        metrics.bytes_ingested_event_applecrashreport = Annotated::new(item.len() as u64);
40        utils::process_apple_crash_report(event, &item.payload());
41        return Some(EventFullyNormalized(false));
42    }
43
44    None
45}