Skip to content

Commit

Permalink
pass in metadata for stack depth config
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Jan 28, 2024
1 parent 408e700 commit d51df35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions tracing-tracy/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use client::Client;
use tracing_subscriber::fmt::format::DefaultFields;
use tracing_subscriber::fmt::FormatFields;
#[allow(unused_imports)] // for documentation.
use super::TracyLayer;

/// Configuration of the [`TracyLayer`] behaviour.
/// Configuration of the [`TracyLayer`](super::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
Expand All @@ -26,11 +24,11 @@ use super::TracyLayer;
/// // The boilerplate ends here
///
/// /// Collect 32 frames in stack traces.
/// fn stack_depth(&self) -> u16 {
/// fn stack_depth(&self, _: &tracing::Metadata) -> u16 {
/// 32
/// }
///
/// /// Do not format in fields into zone names.
/// /// Do not format fields into zone names.
/// fn format_fields_in_zone_name(&self) -> bool {
/// false
/// }
Expand All @@ -53,7 +51,8 @@ pub trait Config {
/// every instrumentation point. Specifying 0 frames will disable stack trace collection.
///
/// Default implementation returns `0`.
fn stack_depth(&self) -> u16 {
fn stack_depth(&self, metadata: &tracing_core::Metadata<'_>) -> u16 {
let _ = metadata;
0
}

Expand All @@ -69,7 +68,7 @@ pub trait Config {
true
}

/// Apply handling for errors detected by the [`TracyLayer`].
/// Apply handling for errors detected by the [`TracyLayer`](super::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
Expand All @@ -86,11 +85,11 @@ pub trait Config {
///
/// By default a message coloured in red is emitted to the tracy client.
fn on_error(&self, client: &Client, error: &'static str) {
client.color_message(error, 0xFF000000, self.stack_depth());
client.color_message(error, 0xFF000000, 0);
}
}

/// A default configuration of the [`TracyLayer`].
/// A default configuration of the [`TracyLayer`](super::TracyLayer).
///
/// This type does not allow for any adjustment of the configuration. In order to customize
/// the behaviour of the layer implement the [`Config`] trait for your own type.
Expand Down
4 changes: 2 additions & 2 deletions tracing-tracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ where
visitor.dest,
"event message is too long and was truncated",
),
self.config.stack_depth(),
self.config.stack_depth(event.metadata()),
);
}
if visitor.frame_mark {
Expand Down Expand Up @@ -253,7 +253,7 @@ where
"",
file,
line,
self.config.stack_depth(),
self.config.stack_depth(metadata),
),
id.into_u64(),
)
Expand Down
2 changes: 1 addition & 1 deletion tracing-tracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Config for CallstackConfig {
fn formatter(&self) -> &Self::Formatter {
self.0.formatter()
}
fn stack_depth(&self) -> u16 {
fn stack_depth(&self, _: &tracing_core::Metadata<'_>) -> u16 {
100
}
}
Expand Down

0 comments on commit d51df35

Please sign in to comment.