#![cfg_attr(
feature = "backtrace",
feature(error_generic_member_access, backtrace_frames)
)]
#![cfg_attr(not(feature = "backtrace"), feature(error_generic_member_access))]
#![feature(error_iter)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(docsrs, doc_auto_cfg)]
#![doc = include_str!("../README.md")]
#[cfg(feature = "bench")]
pub mod bench;
#[cfg(feature = "instant")]
pub mod breakdown;
pub mod compat;
pub mod config;
pub mod deploy;
pub mod diagnostic;
pub mod errors;
pub mod exn;
pub mod hook;
pub mod profiling;
pub mod report;
#[cfg(feature = "int-tokio")]
pub mod tokio_ext;
#[cfg(feature = "fastrace")]
pub mod reporter;
#[cfg(feature = "instant")]
pub use breakdown::{drain_spans, print_breakdown};
pub use deploy::{Deployment, InitError, InitGuard, observe};
pub use diagnostic::{
Diagnostic, LabelSpan, Severity, SourceSpan, eprint_diagnostic, register_source,
render_diagnostic,
};
pub use errors::{
CategoryTag, Coded, ERROR_REGISTRY, ErrorCode, ErrorRegistryEntry, doctor, error_registry,
lookup_error, register_statics,
};
pub use exn::{
Attachment, Backoff, BoxError, BuiltinKey, Context, ErrorExt, Fault, FaultCollection, Frame,
FrameIter, FrameKind, InternalError, OptionExt, Placement, Result, ResultExt, error_counts,
error_counts_by_category, retry_with_backoff, retry_with_policy,
};
pub use hook::{
HookId, add_capture_hook, add_error_hook, capture_hooks_len, clear_error_hooks, hooks_len,
init, remove_error_hook, set_default_hook_enabled,
};
pub use profiling::Nanos;
pub use profiling::clock::now_ns;
#[cfg(feature = "instant")]
pub use profiling::instant::SpanRecord;
pub use profiling::{
all_functions, current_scope_elapsed_ms, current_scope_name, instrument, scope_path, skip,
};
#[cfg(feature = "serde")]
pub use report::render_report_json;
pub use report::{render_report, report_display};
pub use fast_observe_macros::error;
pub use fast_observe_macros::instrument_async;
pub use fast_observe_macros::main;
#[cfg(feature = "anyhow-boundary")]
pub use compat::anyhow_boundary;
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
strum::AsRefStr,
strum::IntoStaticStr,
derive_more::Display,
)]
#[non_exhaustive]
pub enum ErrorCategory {
Content,
Invariant,
Transient,
Fatal,
}
impl ErrorCategory {
#[must_use]
pub const fn policy(self) -> Policy {
match self {
Self::Content => Policy::FixInput,
Self::Transient => Policy::Retry,
Self::Invariant => Policy::Poison,
Self::Fatal => Policy::Abort,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Policy {
FixInput,
Retry,
Poison,
Abort,
}
impl Policy {
#[must_use]
pub const fn advice_line(self) -> &'static str {
match self {
Self::FixInput => "fix the input; retrying unchanged input will fail",
Self::Retry => "safe to retry with backoff; if persistent, escalate",
Self::Poison => "state may be corrupt; unwind to a recovery boundary and reinitialize",
Self::Abort => "fatal invariant violation; do not continue this process",
}
}
}
pub use ErrorCategory as Category;
pub mod prelude {
pub use crate::config::{Backends, config};
pub use crate::{
Attachment, BoxError, Category, Coded, Context, ErrorCategory, ErrorExt, Fault,
FaultCollection, Frame, InternalError, OptionExt, Placement, Policy, Result, ResultExt,
add_capture_hook, add_error_hook, all_functions, bail, doctor, ensure, error, error_counts,
error_registry, finish_frame, init, instrument, instrument_async, lookup_error, main,
observe, render_report, report_display, scope, skip,
};
}
pub(crate) mod log_targets {
pub const ERROR: &str = "fast_observe.error";
pub const DEPLOY: &str = "fast_observe.deploy";
pub const CONFIG: &str = "fast_observe.config";
pub const DIAGNOSTIC: &str = "fast_observe.diagnostic";
}
pub(crate) mod env_vars {
pub const OBSERVE_LOG: &str = "OBSERVE_LOG";
pub const RUST_LOG: &str = "RUST_LOG";
pub const OBSERVE_LOG_DIR: &str = "OBSERVE_LOG_DIR";
pub const OBSERVE_PROFILE: &str = "OBSERVE_PROFILE";
pub const OBSERVE_ERROR_THROTTLE: &str = "OBSERVE_ERROR_THROTTLE";
pub const OBSERVE_REPORT: &str = "OBSERVE_REPORT";
pub const OBSERVE_COLOR: &str = "OBSERVE_COLOR";
#[cfg(feature = "backtrace")]
pub const OBSERVE_BACKTRACE: &str = "OBSERVE_BACKTRACE";
#[cfg(feature = "backtrace")]
pub const RUST_BACKTRACE: &str = "RUST_BACKTRACE";
pub const OBSERVE_REPORT_SOURCE: &str = "OBSERVE_REPORT_SOURCE";
}
#[doc(hidden)]
pub mod __private {
#[cfg(not(target_family = "wasm"))]
pub use linkme;
#[cfg(not(target_family = "wasm"))]
pub use linkme::distributed_slice;
#[cfg(feature = "fastrace")]
pub use ::fastrace;
}
pub fn flush() {
#[cfg(feature = "fastrace")]
fastrace::flush();
}
#[cfg(feature = "bench")]
pub use bench::divan;
#[cfg(feature = "int-axum")]
pub use fastrace_axum;
#[cfg(feature = "reporter-datadog")]
pub use fastrace_datadog;
#[cfg(feature = "reporter-jaeger")]
pub use fastrace_jaeger;
#[cfg(feature = "int-poem")]
pub use fastrace_poem;
#[cfg(feature = "http")]
pub use fastrace_reqwest;
#[cfg(feature = "int-tonic")]
pub use fastrace_tonic;
#[cfg(feature = "int-tower")]
pub use fastrace_tower;
#[cfg(feature = "bridge-tracing")]
pub use fastrace_tracing;
#[cfg(feature = "otel")]
pub use hook::init_otel;
#[cfg(feature = "otel")]
pub use {fastrace_opentelemetry, logforth_append_opentelemetry};