pub struct TracingConfig {
pub format: LogFormat,
pub writer: WriterConfig,
pub level_config: LevelConfig,
pub features: FeatureSet,
pub otel_config: OtelConfig,
pub global_subscriber: bool,
}tracing_subscriber_ext only.Expand description
Main configuration builder for tracing setup Default create a new tracing configuration with sensible defaults
Fields§
§format: LogFormatOutput format configuration
writer: WriterConfigOutput destination configuration
level_config: LevelConfigLevel filtering configuration
features: FeatureSetOptional features configuration
otel_config: OtelConfigOpenTelemetry configuration
global_subscriber: boolWhether to set the subscriber as global default
Implementations§
Source§impl TracingConfig
impl TracingConfig
Sourcepub fn with_format(self, format: LogFormat) -> Self
pub fn with_format(self, format: LogFormat) -> Self
Set the log format
Sourcepub fn with_pretty_format(self) -> Self
pub fn with_pretty_format(self) -> Self
Use pretty formatted output (development style)
Sourcepub fn with_json_format(self) -> Self
pub fn with_json_format(self) -> Self
Use JSON formatted output (production style)
Sourcepub fn with_full_format(self) -> Self
pub fn with_full_format(self) -> Self
Use full formatted output
Sourcepub fn with_compact_format(self) -> Self
pub fn with_compact_format(self) -> Self
Use compact formatted output
Sourcepub fn with_logfmt_format(self) -> Self
Available on crate feature logfmt only.
pub fn with_logfmt_format(self) -> Self
logfmt only.Use logfmt formatted output (requires ‘logfmt’ feature)
Sourcepub fn with_writer(self, writer: WriterConfig) -> Self
pub fn with_writer(self, writer: WriterConfig) -> Self
Set the output writer
Sourcepub fn with_stdout(self) -> Self
pub fn with_stdout(self) -> Self
Write logs to stdout
Sourcepub fn with_stderr(self) -> Self
pub fn with_stderr(self) -> Self
Write logs to stderr
Sourcepub fn with_log_directives(self, directives: impl Into<String>) -> Self
pub fn with_log_directives(self, directives: impl Into<String>) -> Self
Set log directives (takes precedence over environment variables), for example if you want to set it from cli arguments (verbosity)
Sourcepub fn with_default_level(self, level: LevelFilter) -> Self
pub fn with_default_level(self, level: LevelFilter) -> Self
Set the default log level
Sourcepub fn with_env_fallback(self, env_var: impl Into<String>) -> Self
pub fn with_env_fallback(self, env_var: impl Into<String>) -> Self
Add an environment variable fallback for log configuration
Sourcepub fn with_otel_trace_level(self, level: LevelFilter) -> Self
pub fn with_otel_trace_level(self, level: LevelFilter) -> Self
Set the OpenTelemetry trace level
Sourcepub fn with_file_names(self, enabled: bool) -> Self
pub fn with_file_names(self, enabled: bool) -> Self
Enable or disable file names in output
Sourcepub fn with_line_numbers(self, enabled: bool) -> Self
pub fn with_line_numbers(self, enabled: bool) -> Self
Enable or disable line numbers in output
Sourcepub fn with_thread_names(self, enabled: bool) -> Self
pub fn with_thread_names(self, enabled: bool) -> Self
Enable or disable thread names in output
Sourcepub fn with_thread_ids(self, enabled: bool) -> Self
pub fn with_thread_ids(self, enabled: bool) -> Self
Enable or disable thread IDs in output
Sourcepub fn with_span_events(self, events: FmtSpan) -> Self
pub fn with_span_events(self, events: FmtSpan) -> Self
Configure span event logging
Sourcepub fn without_span_events(self) -> Self
pub fn without_span_events(self) -> Self
Disable span event logging
Sourcepub fn with_uptime_timer(self, enabled: bool) -> Self
👎Deprecated: Use TracingConfig::with_timer instead
pub fn with_uptime_timer(self, enabled: bool) -> Self
TracingConfig::with_timer insteadEnable or disable uptime timer (vs wall clock)
Sourcepub fn with_timer(self, timer: LogTimer) -> Self
pub fn with_timer(self, timer: LogTimer) -> Self
Configure time logging (wall clock, uptime or none)
Sourcepub fn with_target_display(self, enabled: bool) -> Self
pub fn with_target_display(self, enabled: bool) -> Self
Enable or disable target display
Sourcepub fn with_metrics(self, enabled: bool) -> Self
pub fn with_metrics(self, enabled: bool) -> Self
Enable or disable metrics collection
Sourcepub fn with_resource_config(self, config: DetectResource) -> Self
pub fn with_resource_config(self, config: DetectResource) -> Self
Set resource configuration for OpenTelemetry
Sourcepub fn with_global_subscriber(self, global: bool) -> Self
pub fn with_global_subscriber(self, global: bool) -> Self
Set whether to initialize the subscriber as global default
When global is true (default), the subscriber is set as the global default.
When false, the subscriber is set as thread-local default and the returned
Guard must be kept alive to maintain the subscriber.
Sourcepub fn build_layer<S>(
&self,
) -> Result<Box<dyn Layer<S> + Send + Sync + 'static>, Error>where
S: Subscriber + for<'a> LookupSpan<'a>,
pub fn build_layer<S>(
&self,
) -> Result<Box<dyn Layer<S> + Send + Sync + 'static>, Error>where
S: Subscriber + for<'a> LookupSpan<'a>,
Build a tracing layer with the current configuration
Sourcepub fn build_filter_layer(&self) -> Result<EnvFilter, Error>
pub fn build_filter_layer(&self) -> Result<EnvFilter, Error>
Build a level filter layer with the current configuration
Sourcepub fn init_subscriber(self) -> Result<Guard, Error>
pub fn init_subscriber(self) -> Result<Guard, Error>
Initialize the tracing subscriber with this configuration
If global_subscriber is true, sets the subscriber as the global default.
If false, returns a Guard that maintains the subscriber as the thread-local default.
When OpenTelemetry is disabled, the Guard will contain None for the OtelGuard.
Sourcepub fn init_subscriber_ext<F, SOut>(self, transform: F) -> Result<Guard, Error>
pub fn init_subscriber_ext<F, SOut>(self, transform: F) -> Result<Guard, Error>
transform parameter allow to customize the registry/subscriber before
the setup of opentelemetry, log, logfilter.
let guard = TracingConfig::default()
.with_json_format()
.with_stderr()
.init_subscriber_ext(|subscriber| subscriber.with(my_layer))?;Sourcepub fn development() -> Self
pub fn development() -> Self
Configuration preset for development environments
- Pretty formatting with colors
- Output to stderr
- Line numbers and thread names enabled
- Span events for NEW and CLOSE
- Full OpenTelemetry integration
Sourcepub fn production() -> Self
pub fn production() -> Self
Configuration preset for production environments
- JSON formatting for structured logging
- Output to stdout
- Minimal metadata (no line numbers or thread names)
- No span events to reduce verbosity
- Full OpenTelemetry integration
Sourcepub fn debug() -> Self
pub fn debug() -> Self
Configuration preset for debugging
- Pretty formatting with full verbosity
- Output to stderr
- All metadata enabled
- Full span events
- Debug level logging
- Full OpenTelemetry integration
Trait Implementations§
Source§impl Debug for TracingConfig
impl Debug for TracingConfig
Auto Trait Implementations§
impl Freeze for TracingConfig
impl RefUnwindSafe for TracingConfig
impl Send for TracingConfig
impl Sync for TracingConfig
impl Unpin for TracingConfig
impl UnwindSafe for TracingConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request