Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tracing & Observability

rsActor provides comprehensive observability through the tracing crate.

Architecture

Tracing in rsActor has two layers:

  1. Core logging (always available): tracing::warn!, tracing::error!, tracing::debug! for lifecycle events, dead letters, and errors. The tracing crate is a required dependency.

  2. Instrumentation spans (opt-in via tracing feature): #[tracing::instrument] attributes that create structured spans with timing and context for actor lifecycle and message processing.

Enabling Instrumentation

[dependencies]
rsactor = { version = "0.14", features = ["tracing"] }
tracing = "0.1"
tracing-subscriber = "0.3"

What Gets Traced

Always Available (Core Logging)

  • Dead letter warnings with structured fields
  • Actor on_start success/failure
  • Actor on_stop errors
  • on_run errors
  • Reply channel failures

With tracing Feature (Instrumentation Spans)

SpanFieldsDescription
actor_lifecycleactor_id, actor_typeEntire actor lifecycle
actor_on_start—Initialization phase
actor_on_run—Each idle handler invocation
actor_on_stopkilledShutdown phase
actor_process_message—Each message processing
actor_tellactor_id, message_typeTell operation
actor_askactor_id, message_type, reply_typeAsk operation
actor_tell_with_timeoutactor_id, message_type, timeout_msTell with timeout
actor_ask_with_timeoutactor_id, message_type, reply_type, timeout_msAsk with timeout
actor_killactor_idKill signal
actor_stopactor_idStop signal

Setup Example

use tracing_subscriber;

#[tokio::main]
async fn main() {
    // Simple setup
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .with_target(false)
        .init();

    // Your actor code here...
}

Running with Tracing

# Basic logging (always works)
RUST_LOG=debug cargo run --example basic

# With instrumentation spans
RUST_LOG=debug cargo run --example tracing_demo --features tracing

Feature Flag Behavior

ConfigurationCore LoggingInstrumentation Spans
DefaultAvailableDisabled
features = ["tracing"]AvailableEnabled

The tracing feature only controls #[tracing::instrument] attributes. Core logging via tracing::warn!, tracing::error!, etc. is always available regardless of feature flags.

Running the Example

RUST_LOG=debug cargo run --example tracing_demo --features tracing