Skip to main content

seleniumbase-rs uses the tracing ecosystem for structured logging. Both the sbrs CLI and the sbrs-mcp server initialize a default tracing_subscriber::fmt() subscriber on startup. This page explains how to control verbosity, configure runtime settings through the environment, and use tracing in your own tests.

Info

What you will learn

  • How to set log levels with RUST_LOG.
  • How SB_* environment variables configure runtime behavior.
  • How spans and structured errors help diagnose failures.
  • How to use tracing in your own async code.

Log levels#

Set the RUST_LOG environment variable to control verbosity:

Terminal

RUST_LOG follows the standard env_logger/tracing-subscriber syntax:

Terminal

Runtime configuration (SB_* environment variables)#

Following Twelve-Factor III (config in the environment), sbrs and the library read runtime settings from SB_* variables:

SB_WEBDRIVER_URLstring#

WebDriver endpoint.

Default: "http://localhost:4444"

SB_CHROME_BINstring#

Explicit Chrome/Chromium binary path.

Default: "auto-detect"

SB_PATCH_CACHE_DIRstring#

Directory for patched Chrome/Chromedriver copies.

Default: "platform cache dir"

SB_LOG_LEVELstring#

The tracing filter (debug, seleniumbase_rs=debug,info). Unset, blank or invalid, sbrs and sbrs-mcp use RUST_LOG, then info.

SB_LOG_FORMATstring#

pretty or json output.

Default: "pretty"

SB_SHUTDOWN_TIMEOUT_SECSinteger#

Graceful shutdown timeout.

Default: "30"

SB_CHROMEDRIVER_PORTinteger#
Not read yet

Parsed into RuntimeConfig::chromedriver_port; nothing in the crate reads it yet.

Default: "0"

SB_IMPLICIT_WAIT_SECSinteger#
Not read yet

Parsed into RuntimeConfig::implicit_wait; nothing in the crate reads it yet.

Default: "30"

Terminal

One bad value does not undo the others: with SB_SHUTDOWN_TIMEOUT_SECS=soon sbrs still honours SB_LOG_LEVEL=debug, uses the default timeout and logs a warning that names the variable. A program that builds the configuration itself can do the same with RuntimeConfig::from_env_lenient(), which returns the configuration and the list of problems.

Spans in the library#

Key BaseCase and BrowserSession methods are instrumented with tracing spans so you can see where time is spent:

  • BaseCase::new
  • BaseCase::with_session
  • BaseCase::open, click, type_text, quit
  • BrowserSession::connect

Example output:

Using tracing in your own tests#

Tauri multi-profile example#

The Tauri app also initializes tracing_subscriber in src-tauri/src/lib.rs. Its REST API logs each endpoint call so you can correlate UI actions with local HTTP requests.

Error diagnostics#

Errors are emitted as structured tracing::error! events. Each event includes:

error.categorystring#

Stable tag such as element_not_found or browser_launch.

error.transientboolean#

Whether the failure is retryable.

error.hintstring#

A short remediation suggestion.

Example output:

You can also log errors manually:

Tip

Enable the full-tracing feature for additional timing histograms and Actix actor instrumentation.

Watching async tasks with tokio-console#

Feature: tokio-console

When something hangs, tokio-console shows every async task live: which ones are waiting, for how long, and on what.

Run with the instrumentation

Build with the tokio-console feature and tokio’s unstable instrumentation (both are for debugging only and make the program bigger):

Start the console

In another terminal:

It connects to 127.0.0.1:6669. Your own program gets the same when it calls seleniumbase_rs::tracing_util::init_tracing() with the feature on.

Troubleshooting#

No log output

Likely cause: Subscriber not initialized.

Fix: Run through sbrs, sbrs-mcp, or call tracing_subscriber::fmt::init() in your main().

Too much noise from dependencies

Likely cause: RUST_LOG=debug includes all crates.

Fix: Scope to seleniumbase_rs=debug.

JSON format not working

Likely cause: SB_LOG_FORMAT=json unsupported by default subscriber.

Fix: Use a custom subscriber or enable the full-tracing feature.

Shutdown timeout errors

Likely cause: SB_SHUTDOWN_TIMEOUT_SECS too low.

Fix: Increase it for slow CI agents.