metry 0.1.1

All-in-one telemetry framework, based on tracing crate.
Documentation
//! A configurator module for telemetry.
//!
//! # Usage
//!
//! The configurator creates a pipeline that by default registers
//! a noop implementation for events emitted by [tracing] crate.
//! The utility functions on the resultant pipeline add
//! logs, metrics and trace subscribers up until the `init` method is called.
//!
//! ## Setup telemetry collection
//!
//! ### Minimal setup for an AWS environment
//! ```no_run
//! use metry::telemetry;
//!
//! telemetry::new()
//!     .with_stdout_logs()
//!     .with_aws_metrics()
//!     .with_aws_traces()
//!     .init()
//!     .await;
//! ```
//!
//! ### Setup with default settings and all data written to stdout
//! ```no_run
//! use metry::{log, metrics, telemetry, trace, Level};
//!
//! telemetry::new()
//!     .with_level(Level::DEBUG)
//!     .with_logs(log::LayerBuilder::Stdout(logs::LogOptions::default()))
//!     .with_metrics(metrics::LayerBuilder::Stdout(metrics::MetricsOptions::default()))
//!     .with_traces(trace::LayerBuilder::Stdout(trace::TraceOptions::default())
//!     .init()
//!     .await;
//! ```
//!
//! ### Provide custom configuration for each provider
//! ```no_run
//! use std::time::Duration;
//! use metry::{
//!     telemetry,
//!     log,
//!     metrics::{self, CloudWatchMetricsOptionsConfigurator, MetricsOptionsConfigurator},
//!     trace,
//!     Level
//! };
//! use opentelemetry::KeyValue
//! use opentelemetry_aws::trace::XrayIdGenerator;
//! use opentelemetry_sdk::Resource;
//! use opentelemetry_semantic_conventions::resource::SERVICE_NAME;
//! use tracing_core::LevelFilter;
//!
//! let resource = Resource::new(vec![KeyValue::new(SERVICE_NAME, "telemetry-example-rust")]);
//!
//! telemetry::new()
//!     .with_level(Level::DEBUG)
//!     .with_logs(log::LayerBuilder::Stdout(
//!         logs::LogOptions::with_log_config(opentelemetry_sdk::logs::config().with_resource(resource)),
//!     ))
//!     .with_metrics(metrics::LayerBuilder::CloudWatch(
//!         metrics::CloudWatchMetricsOptions::default()
//!             .with_namespace("rust-metrics".to_string())
//!             .with_exporter_interval(Duration::from_secs(10))
//!             .with_view(Box::new(|instrument: &Instrument| -> Option<Stream> {
//!                 let start = "s3";
//!                 if instrument.name.starts_with(start) {
//!                     let new_name = instrument.name.replace(start, "s3-bucket-listing");
//!                     Some(
//!                         Stream::new()
//!                             .name(new_name)
//!                             .allowed_attribute_keys([Key::from("allowed_key")]),
//!                     )
//!                 } else {
//!                     None
//!                 }
//!             })),
//!     ))
//!     .with_traces(trace::LayerBuilder::Xray(
//!         trace::TraceOptions::with_trace_config(
//!             opentelemetry_sdk::trace::config()
//!                 .with_resource(resource)
//!                 .with_id_generator(XrayIdGenerator::default()),
//!         ),
//!     ))
//!     .init()
//!     .await;
//! ```
//!
//! ## Collect data in your code
//! To publish a log emit any [tracing] event.
//!
//! To publish a new metric follow instructions in [tracing_opentelemetry::MetricsLayer].
//!
//! To record trace create [tracing] spans and either bring them in scope manually or attach to futures.
//!
//! ### Examples:
//! ```no_run
//! use tracing::{info, info_span};
//!
//! // Emit a log event with level info
//! info!("Started execution");
//!
//! // Start a synchronous trace span
//! let span = info_span!("my sync span");
//! span.in_scope(|| {
//!     info!("This event is recorder within the trace span");
//!
//!     // Do work inside the span...
//!
//!     // Collect metrics: count on foo
//!     info!(monotonic_counter.foo = 1);
//! });
//!
//! // Run async code in a future with a span attached
//! let future_result: Vec<u64> = some_future
//!     .instrument(tracing::info_span!("my async span"))
//!     .await;
//!
//! // Collect metrics: put data into the bar histogram
//! info!(histogram.bar = future_result);
//! info!("Execution complete");
//! ```
//!

mod level;
mod pipeline;

pub use level::Level;
pub use pipeline::{new, TelemetryPipeline};