1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::borrow::Cow;

use sentry_core::protocol::{DebugMeta, Event};
use sentry_core::{ClientOptions, Integration};

/// The Sentry Debug Images Integration.
pub struct DebugImagesIntegration {
    /// A custom filter for which Events should get debug images.
    pub filter: Box<dyn Fn(&Event<'static>) -> bool + Send + Sync>,
}

impl DebugImagesIntegration {
    /// Creates a new Debug Images Integration.
    pub fn new() -> Self {
        Self::default()
    }
}

impl Default for DebugImagesIntegration {
    fn default() -> Self {
        Self {
            filter: Box::new(|_| true),
        }
    }
}

impl Integration for DebugImagesIntegration {
    fn name(&self) -> &'static str {
        "debug-images"
    }

    fn process_event(
        &self,
        mut event: Event<'static>,
        _opts: &ClientOptions,
    ) -> Option<Event<'static>> {
        lazy_static::lazy_static! {
            static ref DEBUG_META: DebugMeta = DebugMeta {
                images: crate::debug_images(),
                ..Default::default()
            };
        }

        if event.debug_meta.is_empty() && (self.filter)(&event) {
            event.debug_meta = Cow::Borrowed(&DEBUG_META);
        }

        Some(event)
    }
}