Skip to content

feat(runtime): adopt tracing-panic to bring panic! into tracing events #121

@humancto

Description

@humancto

Background

PR #118 left the open work to bring panic! calls outside HTTP handlers (e.g. inside start_server setup, inside a schedule {} block on a different task) into the tracing event stream. Today panics in those paths go to the default panic hook → stderr, unstructured, no tracing event with span context.

What to add

Install tracing-panic's panic hook in init_subscriber:

use tracing_panic::panic_hook;

pub fn init_subscriber() {
    INIT.get_or_init(|| {
        // ... existing layer setup ...

        // After layer install, wrap the panic hook so panic!s become
        // structured tracing::error! events.
        std::panic::set_hook(Box::new(panic_hook));
    });
}

~3 lines + a Cargo.toml entry. Documented on the tracing-panic README.

Origin: rust-expert review on PR #118, follow-up #3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions