1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! [`RuntimeObserver`] trait and associated metadata types for workflow telemetry.
//!
//! Provides opt-in hooks at key execution boundaries: invocation start/finish,
//! per-node completion, checkpoint operations, and event-bus emissions. Every
//! method defaults to a no-op; implement only the hooks you need.
//!
//! ## Usage
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use weavegraph::runtimes::{AppRunner, observer::{RuntimeObserver, NodeFinishMeta}};
//! use weavegraph::app::App;
//!
//! #[derive(Debug)]
//! struct CountingObserver {
//! count: std::sync::atomic::AtomicU64,
//! }
//!
//! impl RuntimeObserver for CountingObserver {
//! fn on_node_finish(&self, meta: &NodeFinishMeta<'_>) {
//! self.count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
//! }
//! }
//!
//! # async fn example(app: App) {
//! let observer = Arc::new(CountingObserver { count: Default::default() });
//! let runner = AppRunner::builder()
//! .app(app)
//! .observer(observer)
//! .build()
//! .await;
//! # }
//! ```
//!
//! ## Performance
//!
//! Hooks are called **synchronously** on the execution thread and must be fast
//! and non-blocking. Panics are caught by the runner, which emits a
//! `tracing::warn!` and continues — an observer failure never aborts the graph.
//!
//! ## Per-node timing in 0.6.0
//!
//! `step_duration_ms` in [`NodeFinishMeta`] is the wall-clock duration of the
//! **entire superstep**, shared by every node that ran in the same parallel step.
//! Per-node timing requires scheduler-level instrumentation and is planned for a
//! future release.
use fmt;
use RefUnwindSafe;
use crateNodeKind;
/// Outcome of a completed workflow invocation.
/// Outcome of a completed node execution within a superstep.
/// Metadata supplied to [`RuntimeObserver::on_invocation_start`].
/// Metadata supplied to [`RuntimeObserver::on_invocation_finish`].
/// Metadata supplied to [`RuntimeObserver::on_node_finish`].
///
/// See the [per-node timing note](self#per-node-timing-in-060) in the module docs.
/// Metadata supplied to [`RuntimeObserver::on_checkpoint_load`].
/// Metadata supplied to [`RuntimeObserver::on_checkpoint_save`].
/// Metadata supplied to [`RuntimeObserver::on_event_bus_emit`].
/// Opt-in telemetry interface for the runtime.
///
/// Register an implementation with
/// [`AppRunnerBuilder::observer`](crate::runtimes::runner::AppRunnerBuilder::observer).
/// All methods default to no-ops; override only the hooks you need.
///
/// ## Contract
///
/// Implementations must be `Send + Sync + 'static` — the runner shares observers
/// across async tasks. The [`RefUnwindSafe`] bound lets the runner catch panics
/// inside hooks without an `AssertUnwindSafe` wrapper at every callsite; a
/// panicking hook produces a `tracing::warn!` and execution continues.