Skip to main content

Observability

Struct Observability 

Source
pub struct Observability { /* private fields */ }
Available on crate feature observability only.
Expand description

The configured telemetry providers. Cheap to clone; every clone refers to the same providers.

Dropping the last clone without calling shutdown lets the SDK flush on drop, which may block; call shutdown explicitly (Kerniq’s App does so after draining connections).

Implementations§

Source§

impl Observability

Source

pub fn builder() -> ObservabilityBuilder

Starts configuring observability.

Source

pub fn disabled() -> Observability

A handle with every signal disabled.

Source

pub fn service(&self) -> &ServiceInfo

The service identity.

Source

pub fn resource(&self) -> &Resource

Available on crate features logs or metrics or tracing only.

The OpenTelemetry resource attached to every signal.

Source

pub fn meter(&self, name: &'static str) -> Meter

Available on crate feature metrics only.

A meter for application instruments. Create instruments once and reuse them; recording is lock-free in the common case. Returns a no-op meter when metrics are disabled, so instrumentation code never needs to check.

Source

pub fn meter_provider(&self) -> Option<&SdkMeterProvider>

Available on crate feature metrics only.

The SDK meter provider, when metrics are enabled.

Source

pub fn tracer(&self, name: &'static str) -> SdkTracer

Available on crate feature tracing only.

A tracer for manual spans through the OpenTelemetry API. Most code should use tracing spans instead, which are exported through the same provider.

Source

pub fn tracer_provider(&self) -> Option<&SdkTracerProvider>

Available on crate feature tracing only.

The SDK tracer provider, when tracing is enabled.

Source

pub fn propagator(&self) -> Arc<dyn TextMapPropagator + Send + Sync> ⓘ

Available on crate feature tracing only.

The W3C TraceContext + Baggage propagator, for outbound calls (see kerniq_observability_axum::propagation).

Source

pub fn logger_provider(&self) -> Option<&SdkLoggerProvider>

Available on crate feature logs only.

The SDK logger provider, when log export is enabled.

Source

pub fn prometheus(&self) -> Option<&PrometheusExporter>

Available on crate feature prometheus only.

The Prometheus endpoint, when configured.

Source

pub fn http_instrumentation(&self) -> HttpInstrumentation

HTTP instrumentation configured from this handle: metrics when metrics are enabled, spans and W3C propagation when tracing is enabled, and the configured exclusions (the Prometheus path is always excluded).

Source

pub fn stats(&self) -> TelemetryStats

Export-pipeline counters (see TelemetryStats). Also published as the kerniq.telemetry.items and kerniq.telemetry.exports metrics.

Source

pub fn force_flush(&self) -> Vec<String>

Exports everything buffered now. Blocks the calling thread until the exporters return; use from spawn_blocking in async code.

Source

pub async fn shutdown(&self) -> ShutdownReport

Flushes and shuts down every provider, in at most the configured shutdown timeout. Idempotent; later calls return immediately.

Call it after the server has stopped accepting requests and drained (Kerniq’s App does this automatically). Providers are shut down on Tokio’s blocking pool, so the async runtime stays responsive even if a Collector is unreachable; the caller waits at most the timeout.

Source

pub fn install_global_providers(&self)

Sets this handle’s providers and propagator as the OpenTelemetry globals (opentelemetry::global), for libraries that instrument through the global API. Never done implicitly.

Source

pub fn tracing_layer<S>(&self) -> Box<dyn Layer<S> + Send + Sync>
where S: Subscriber + for<'a> LookupSpan<'a> + Send + Sync,

Available on crate features logs or tracing only.

The tracing layers for this configuration (console output, span export, log export), each with its own filter, for composing into an application-owned subscriber (with install_subscriber(false)).

use tracing_subscriber::layer::SubscriberExt;
use kerniq_observability::prelude::*;

let observability = Observability::builder()
    .logs(LogsConfig::json())
    .install_subscriber(false)
    .build()
    .await?;
let subscriber = tracing_subscriber::registry()
    .with(observability.tracing_layer())
    // .with(your_other_layer)
    ;
tracing::subscriber::set_global_default(subscriber).unwrap();

Trait Implementations§

Source§

impl Clone for Observability

Source§

fn clone(&self) -> Observability

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Observability

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ServiceExt for T

Source§

fn compression(self) -> Compression<Self>
where Self: Sized,

Available on crate features compression-br or compression-deflate or compression-gzip or compression-zstd only.
Compresses response bodies. Read more
Source§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

Available on crate feature trace only.
High level tracing that classifies responses using HTTP status codes. Read more
Source§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

Available on crate feature trace only.
High level tracing that classifies responses using gRPC headers. Read more
Source§

fn set_request_id<M>( self, header_name: HeaderName, make_request_id: M, ) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Available on crate feature request-id only.
Add request id header and extension. Read more
Source§

fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Available on crate feature request-id only.
Add request id header and extension, using x-request-id as the header name. Read more
Source§

fn propagate_request_id( self, header_name: HeaderName, ) -> PropagateRequestId<Self>
where Self: Sized,

Available on crate feature request-id only.
Propgate request ids from requests to responses. Read more
Source§

fn propagate_x_request_id(self) -> PropagateRequestId<Self>
where Self: Sized,

Available on crate feature request-id only.
Propgate request ids from requests to responses, using x-request-id as the header name. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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