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
//! # Event subscriber trait.
//!
//! [`Subscribe`] is the extension point for observing runtime events.
//!
//! Each subscriber gets:
//! - a dedicated worker task,
//! - a bounded queue,
//! - panic isolation.
//!
//! Delivery is best-effort.
//! If a subscriber falls behind, new events may be dropped for that subscriber only.
//! Other subscribers and task execution are not blocked.
//!
//! ## Flow
//!
//! ```text
//! SubscriberSet ──► [bounded queue] ──► worker ──► subscriber.on_event()
//! └─► panic ──► SubscriberPanicked
//! ```
//!
//! ## Rules
//!
//! - Ordinary overflows are reported as [`EventKind::SubscriberOverflow`](crate::EventKind::SubscriberOverflow).
//! - Ordinary panics are reported as [`EventKind::SubscriberPanicked`](crate::EventKind::SubscriberPanicked).
//! - Diagnostic events are not re-reported if they overflow or panic, to avoid feedback loops.
//! - Events are processed sequentially (FIFO) per subscriber.
//! - Queue overflow drops the event for this subscriber only.
//! - A slow subscriber only affects its own queue.
//!
//! ## Example
//!
//! ```rust
//! use taskvisor::{Event, EventKind, Subscribe};
//!
//! struct Metrics;
//!
//! impl Subscribe for Metrics {
//! fn on_event(&self, ev: &Event) {
//! if matches!(ev.kind, EventKind::TaskFailed) {
//! // update counters, push to a channel, etc.
//! }
//! }
//!
//! fn name(&self) -> &str { "metrics" }
//! fn queue_capacity(&self) -> usize { 2048 }
//! }
//! ```
use crateEvent;
/// Event subscriber for runtime observability.
///
/// `Subscribe` is synchronous by design.
/// The runtime already moves delivery to a dedicated worker task for each subscriber.
///
/// Keep [`on_event`](Self::on_event) fast; for async I/O, send data to a channel and process it elsewhere.
///
/// Panics are caught and isolated.
/// A panic while handling an ordinary event is reported as `SubscriberPanicked`.
/// A panic while handling an internal diagnostic event is not reported again, to avoid a feedback loop.