sentry_debug_images/
integration.rs1use std::borrow::Cow;
2use std::sync::LazyLock;
3
4use sentry_core::protocol::{DebugMeta, Event};
5use sentry_core::{ClientOptions, Integration};
6
7static DEBUG_META: LazyLock<DebugMeta> = LazyLock::new(|| DebugMeta {
8 images: crate::debug_images(),
9 ..Default::default()
10});
11
12pub struct DebugImagesIntegration {
14 filter: Box<dyn Fn(&Event<'_>) -> bool + Send + Sync>,
15}
16
17impl DebugImagesIntegration {
18 pub fn new() -> Self {
20 Self::default()
21 }
22
23 #[must_use]
27 pub fn filter<F>(mut self, filter: F) -> Self
28 where
29 F: Fn(&Event<'_>) -> bool + Send + Sync + 'static,
30 {
31 self.filter = Box::new(filter);
32 self
33 }
34}
35
36impl Default for DebugImagesIntegration {
37 fn default() -> Self {
38 LazyLock::force(&DEBUG_META);
39 Self {
40 filter: Box::new(|_| true),
41 }
42 }
43}
44
45impl std::fmt::Debug for DebugImagesIntegration {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 #[derive(Debug)]
48 struct Filter;
49 f.debug_struct("DebugImagesIntegration")
50 .field("filter", &Filter)
51 .finish()
52 }
53}
54
55impl Integration for DebugImagesIntegration {
56 fn name(&self) -> &'static str {
57 "debug-images"
58 }
59
60 fn process_event(
61 &self,
62 mut event: Event<'static>,
63 _opts: &ClientOptions,
64 ) -> Option<Event<'static>> {
65 if event.debug_meta.is_empty() && (self.filter)(&event) {
66 event.debug_meta = Cow::Borrowed(&DEBUG_META);
67 }
68
69 Some(event)
70 }
71}