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
//! # signal-kit
//!
//! Opinionated OpenTelemetry initialisation for async Rust services.
//!
//! Most applications should use [`ObservabilityBuilder`] or the convenience
//! functions [`init`] and [`try_init`].
//!
//! ```no_run
//! use signal_kit::ObservabilityBuilder;
//!
//! # fn main() -> Result<(), signal_kit::OtelInitError> {
//! let _guard = ObservabilityBuilder::new("my-service")
//! .with_attribute("version", env!("CARGO_PKG_VERSION"))
//! .init()?;
//! # Ok(())
//! # }
//! ```
//!
//! Use [`try_init`] for production applications and tests. Use [`init`] for
//! examples, prototypes, and binaries where panicking on startup failure is
//! acceptable. The crate installs the global tracing subscriber and should
//! usually be initialized once near the start of `main`.
//!
//! ## Environment Variables
//!
//! Compile-time build metadata is read with `option_env!`: `GIT_COMMIT`,
//! `GIT_BRANCH`, `GIT_REPOSITORY_URL`, and `BUILD_NUMBER`.
//!
//! Runtime exporter variables follow OpenTelemetry conventions:
//! `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`,
//! `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, and
//! `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`. Signal-specific endpoints take
//! precedence over the general endpoint.
//!
//! Crate-specific runtime variables are namespaced under `SIGNAL_KIT_`:
//! `SIGNAL_KIT_STRUCTURED_LOGGING`, `SIGNAL_KIT_FILE_ENABLED`,
//! `SIGNAL_KIT_FILE_PATH`, `SIGNAL_KIT_FILE_ROTATION`, and
//! `SIGNAL_KIT_FILE_RETENTION_DAYS`.
//!
//! Resource attributes are resolved in this order: explicit builder
//! attributes, `OTEL_RESOURCE_ATTRIBUTES`, crate convenience aliases such as
//! `ENVIRONMENT`, `CLOUD_*`, and `KUBERNETES_*`, then compile-time metadata.
use Duration;
pub use ;
/// Metrics initialization and configuration.
pub use build_resource;
pub use ;
/// The interval at which metrics and traces are exported to the otlp collector.
pub const OBSERVABILITY_EXPORT_INTERVAL: Duration = from_secs;
/// Check if OTLP endpoint is configured for a specific signal.
///
/// According to OpenTelemetry specification, signal-specific endpoints take precedence
/// over the general endpoint.
///
/// # Arguments
/// * `signal` - The signal type ("traces", "metrics", "logs")
///
/// # Returns
/// * `Some(endpoint)` if an endpoint is configured, `None` otherwise