# tokio-rs/tracing architecture

> Architecture diagram of the GitHub repository tokio-rs/tracing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tokio-rs/tracing
- Repository: https://github.com/tokio-rs/tracing

## Overview

##### Main Components

a) Core Components:
- tracing-core: The fundamental primitives layer
- tracing: The main instrumentation API
- tracing-subscriber: The collector implementation layer

b) Integration Components:
- tracing-futures: Async/futures integration
- tracing-attributes: Procedural macros
- tracing-log: Log compatibility layer
- tracing-appender: Output handling
- tracing-error: Error instrumentation
- tracing-flame: Flame graph generation

**┌─────────────────────────────────────────────────────────────────┐**
- Application Layer                           │
- ┬─────────────────────────────────┘

**┌───────────────────────────────▼─────────────────────────────────┐**
- Instrumentation Layer                        │
- ┌─────────────┐    ┌──────────────┐    ┌──────────────────┐   │
- tracing   │◄──►│ tracing-attr │◄──►│ tracing-futures  │   │
- ┬──────┘    └──────────────┘    └──────────────────┘   │

- ┌──────▼──────┐                                               │
- tracing-core │                                               │
- ┬──────┘                                               │
- ┼──────────────────────────────────────────────────────┘

**┌─────────▼──────────────────────────────────────────────────────┐**
- Collector Layer                             │
- ┌─────────────────┐    ┌──────────────┐   ┌───────────────┐   │
- tracing-subscriber│──►│tracing-appender│  │tracing-flame  │   │
- ┘    └──────────────┘   └───────────────┘   │
- ┘

**┌─────────▼──────────────────────────────────────────────────────┐**
- Output Targets                              │
- ┌─────────┐  ┌─────────┐  ┌──────────┐  ┌──────────────────┐  │
- Files  │  │  Stdout │  │ Journald │  │ Flame Graphs     │  │
- ┘  └─────────┘  └──────────┘  └──────────────────┘  │
- ┘

##### Important Relationships to Highlight
- How tracing-core provides the foundation for all other components
- How tracing-subscriber acts as a bridge between instrumentation and output
- Demonstrate how different output formats are handled through the collector layer

##### Additional Elements
- Version compatibility information
- Integration points with external systems (log crate, async runtimes)

##### Implementation Details
- Use standardized UML notation where appropriate

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef integration fill:#90ee90,stroke:#333
    classDef collector fill:#ffd700,stroke:#333
    classDef output fill:#dda0dd,stroke:#333
    classDef layer fill:none,stroke:#333,stroke-dasharray: 5 5

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        App[Application Code]
    end

    %% Instrumentation Layer
    subgraph InstrumentLayer["Instrumentation Layer"]
        Tracing["tracing"]
        TracingCore["tracing-core"]
        TracingAttr["tracing-attributes"]
        TracingFutures["tracing-futures"]
        TracingLog["tracing-log"]
        TracingError["tracing-error"]
        
        CorePrimitives["Core Primitives"]
        MainInstr["Main Instrumentation"]
        AsyncRuntime["Async Runtime Support"]
        ErrorHandling["Error Handling"]
        LogCompat["Log Compatibility"]
    end

    %% Collector Layer
    subgraph CollectorLayer["Collector Layer"]
        TracingSub["tracing-subscriber"]
        TracingAppender["tracing-appender"]
        TracingFlame["tracing-flame"]
        
        CollectorImpl["Collector Implementation"]
        Formatting["Formatting & Output"]
        Filtering["Filtering System"]
    end

    %% Output Layer
    subgraph OutputLayer["Output Targets"]
        FileOutput["File Output"]
        JournaldOutput["Journald Output"]
        FlameOutput["Flame Graph Output"]
    end

    %% Relationships
    App --> Tracing
    Tracing --> TracingCore
    TracingCore --> TracingSub
    Tracing --> TracingAttr
    Tracing --> TracingFutures
    Tracing --> TracingLog
    Tracing --> TracingError
    
    TracingSub --> TracingAppender
    TracingSub --> TracingFlame
    
    TracingAppender --> FileOutput
    TracingAppender --> JournaldOutput
    TracingFlame --> FlameOutput

    %% Component Details
    TracingCore --> CorePrimitives
    Tracing --> MainInstr
    TracingFutures --> AsyncRuntime
    TracingError --> ErrorHandling
    TracingLog --> LogCompat
    TracingSub --> CollectorImpl
    TracingSub --> Formatting
    TracingSub --> Filtering

    %% Click Events
    click TracingCore "https://github.com/tokio-rs/tracing/tree/master/tracing-core/src/"
    click Tracing "https://github.com/tokio-rs/tracing/tree/master/tracing/src/"
    click TracingSub "https://github.com/tokio-rs/tracing/tree/master/tracing-subscriber/src/"
    click TracingFutures "https://github.com/tokio-rs/tracing/tree/master/tracing-futures/src/"
    click TracingAttr "https://github.com/tokio-rs/tracing/tree/master/tracing-attributes/src/"
    click TracingLog "https://github.com/tokio-rs/tracing/tree/master/tracing-log/src/"
    click TracingAppender "https://github.com/tokio-rs/tracing/tree/master/tracing-appender/src/"
    click TracingError "https://github.com/tokio-rs/tracing/tree/master/tracing-error/src/"
    click TracingFlame "https://github.com/tokio-rs/tracing/tree/master/tracing-flame/src/"
    click CollectorImpl "https://github.com/tokio-rs/tracing/tree/master/tracing-subscriber/src/subscribe/"
    click Formatting "https://github.com/tokio-rs/tracing/tree/master/tracing-subscriber/src/fmt/"
    click Filtering "https://github.com/tokio-rs/tracing/tree/master/tracing-subscriber/src/filter/"
    click CorePrimitives "https://github.com/tokio-rs/tracing/blob/master/tracing-core/src/span.rs"
    click MainInstr "https://github.com/tokio-rs/tracing/blob/master/tracing/src/instrument.rs"
    click FileOutput "https://github.com/tokio-rs/tracing/tree/master/tracing-appender/src/rolling/"
    click JournaldOutput "https://github.com/tokio-rs/tracing/tree/master/tracing-journald/src/"
    click FlameOutput "https://github.com/tokio-rs/tracing/tree/master/tracing-flame/src/"
    click AsyncRuntime "https://github.com/tokio-rs/tracing/tree/master/tracing-futures/src/executor/"
    click ErrorHandling "https://github.com/tokio-rs/tracing/blob/master/tracing-error/src/error.rs"
    click LogCompat "https://github.com/tokio-rs/tracing/blob/master/tracing-log/src/log_tracer.rs"

    %% Style Applications
    class Tracing,TracingCore core
    class TracingAttr,TracingFutures,TracingLog,TracingError integration
    class TracingSub,TracingAppender,TracingFlame collector
    class FileOutput,JournaldOutput,FlameOutput output
```
