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 /// A simple interface to flashbots RPC endpoints.
26 #[cfg(feature = "flashbots")]
27 pub mod flashbots;
28
29 /// [`FromEnv`], [`FromEnvVar`] traits and related utilities.
30 ///
31 /// [`FromEnv`]: from_env::FromEnv
32 /// [`FromEnvVar`]: from_env::FromEnvVar
33 pub mod from_env;
34
35 /// Prometheus metrics utilities.
36 pub mod metrics;
37
38 /// OpenTelemetry utilities.
39 pub mod otlp;
40
41 #[cfg(feature = "alloy")]
42 /// Alloy Provider configuration and instantiation
43 pub mod provider;
44
45 #[cfg(feature = "aws")]
46 /// Signer using a local private key or AWS KMS key.
47 pub mod signer;
48
49 /// Tracing utilities.
50 pub mod tracing;
51}
52
53/// Re-exports of common dependencies.
54pub mod deps {
55 pub use metrics;
56 pub use opentelemetry;
57 pub use opentelemetry_otlp;
58 pub use opentelemetry_sdk;
59 pub use tracing;
60 pub use tracing_core;
61 pub use tracing_opentelemetry;
62 pub use tracing_subscriber;
63}
64
65/// Init metrics and tracing, including OTLP if enabled.
66///
67/// This will perform the following:
68/// - Read environment configuration for tracing
69/// - Determine whether to enable OTLP
70/// - Install a global tracing subscriber, using the OTLP provider if enabled
71/// - Read environment configuration for metrics
72/// - Install a global metrics recorder and serve it over HTTP on 0.0.0.0
73///
74/// See [`init_tracing`] and [`init_metrics`] for more
75/// details on specific actions taken and env vars read.
76///
77/// # Returns
78///
79/// The OpenTelemetry guard, if OTLP is enabled. This guard should be kept alive
80/// for the lifetime of the program to ensure the exporter continues to send
81/// data to the remote API.
82///
83/// [`init_tracing`]: utils::tracing::init_tracing
84/// [`init_metrics`]: utils::metrics::init_metrics
85pub fn init4() -> Option<utils::otlp::OtelGuard> {
86 let guard = utils::tracing::init_tracing();
87 utils::metrics::init_metrics();
88
89 // This will install the AWS-LC-Rust TLS provider for rustls, if no other
90 // provider has been installed yet
91 #[cfg(feature = "rustls")]
92 let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
93
94 guard
95}