init4_bin_base/lib.rs
1//! Shared utilities for Signet services.
2
3#![warn(
4 missing_copy_implementations,
5 missing_debug_implementations,
6 missing_docs,
7 unreachable_pub,
8 clippy::missing_const_for_fn,
9 rustdoc::all
10)]
11#![cfg_attr(not(test), warn(unused_crate_dependencies))]
12#![deny(unused_must_use, rust_2018_idioms)]
13#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
14
15#[cfg(feature = "perms")]
16/// Permissioning and authorization utilities for Signet builders.
17pub mod perms;
18
19/// Signet utilities.
20pub mod utils {
21 /// Slot calculator for determining the current slot and timepoint within a
22 /// slot.
23 pub mod calc;
24
25 /// [`FromEnv`], [`FromEnvVar`] traits and related utilities.
26 ///
27 /// [`FromEnv`]: from_env::FromEnv
28 /// [`FromEnvVar`]: from_env::FromEnvVar
29 pub mod from_env;
30
31 /// Prometheus metrics utilities.
32 pub mod metrics;
33
34 /// OpenTelemetry utilities.
35 pub mod otlp;
36
37 #[cfg(feature = "alloy")]
38 /// Alloy Provider configuration and instantiation
39 pub mod provider;
40
41 #[cfg(feature = "alloy")]
42 /// Signer using a local private key or AWS KMS key.
43 pub mod signer;
44
45 /// Tracing utilities.
46 pub mod tracing;
47}
48
49/// Re-exports of common dependencies.
50pub mod deps {
51 pub use metrics;
52 pub use opentelemetry;
53 pub use opentelemetry_otlp;
54 pub use opentelemetry_sdk;
55 pub use tracing;
56 pub use tracing_core;
57 pub use tracing_opentelemetry;
58 pub use tracing_subscriber;
59}
60
61/// Init metrics and tracing, including OTLP if enabled.
62///
63/// This will perform the following:
64/// - Read environment configuration for tracing
65/// - Determine whether to enable OTLP
66/// - Install a global tracing subscriber, using the OTLP provider if enabled
67/// - Read environment configuration for metrics
68/// - Install a global metrics recorder and serve it over HTTP on 0.0.0.0
69///
70/// See [`init_tracing`] and [`init_metrics`] for more
71/// details on specific actions taken and env vars read.
72///
73/// # Returns
74///
75/// The OpenTelemetry guard, if OTLP is enabled. This guard should be kept alive
76/// for the lifetime of the program to ensure the exporter continues to send
77/// data to the remote API.
78///
79/// [`init_tracing`]: utils::tracing::init_tracing
80/// [`init_metrics`]: utils::metrics::init_metrics
81pub fn init4() -> Option<utils::otlp::OtelGuard> {
82 let guard = utils::tracing::init_tracing();
83 utils::metrics::init_metrics();
84
85 // This will install the AWS-LC-Rust TLS provider for rustls, if no other
86 // provider has been installed yet
87 #[cfg(feature = "rustls")]
88 let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
89
90 guard
91}