pub struct ChromeLayerBuilder<S>
where S: Subscriber + for<'span> LookupSpan<'span> + Send + Sync,
{ /* private fields */ }
Expand description

A builder for ChromeLayer.

Implementations§

source§

impl<S> ChromeLayerBuilder<S>
where S: Subscriber + for<'span> LookupSpan<'span> + Send + Sync,

source

pub fn new() -> Self

source

pub fn file<P: AsRef<Path>>(self, file: P) -> Self

Set the file to which to output the trace.

Defaults to ./trace-{unix epoch in micros}.json.

§Panics

If file could not be opened/created. To handle errors, open a file and pass it to writer instead.

source

pub fn writer<W: Write + Send + 'static>(self, writer: W) -> Self

Supply an arbitrary writer to which to write trace contents.

§Examples
let (layer, guard) = ChromeLayerBuilder::new().writer(std::io::sink()).build();
source

pub fn include_args(self, include: bool) -> Self

Include arguments in each trace entry.

Defaults to false.

Includes the arguments used when creating a span/event in the “args” section of the trace entry.

source

pub fn include_locations(self, include: bool) -> Self

Include file+line with each trace entry.

Defaults to true.

This can add quite a bit of data to the output so turning it off might be helpful when collecting larger traces.

source

pub fn trace_style(self, style: TraceStyle) -> Self

Sets the style used when recording trace events.

See TraceStyle for details.

source

pub fn name_fn( self, name_fn: Box<dyn Fn(&EventOrSpan<'_, '_, S>) -> String + Send + Sync> ) -> Self

Allows supplying a function that derives a name from an Event or Span. The result is used as the “name” field on trace entries.

§Example
use tracing_chrome::{ChromeLayerBuilder, EventOrSpan};
use tracing_subscriber::{registry::Registry, prelude::*};

let (chrome_layer, _guard) = ChromeLayerBuilder::new().name_fn(Box::new(|event_or_span| {
    match event_or_span {
        EventOrSpan::Event(ev) => { ev.metadata().name().into() },
        EventOrSpan::Span(_s) => { "span".into() },
    }
})).build();
tracing_subscriber::registry().with(chrome_layer).init()
source

pub fn category_fn( self, cat_fn: Box<dyn Fn(&EventOrSpan<'_, '_, S>) -> String + Send + Sync> ) -> Self

Allows supplying a function that derives a category from an Event or Span. The result is used as the “cat” field on trace entries.

§Example
use tracing_chrome::{ChromeLayerBuilder, EventOrSpan};
use tracing_subscriber::{registry::Registry, prelude::*};

let (chrome_layer, _guard) = ChromeLayerBuilder::new().category_fn(Box::new(|_| {
    "my_module".into()
})).build();
tracing_subscriber::registry().with(chrome_layer).init()
source

pub fn build(self) -> (ChromeLayer<S>, FlushGuard)

Creates a ChromeLayer and associated FlushGuard.

§Panics

If no file or writer was specified and the default trace file could not be opened/created.

Trait Implementations§

source§

impl<S> Default for ChromeLayerBuilder<S>
where S: Subscriber + for<'span> LookupSpan<'span> + Send + Sync + Default,

source§

fn default() -> ChromeLayerBuilder<S>

Returns the “default value” for a type. 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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where 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 T
where 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.