Struct AppInsights

Source
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>

Source

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>

Source

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.

Source

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>

Source

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());
Source

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);
Source

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);
Source

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);
Source

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());
Source

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);
Source

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);
Source

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);
Source

pub fn with_field_mapper<F>( self, field_mapper: F, ) -> AppInsights<Ready, C, R, U, P, E>
where F: Fn(&Parts) -> HashMap<String, String> + Send + Sync + 'static,

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
    });
Source

pub fn with_panic_mapper<F, T>( self, panic_mapper: F, ) -> AppInsights<Ready, C, R, U, T, E>
where F: Fn(String) -> (u16, T) + Send + Sync + 'static,

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 })
    });
Source

pub fn with_success_filter<F>( self, success_filter: F, ) -> AppInsights<Ready, C, R, U, P, E>
where F: Fn(StatusCode) -> bool + Send + Sync + 'static,

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
    });
Source

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>();
Source

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§

Source§

impl Default for AppInsights<Base>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S, C, R, U, P, E> Freeze for AppInsights<S, C, R, U, P, E>
where C: Freeze, R: Freeze, U: Freeze,

§

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>
where C: Send, R: Send, U: Send, S: Send, E: Send,

§

impl<S, C, R, U, P, E> Sync for AppInsights<S, C, R, U, P, E>
where C: Sync, R: Sync, U: Sync, S: Sync, E: Sync,

§

impl<S, C, R, U, P, E> Unpin for AppInsights<S, C, R, U, P, E>
where C: Unpin, R: Unpin, U: Unpin, S: Unpin, E: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,