pub struct AppInsights<S = Base, C = Client, R = Tokio, U = Registry, P = (), E = ()> { /* private fields */ }
Expand description
The main telemetry struct.
Refer to the top-level documentation for usage information.
Implementations§
Source§impl<C, R, U, P, E> AppInsights<Base, C, R, U, P, E>
impl<C, R, U, P, E> AppInsights<Base, C, R, U, P, E>
Sourcepub fn with_connection_string(
self,
connection_string: impl Into<Option<String>>,
) -> AppInsights<WithConnectionString, C, R, U, P, E>
pub fn with_connection_string( self, connection_string: impl Into<Option<String>>, ) -> AppInsights<WithConnectionString, C, R, U, P, E>
Sets the connection string to use for telemetry.
If this is not set, then no telemetry will be sent.
use axum_insights::{AppInsights, WithConnectionString};
let i: AppInsights<WithConnectionString> = AppInsights::default()
.with_connection_string(None);
Source§impl<C, R, U, P, E> AppInsights<WithConnectionString, C, R, U, P, E>
impl<C, R, U, P, E> AppInsights<WithConnectionString, C, R, U, P, E>
Sourcepub fn with_service_config(
self,
namespace: impl AsRef<str>,
name: impl AsRef<str>,
servername: impl AsRef<str>,
) -> AppInsights<Ready, C, R, U, P>
pub fn with_service_config( self, namespace: impl AsRef<str>, name: impl AsRef<str>, servername: impl AsRef<str>, ) -> AppInsights<Ready, C, R, U, P>
Sets the service namespace and name.
use axum_insights::{AppInsights, Ready};
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername");
This is a convenience method for AppInsights::with_trace_config
.
Sourcepub fn with_trace_config(self, config: Config) -> AppInsights<Ready, C, R, U, P>
pub fn with_trace_config(self, config: Config) -> AppInsights<Ready, C, R, U, P>
Sets the trace config to use for telemetry.
use axum_insights::{AppInsights, Ready};
use opentelemetry_sdk::trace::Config;
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_trace_config(Config::default());
Source§impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E>
impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E>
Sourcepub fn with_client(self, client: C) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_client(self, client: C) -> AppInsights<Ready, C, R, U, P, E>
Sets the HTTP client to use for sending telemetry. The default is reqwest async client.
use axum_insights::{AppInsights, Ready};
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_client(reqwest::Client::new());
Sourcepub fn with_live_metrics(
self,
should_collect_live_metrics: bool,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_live_metrics( self, should_collect_live_metrics: bool, ) -> AppInsights<Ready, C, R, U, P, E>
Sets whether or not live metrics should be collected. The default is false.
use axum_insights::{AppInsights, Ready};
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_client(reqwest::Client::new())
.with_live_metrics(true);
Sourcepub fn with_sample_rate(
self,
sample_rate: f64,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_sample_rate( self, sample_rate: f64, ) -> AppInsights<Ready, C, R, U, P, E>
Sets the sample rate for telemetry. The default is 1.0.
use axum_insights::{AppInsights, Ready};
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_sample_rate(1.0);
Sourcepub fn with_minimum_level(
self,
minimum_level: LevelFilter,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_minimum_level( self, minimum_level: LevelFilter, ) -> AppInsights<Ready, C, R, U, P, E>
Sets the minimum level for telemetry. The default is INFO.
use axum_insights::{AppInsights, Ready};
use tracing_subscriber::filter::LevelFilter;
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_minimum_level(LevelFilter::INFO);
Sourcepub fn with_subscriber<T>(
self,
subscriber: T,
) -> AppInsights<Ready, C, R, T, P, E>
pub fn with_subscriber<T>( self, subscriber: T, ) -> AppInsights<Ready, C, R, T, P, E>
Sets the subscriber to use for telemetry. The default is a new subscriber.
use axum_insights::{AppInsights, Ready};
use tracing_subscriber::Registry;
let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_subscriber(tracing_subscriber::registry());
Sourcepub fn with_runtime<T>(self, runtime: T) -> AppInsights<Ready, C, T, U, P, E>where
T: RuntimeChannel,
pub fn with_runtime<T>(self, runtime: T) -> AppInsights<Ready, C, T, U, P, E>where
T: RuntimeChannel,
Sets the runtime to use for the telemetry batch exporter. The default is Tokio.
use axum_insights::{AppInsights, Ready};
use opentelemetry_sdk::runtime::Tokio;
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_runtime(Tokio);
Sourcepub fn with_catch_panic(
self,
should_catch_panic: bool,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_catch_panic( self, should_catch_panic: bool, ) -> AppInsights<Ready, C, R, U, P, E>
Sets whether or not to catch panics, and emit a trace for them. The default is false.
use axum_insights::{AppInsights, Ready};
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_catch_panic(true);
Sourcepub fn with_noop(self, should_noop: bool) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_noop(self, should_noop: bool) -> AppInsights<Ready, C, R, U, P, E>
Sets whether or not to make this telemetry layer a noop. The default is false.
This is useful whenever you are running axum tests, as the global subscriber cannot be set in a multiple times. Effectively, this causes the telemetry layer to be a no-op.
use axum_insights::{AppInsights, Ready};
let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_noop(true);
Sourcepub fn with_field_mapper<F>(
self,
field_mapper: F,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_field_mapper<F>( self, field_mapper: F, ) -> AppInsights<Ready, C, R, U, P, E>
Sets a function to extract extra fields from the request. The default is no extra fields.
use axum_insights::{AppInsights, Ready};
use std::collections::HashMap;
let i: AppInsights<Ready> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_field_mapper(|parts| {
let mut map = HashMap::new();
map.insert("extra_field".to_owned(), "extra_value".to_owned());
map
});
Sourcepub fn with_panic_mapper<F, T>(
self,
panic_mapper: F,
) -> AppInsights<Ready, C, R, U, T, E>
pub fn with_panic_mapper<F, T>( self, panic_mapper: F, ) -> AppInsights<Ready, C, R, U, T, E>
Sets a function to extract extra fields from a panic. The default is a default error.
use axum_insights::{AppInsights, Ready};
struct WebError {
message: String,
}
let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_panic_mapper(|panic| {
(500, WebError { message: panic })
});
Sourcepub fn with_success_filter<F>(
self,
success_filter: F,
) -> AppInsights<Ready, C, R, U, P, E>
pub fn with_success_filter<F>( self, success_filter: F, ) -> AppInsights<Ready, C, R, U, P, E>
Sets a function to determine the success-iness of a status. The default is (100 - 399 => true).
This allows you to fine-tune which statuses are considered successful, and which are not. If you have lots of spurious 404s, for example, you can add that to the success statuses.
use axum_insights::{AppInsights, Ready};
use http::StatusCode;
let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_success_filter(|status| {
status.is_success() || status.is_redirection() || status.is_informational() || status == StatusCode::NOT_FOUND
});
Sourcepub fn with_error_type<T>(self) -> AppInsights<Ready, C, R, U, P, T>
pub fn with_error_type<T>(self) -> AppInsights<Ready, C, R, U, P, T>
Sets the error type to use for telemetry. The default is ().
use axum_insights::{AppInsights, AppInsightsError, Ready};
struct WebError {
message: String,
}
impl AppInsightsError for WebError {
fn message(&self) -> Option<String> {
Some(self.message.clone())
}
fn backtrace(&self) -> Option<String> {
None
}
}
let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.with_error_type::<WebError>();
Sourcepub fn build_and_set_global_default(
self,
) -> Result<AppInsightsComplete<P, E>, Box<dyn Error + Send + Sync + 'static>>where
C: HttpClient + 'static,
R: RuntimeChannel,
U: SubscriberExt + for<'span> LookupSpan<'span> + Send + Sync + 'static,
pub fn build_and_set_global_default(
self,
) -> Result<AppInsightsComplete<P, E>, Box<dyn Error + Send + Sync + 'static>>where
C: HttpClient + 'static,
R: RuntimeChannel,
U: SubscriberExt + for<'span> LookupSpan<'span> + Send + Sync + 'static,
Builds the telemetry layer, and sets it as the global default.
use axum_insights::{AppInsights, AppInsightsComplete};
let i: AppInsightsComplete<_, _> = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name", "servername")
.build_and_set_global_default()
.unwrap();
The global default currently has to be set by this library. If you want to use other subscribers,
then you need to use AppInsights::with_subscriber
to inject that subscriber, and then
allow this call to set the global default.
Trait Implementations§
Auto Trait Implementations§
impl<S, C, R, U, P, E> Freeze for AppInsights<S, C, R, U, P, E>
impl<S = Base, C = Client, R = Tokio, U = Registry, P = (), E = ()> !RefUnwindSafe for AppInsights<S, C, R, U, P, E>
impl<S, C, R, U, P, E> Send for AppInsights<S, C, R, U, P, E>
impl<S, C, R, U, P, E> Sync for AppInsights<S, C, R, U, P, E>
impl<S, C, R, U, P, E> Unpin for AppInsights<S, C, R, U, P, E>
impl<S = Base, C = Client, R = Tokio, U = Registry, P = (), E = ()> !UnwindSafe for AppInsights<S, C, R, U, P, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more