Struct tracing_loki::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

Builder for constructing a Layer and its corresponding BackgroundTask.

See the crate’s root documentation for an example.

Implementations§

source§

impl Builder

source

pub fn label<S: Into<String>, T: AsRef<str>>( self, key: S, value: T ) -> Result<Builder, Error>

Add a label to the logs sent to Loki through the built Layer.

Labels are supposed to be closed categories with few possible values. For example, "environment" with values "ci", "development", "staging" or "production" would work well.

For open categories, extra fields are a better fit. See Builder::extra_field.

No two labels can share the same name, and the key "level" is reserved for the log level.

Errors

This function will return an error if a key is a duplicate or when the key is "level".

Example
let builder = tracing_loki::builder()
    .label("environment", "production")?;
source

pub fn extra_field<S: Into<String>, T: Into<String>>( self, key: S, value: T ) -> Result<Builder, Error>

Set an extra field that is sent with all log records sent to Loki through the built layer.

Fields are meant to be used for open categories or closed categories with many options. For example, "run_id" with randomly generated UUIDv4s would be a good fit for these extra fields.

Example
let builder = tracing_loki::builder()
    .extra_field("run_id", "5b6aedb4-e2c1-4ad9-b8a7-3ef92b5c8120")?;
source

pub fn http_header<S: AsRef<str>, T: AsRef<str>>( self, key: S, value: T ) -> Result<Builder, Error>

Set an extra HTTP header to be sent with all requests sent to Loki.

This can be useful to set the X-Scope-OrgID header which Loki processes as the tenant ID in a multi-tenant setup.

Example
let builder = tracing_loki::builder()
    // Set the tenant ID for Loki.
    .http_header("X-Scope-OrgID", "7662a206-fa0f-407f-abe9-261d652c750b")?;
source

pub fn build_url(self, loki_url: Url) -> Result<(Layer, BackgroundTask), Error>

Build the tracing Layer and its corresponding BackgroundTask.

The loki_url is the URL of the Loki server, like https://127.0.0.1:3100.

The Layer needs to be registered with a tracing_subscriber::Registry, and the BackgroundTask needs to be tokio::spawned.

Note that unlike the layer function, this function does not strip off the path component of loki_url before appending /loki/api/v1/push.

See the crate’s root documentation for an example.

source

pub fn build_controller_url( self, loki_url: Url ) -> Result<(Layer, BackgroundTaskController, BackgroundTask), Error>

Build the tracing Layer, BackgroundTask and its BackgroundTaskController.

The BackgroundTaskController can be used to signal the background task to shut down.

The loki_url is the URL of the Loki server, like https://127.0.0.1:3100.

The Layer needs to be registered with a tracing_subscriber::Registry, and the BackgroundTask needs to be tokio::spawned.

Note that unlike the layer function, this function does not strip off the path component of loki_url before appending /loki/api/v1/push.

See the crate’s root documentation for an example.

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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