dump_context/
dump_context.rs1use cel_context::{
6 ContentRole, ContextContribution, ContextElement, ContextMerger, ContextSource,
7 ContextWatchdog, ElementState,
8};
9
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}