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
#![deny(warnings)]
#![deny(missing_docs)]
#![recursion_limit = "1024"]
#![deny(
clippy::all,
clippy::unwrap_used,
clippy::unnecessary_unwrap,
clippy::pedantic,
clippy::mod_module_files
)]
//! Send traces to Axiom with a single line.
//!
//! # Example
//!
//! In a project that uses [Tokio](https://tokio.rs) and
//! [tracing](https://docs.rs/tracing) run `cargo add tracing-axiom` and
//! configure it like this:
//!
//! ```rust,no_run
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! tracing_axiom::init()?; // Set AXIOM_DATASET and AXIOM_TOKEN in your env!
//! say_hello();
//! Ok(())
//! }
//!
//! #[tracing::instrument]
//! pub fn say_hello() {
//! tracing::info!("Hello, world!");
//! }
//! ```
//!
//! The example above gets the Axiom API token from the `AXIOM_TOKEN` env and
//! the dataset name from `AXIOM_DATASET`. For more advanced configuration, see [`builder()`].
mod builder;
mod error;
pub use builder::Builder;
pub use error::Error;
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadmeDoctests;
/// Initialize a global subscriber which sends traces to Axiom.
///
/// It uses the environment variables `AXIOM_TOKEN` and optionally `AXIOM_URL`
/// to configure the endpoint.
/// If you want to manually set these, see [`Builder`].
///
/// # Errors
///
/// Errors if the initialization was unsuccessful, likely because a global
/// subscriber was already installed or `AXIOM_TOKEN` and/or `AXIOM_DATASET`
/// is not set or invalid.
pub fn init() -> Result<(), Error> {
builder().init()
}
/// Create a new [`Builder`].
#[must_use]
pub fn builder() -> Builder {
Builder::new()
}