Trait tracing_tracy::Config
source · pub trait Config {
type Formatter: for<'writer> FormatFields<'writer> + 'static;
// Required method
fn formatter(&self) -> &Self::Formatter;
// Provided methods
fn stack_depth(&self, metadata: &Metadata<'_>) -> u16 { ... }
fn format_fields_in_zone_name(&self) -> bool { ... }
fn on_error(&self, client: &Client, error: &'static str) { ... }
}
Expand description
Configuration of the TracyLayer
behaviour.
For most users DefaultConfig
is going to be a good default choice, however advanced users
can implement this trait manually to override the formatter used or to otherwise modify the
behaviour of the TracyLayer
.
§Examples
use tracing_subscriber::fmt::format::DefaultFields;
struct TracyLayerConfig {
fmt: DefaultFields,
}
impl tracing_tracy::Config for TracyLayerConfig {
type Formatter = DefaultFields;
fn formatter(&self) -> &Self::Formatter {
&self.fmt
}
// The boilerplate ends here
/// Collect 32 frames in stack traces.
fn stack_depth(&self, _: &tracing::Metadata) -> u16 {
32
}
/// Do not format fields into zone names.
fn format_fields_in_zone_name(&self) -> bool {
false
}
// etc.
}
With this configuration TracyLayer
will collect some call stacks and the formatting of the
zone names is different from the DefaultConfig
.
Required Associated Types§
type Formatter: for<'writer> FormatFields<'writer> + 'static
Required Methods§
Provided Methods§
sourcefn stack_depth(&self, metadata: &Metadata<'_>) -> u16
fn stack_depth(&self, metadata: &Metadata<'_>) -> u16
Specify the maximum number of stack frames that will be collected.
Note that enabling callstack collection can and will introduce a non-trivial overhead at every instrumentation point. Specifying 0 frames will disable stack trace collection.
Default implementation returns 0
.
sourcefn format_fields_in_zone_name(&self) -> bool
fn format_fields_in_zone_name(&self) -> bool
Specify whether or not to include tracing span fields in the tracy zone name, or to emit them as zone text.
The former enables zone analysis along unique span field invocations, while the latter aggregates every invocation of a given span into a single zone, irrespective of field values.
Default implementation returns true
.
sourcefn on_error(&self, client: &Client, error: &'static str)
fn on_error(&self, client: &Client, error: &'static str)
Apply handling for errors detected by the TracyLayer
.
Fundamentally the way the tracing crate and the Tracy profiler work are somewhat
incompatible in certain ways. For instance, a tracing::Span
can be created on one
thread and moved to another, where it is cleaned up. Tracy on the other hand expects that
its eqvivalent concept of zone remains entirely within a thread.
Another example a limitation in Tracy
where the message length or zone name cannot exceed
a certain (low) limit of bytes.
Although tracing_tracy
does it best to paper over these sorts of differences, it can’t
always make them invisible. In certain cases detecting these sorts of issues is
straightforward, and it is when tracing_tracy
will invoke this method to enable users to
report the issues in whatever way they wish to.
By default a message coloured in red is emitted to the tracy client.