pub trait AppInsightsError {
// Required methods
fn message(&self) -> Option<String>;
fn backtrace(&self) -> Option<String>;
}
Expand description
A trait that extracts relevant information from a global error type.
A type that implements this trait can be used as the E
type parameter for AppInsights
.
It is usually set via AppInsights::with_error_type
.
use axum_insights::AppInsights;
use axum_insights::AppInsightsError;
struct WebError {
message: String,
}
impl AppInsightsError for WebError {
fn message(&self) -> Option<String> {
Some(self.message.clone())
}
fn backtrace(&self) -> Option<String> {
None
}
}
let telemetry_layer = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_error_type::<WebError>()
.build_and_set_global_default()
.unwrap()
.layer();
If your handlers all return a type that implements this trait, then you can use the AppInsightsLayer
to automatically
instrument all of your handlers to extract some of the error information from your error type (only attempts the extraction
for 400s and 500s).
Implementing this trait allows the AppInsightsLayer
to extract the error message and backtrace from your error type,
and add that information to the resulting traces.