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