pub struct ContextWatchdog { /* private fields */ }Expand description
Watches for context changes by diffing consecutive snapshots.
Implementations§
Source§impl ContextWatchdog
impl ContextWatchdog
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/dump_context.rs (line 34)
10fn main() {
11 let mut merger = ContextMerger::new().with_defaults("Incident Review", "Payment API");
12 merger.push(ContextContribution::new(
13 "trace_stream",
14 vec![ContextElement {
15 id: "trace:payment-api:slow-span".into(),
16 label: Some("payment-api span exceeded latency budget".into()),
17 description: None,
18 element_type: "trace_span".into(),
19 value: Some("duration_ms=1840".into()),
20 bounds: None,
21 state: ElementState::default(),
22 parent_id: None,
23 actions: Vec::new(),
24 confidence: 0.0,
25 source: ContextSource::External,
26 content_role: ContentRole::Content,
27 properties: Default::default(),
28 }],
29 ));
30
31 let ctx = merger.build();
32 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
33
34 let mut watchdog = ContextWatchdog::new();
35 assert!(watchdog.tick(&ctx, true).is_empty());
36
37 let mut changed = ctx.clone();
38 changed.elements.push(ContextElement {
39 id: "log:payment-api:retry".into(),
40 label: Some("payment-api retried card processor request".into()),
41 description: None,
42 element_type: "log_event".into(),
43 value: Some("attempt=2".into()),
44 bounds: None,
45 state: ElementState::default(),
46 parent_id: None,
47 actions: Vec::new(),
48 confidence: 0.0,
49 source: ContextSource::External,
50 content_role: ContentRole::Content,
51 properties: Default::default(),
52 });
53 let events = watchdog.tick(&changed, true);
54 println!("watchdog events: {events:?}");
55}Sourcepub fn tick(
&mut self,
context: &ScreenContext,
network_idle: bool,
) -> Vec<CelEvent>
pub fn tick( &mut self, context: &ScreenContext, network_idle: bool, ) -> Vec<CelEvent>
Compare the current context against the previous snapshot and emit events.
context: The current screen context.
network_idle: Whether the network monitor reports idle state.
Returns a list of events that occurred since the last tick.
Examples found in repository?
examples/dump_context.rs (line 35)
10fn main() {
11 let mut merger = ContextMerger::new().with_defaults("Incident Review", "Payment API");
12 merger.push(ContextContribution::new(
13 "trace_stream",
14 vec![ContextElement {
15 id: "trace:payment-api:slow-span".into(),
16 label: Some("payment-api span exceeded latency budget".into()),
17 description: None,
18 element_type: "trace_span".into(),
19 value: Some("duration_ms=1840".into()),
20 bounds: None,
21 state: ElementState::default(),
22 parent_id: None,
23 actions: Vec::new(),
24 confidence: 0.0,
25 source: ContextSource::External,
26 content_role: ContentRole::Content,
27 properties: Default::default(),
28 }],
29 ));
30
31 let ctx = merger.build();
32 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
33
34 let mut watchdog = ContextWatchdog::new();
35 assert!(watchdog.tick(&ctx, true).is_empty());
36
37 let mut changed = ctx.clone();
38 changed.elements.push(ContextElement {
39 id: "log:payment-api:retry".into(),
40 label: Some("payment-api retried card processor request".into()),
41 description: None,
42 element_type: "log_event".into(),
43 value: Some("attempt=2".into()),
44 bounds: None,
45 state: ElementState::default(),
46 parent_id: None,
47 actions: Vec::new(),
48 confidence: 0.0,
49 source: ContextSource::External,
50 content_role: ContentRole::Content,
51 properties: Default::default(),
52 });
53 let events = watchdog.tick(&changed, true);
54 println!("watchdog events: {events:?}");
55}Sourcepub fn merge_events(&self, events: Vec<CelEvent>) -> Vec<CelEvent>
pub fn merge_events(&self, events: Vec<CelEvent>) -> Vec<CelEvent>
Merge source-specific push events that have already been normalized to CEL events.
Sourcepub fn merge_ax_events<T>(&self, _events: Vec<T>) -> Vec<CelEvent>
pub fn merge_ax_events<T>(&self, _events: Vec<T>) -> Vec<CelEvent>
Compatibility shim for runtimes that still receive source-specific
accessibility events. Convert those events before calling merge_events
if push-event fidelity matters.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContextWatchdog
impl RefUnwindSafe for ContextWatchdog
impl Send for ContextWatchdog
impl Sync for ContextWatchdog
impl Unpin for ContextWatchdog
impl UnsafeUnpin for ContextWatchdog
impl UnwindSafe for ContextWatchdog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more