# open-telemetry/opentelemetry-python architecture

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

- Interactive diagram: https://gitdiagram.com/open-telemetry/opentelemetry-python
- Repository: https://github.com/open-telemetry/opentelemetry-python

## Overview

##### Main Components

a. Core Components:
- API Layer (`opentelemetry-api`)
- SDK Layer (`opentelemetry-sdk`)
- Semantic Conventions (`opentelemetry-semantic-conventions`)
- Protocol Definitions (`opentelemetry-proto`)

b. Signal Types:
- Traces (Stable)
- Metrics (Stable)
- Logs (Experimental)

c. Extension Points:
- Exporters
- Propagators
- Shims (OpenCensus, OpenTracing)

##### Component Relationships

**Top Level:**
**[Application Code] → [OpenTelemetry API] → [OpenTelemetry SDK] → [Exporters] → [Backend Systems]**

**With the following parallel components:**
- Propagators (Cross-cutting)
- Semantic Conventions (Cross-cutting)
- Shims (Integration Layer)

##### Detailed Component Breakdown

a. API Layer (Blue):
- Trace API
- Metrics API
- Logs API
- Context API
- Baggage API

b. SDK Layer (Green):
- Trace SDK (SpanProcessor, Sampler)
- Metrics SDK (MeterProvider, Views)
- Logs SDK (LoggerProvider)
- Resource SDK
- Configuration Components

c. Exporters (Yellow):
- OTLP (gRPC/HTTP)
- Zipkin
- Prometheus
- OpenCensus
- In-Memory (testing)

d. Propagators (Purple):
- B3
- Jaeger
- W3C TraceContext
- W3C Baggage

##### Implementation Details

- Labels for supported Python versions (3.8+)
- Version stability indicators
- Configuration paths
- Test coverage boundaries

##### Additional Elements

- Error handling flows
- Resource detection paths
- Instrumentation points
- Configuration options
- Sampling decisions
- Context propagation paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        direction TB
        API[API Component]:::api
        SDK[SDK Component]:::sdk
        EXP[Exporter]:::exporter
        PROP[Propagator]:::propagator
        STAB[Stable Connection]
        UNSTAB[Experimental]
        style STAB stroke-width:2px
        style UNSTAB stroke-width:2px,stroke-dasharray: 5 5
        
    end

    subgraph "Application Layer"
        APP[Application Code]
    end

    subgraph "API Layer"
        direction TB
        TRACE_API[Trace API]:::api
        METRICS_API[Metrics API]:::api
        LOGS_API[Logs API]:::api
        CONTEXT_API[Context API]:::api
        BAGGAGE_API[Baggage API]:::api
    end

    subgraph "SDK Layer"
        direction TB
        TRACE_SDK[Trace SDK]:::sdk
        METRICS_SDK[Metrics SDK]:::sdk
        LOGS_SDK[Logs SDK]:::sdk
        RESOURCE_SDK[Resource SDK]:::sdk
    end

    subgraph "Extension Points"
        direction TB
        subgraph "Exporters"
            direction TB
            OTLP[OTLP]:::exporter
            ZIPKIN[Zipkin]:::exporter
            PROMETHEUS[Prometheus]:::exporter
            OPENCENSUS_EX[OpenCensus]:::exporter
        end

        subgraph "Propagators"
            direction TB
            B3[B3]:::propagator
            JAEGER[Jaeger]:::propagator
            W3C_TRACE[W3C TraceContext]:::propagator
            W3C_BAG[W3C Baggage]:::propagator
        end

        subgraph "Shims"
            direction TB
            OPENCENSUS_SHIM[OpenCensus Shim]
            OPENTRACING_SHIM[OpenTracing Shim]
        end
    end

    subgraph "Cross-Cutting Concerns"
        SEMANTIC[Semantic Conventions]
        PROTO[Protocol Definitions]
    end

    subgraph "Backend Systems"
        BACKENDS[Observability Backends]
    end

    %% Connections
    APP --> TRACE_API & METRICS_API & LOGS_API
    TRACE_API --> TRACE_SDK
    METRICS_API --> METRICS_SDK
    LOGS_API -.-> LOGS_SDK
    
    TRACE_SDK & METRICS_SDK & LOGS_SDK --> OTLP & ZIPKIN & PROMETHEUS & OPENCENSUS_EX
    OTLP & ZIPKIN & PROMETHEUS & OPENCENSUS_EX --> BACKENDS

    %% Cross-cutting connections
    SEMANTIC -.-> APP & TRACE_SDK & METRICS_SDK & LOGS_SDK
    PROTO -.-> OTLP

    %% Propagator connections
    B3 & JAEGER & W3C_TRACE & W3C_BAG -.-> CONTEXT_API
    CONTEXT_API --> TRACE_SDK

    %% Shim connections
    OPENCENSUS_SHIM & OPENTRACING_SHIM -.-> TRACE_API

    %% Click events
    click TRACE_API "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api/src/opentelemetry/trace/"
    click METRICS_API "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api/src/opentelemetry/metrics/"
    click LOGS_API "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api/src/opentelemetry/_logs/"
    click CONTEXT_API "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api/src/opentelemetry/context/"
    click BAGGAGE_API "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api/src/opentelemetry/baggage/"
    
    click TRACE_SDK "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-sdk/src/opentelemetry/sdk/trace/"
    click METRICS_SDK "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-sdk/src/opentelemetry/sdk/metrics/"
    click LOGS_SDK "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-sdk/src/opentelemetry/sdk/_logs/"
    click RESOURCE_SDK "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-sdk/src/opentelemetry/sdk/resources/"
    
    click SEMANTIC "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-semantic-conventions/src/opentelemetry/semconv/"
    click PROTO "https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-proto/src/opentelemetry/proto/"
    
    click OTLP "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp/"
    click ZIPKIN "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin/"
    click PROMETHEUS "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-prometheus/"
    click OPENCENSUS_EX "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-opencensus/"
    
    click B3 "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-b3/"
    click JAEGER "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-jaeger/"
    
    click OPENCENSUS_SHIM "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opencensus-shim/"
    click OPENTRACING_SHIM "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opentracing-shim/"

    %% Styles
    classDef api fill:#2374ab
    classDef sdk fill:#2a9d8f
    classDef exporter fill:#e9c46a
    classDef propagator fill:#8338ec
```
