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
use Arc;
use OnceLock;
use AtomicU64;
use crateAuditEvent;
use crateEventSink;
/// Counts events silently dropped because the telemetry channel was full.
///
/// Consumers of `WriterSink` do not drop events; this counter is retained for
/// compatibility with code paths that may use a custom buffering sink that
/// increments this counter on back-pressure.
/// Monitor this counter in alerting rules for SOC2 / FedRAMP compliance.
pub static DROPPED_AUDIT_EVENTS: AtomicU64 = new;
/// Global sink set once at `init_telemetry_with_sink` time.
static TELEMETRY_SINK: = new;
/// Handle returned by `init_telemetry_with_sink`.
///
/// Call `shutdown()` before the process exits to flush any buffered events.
/// Initialises the telemetry pipeline with an injectable sink.
///
/// Allows servers, CLIs, and tests to provide their own sink implementation.
/// A second call is a silent no-op; the first initialisation wins.
///
/// Args:
/// * `sink` - The sink implementation to install globally.
///
/// Usage:
/// ```ignore
/// use auths_telemetry::{init_telemetry_with_sink, sinks::stdout::new_stdout_sink};
/// use std::sync::Arc;
/// let _handle = init_telemetry_with_sink(Arc::new(new_stdout_sink()));
/// ```
/// Emits a structured telemetry event to the active sink.
///
/// Serialises `event` to JSON and forwards to the active sink. Returns
/// immediately. If `init_telemetry_with_sink` was never called, this is a no-op.
///
/// Args:
/// * `event` - The structured audit event to emit.
///
/// Usage:
/// ```rust
/// use auths_telemetry::{build_audit_event, emit_telemetry};
/// let event = build_audit_event("did:keri:abc...", "session_verification", "Success", 0);
/// emit_telemetry(&event);
/// ```