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
//! JSON log subscriber (ADR-0072, opt-in via `otlp-json` feature).
//!
//! Installs a `tracing_subscriber` JSON formatter that writes one
//! newline-delimited JSON object per event to stdout. This shape is what
//! the [`opentelemetry-log`](https://docs.rs/opentelemetry-stdout/) exporter
//! and most log shippers (Fluent Bit, Vector, Promtail, Loki) expect on
//! the wire — the lightweight alternative to a full `opentelemetry-otlp`
//! gRPC exporter called out in ADR-0072 §"Implementation".
//!
//! # Design
//!
//! - Reuses `tracing_subscriber::fmt::format::Json` (already in
//! `tracing-subscriber`'s `json` feature). No new dependencies.
//! - Best-effort: a `set_global_default` failure is intentionally ignored
//! because the most common cause is a competing subscriber (e.g. a test
//! harness). Returning the error to the caller would break otherwise
//! working applications.
use MakeWriter;
/// Writer that sends events to stdout. Defined as its own type so the
/// JSON subscriber does not depend on the default `tracing_subscriber`
/// `Stdout` target (which can be re-initialised across tests).
;
/// `Write` adapter that writes to locked stdout.
;
/// Install a global JSON tracing subscriber.
///
/// Idempotent at the level the caller cares about: if a subscriber is
/// already installed (`set_global_default` fails), the function returns
/// without touching anything. This is the same pattern used by
/// `tracing_subscriber::fmt::init()` and keeps the public API panic-free.