Skip to main content

Crate tracing_declarative

Crate tracing_declarative 

Source
Expand description

tracing-declarative — Declarative tracing initialization via tracing.toml.

§Quick start

Create a tracing.toml in your project root:

[global]
level = "info"
ansi = true

[filter]
default_level = "info"

[[appender]]
name = "stdout"
kind = "stdout"
enabled = true

[appender.formatter]
type = "logback"
pattern = "%d [%thread] %-5level %logger{36} - %msg%n"

Then initialize in your main:

tracing_declarative::init().expect("tracing init failed");
tracing::info!("application started");

§Configuration search path

init() looks for tracing.toml in this order:

  1. TRACING_CONFIG environment variable
  2. ./tracing.toml (current working directory)
  3. ./tracing.toml (executable directory)

If no file is found, a built-in default is used (INFO level, stdout, default formatter).

§Feature flags

  • hot-reload (default) — File-watch support (unstable; tracing does not support re-initialization, so this is a no-op in practice).
  • opentelemetry — OpenTelemetry OTLP trace export via HTTP/protobuf.

§Supported formatter engines

typeSyntaxModule
"default"tracing-subscriber built-informatter::default
"logback"logback conversion wordsformatter::logback
"log4j"log4j PatternLayoutformatter::log4j

Modules§

appender
Appender module (currently empty — logic lives in lib.rs). Appender module — intentionally empty.
config
Configuration structures parsed from tracing.toml. Configuration structures parsed from tracing.toml.
error
Error types. Error types for tracing-config.
formatter
Formatter engines (default, logback, log4j). Formatter implementations.
sampling
Sampling / rate-limiting writer. Sampling/Rate limiting layer for tracing events.
span_fields
Span field capture layer (%X{key} / %mdc support). Span field capture layer for %X{key} / %mdc support.
windows
Windows console ANSI support. Windows console support for ANSI color escape codes.

Constants§

CRATE_NAME
Crate name (injected by build.rs).
CRATE_VERSION
Crate version (injected by build.rs).

Functions§

init
Initialize tracing from the default tracing.toml search path.
init_from_file
Initialize tracing from a specific file path.
init_from_str
Initialize tracing from a TOML string.
parse
Parse configuration without initializing tracing.
try_init_from_strDeprecated
Try to initialize tracing from a TOML string.