Skip to main content

ContextWatchdog

Struct ContextWatchdog 

Source
pub struct ContextWatchdog { /* private fields */ }
Expand description

Watches for context changes by diffing consecutive snapshots.

Implementations§

Source§

impl ContextWatchdog

Source

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}
Source

pub fn tick( &mut self, context: &ContextSnapshot, 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}
Source

pub fn merge_events(&self, events: Vec<CelEvent>) -> Vec<CelEvent>

Merge source-specific push events that have already been normalized to CEL events.

Source

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.

Source

pub fn reset(&mut self)

Reset the watchdog state (e.g., when restarting monitoring).

Trait Implementations§

Source§

impl Default for ContextWatchdog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.