substrate_core/trace.rs
1//! Cross-cutting trace port: the trait lives in core so the application layer
2//! can emit events without knowing which backend receives them.
3//!
4//! **Rule:** only the trait and the event structs live here. Adapter
5//! implementations (`NoopTrace`, `RecordingTrace`, `MultiTrace`, etc.) belong
6//! in the `substrate-trace` crate.
7
8/// An event fired when a task is first registered with the system.
9#[derive(Debug, Clone)]
10pub struct TaskRegistered {
11 /// Stable task identity.
12 pub task_id: String,
13 /// Traceability link to a requirement (FR/NFR id), if present.
14 pub requirement_id: Option<String>,
15 /// Traceability link to an epic, if present.
16 pub epic_id: Option<String>,
17}
18
19/// An event fired when a task completes successfully.
20#[derive(Debug, Clone)]
21pub struct TaskCompleted {
22 /// Stable task identity.
23 pub task_id: String,
24 /// Pull-request URLs emitted by the run.
25 pub pr_urls: Vec<String>,
26 /// Traceability link to the originating requirement, if present.
27 pub requirement_id: Option<String>,
28}
29
30/// An event fired when a task fails.
31#[derive(Debug, Clone)]
32pub struct TaskFailed {
33 /// Stable task identity.
34 pub task_id: String,
35 /// Human-readable failure description.
36 pub error: String,
37 /// Traceability link to the originating requirement, if present.
38 pub requirement_id: Option<String>,
39}
40
41/// The cross-cutting trace port.
42///
43/// Adapters implement this to ship events to AgilePlus, Tracera, an in-memory
44/// recording double, or a fan-out multiplexer. The port is defined here in
45/// core so that `DispatchService` can emit events without depending on any
46/// adapter crate.
47pub trait TracePort: Send + Sync {
48 /// Called once when a task is accepted into the system.
49 fn task_registered(&self, event: TaskRegistered);
50
51 /// Called once when a task run concludes successfully.
52 fn task_completed(&self, event: TaskCompleted);
53
54 /// Called once when a task run concludes with a failure.
55 fn task_failed(&self, event: TaskFailed);
56}