# getsentry/sentry-python architecture

> Architecture diagram of the GitHub repository getsentry/sentry-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/getsentry/sentry-python
- Repository: https://github.com/getsentry/sentry-python

## Overview

##### Main Components

a. Core Components:
- Client Layer (sentry_sdk/client.py)
- Transport Layer (sentry_sdk/transport.py)
- Hub & Scope Management (sentry_sdk/hub.py, sentry_sdk/scope.py)
- Event Processing Pipeline
- Serialization Layer (sentry_sdk/serializer.py)

b. Feature Modules:
- Tracing System
- Profiler
- Metrics Collection
- Session Management
- AI Monitoring
- Crons Management

c. Integration Layer:
Integrations into categories:
- Web Frameworks (Django, Flask, FastAPI, etc.)
- Task Queues (Celery, Huey, RQ)
- Database (SQLAlchemy, Redis, MongoDB)
- Cloud Platforms (AWS Lambda, GCP)
- AI/ML (OpenAI, Anthropic, LangChain)

**┌─────────────────────────────────────────────────────────────┐**
- Application Code                         │
- ┬─────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Sentry SDK Core                          │
- ┬─────────────┬────────────────┬───────────────┤
- Client     │    Hub      │    Scope       │   Transport   │
- ┴─────────────┴────────────────┴───────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Feature Modules                          │
- ┬─────────────┬────────────────┬───────────────┤
- Tracing    │  Profiler   │    Metrics     │   Sessions    │
- ┴─────────────┴────────────────┴───────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Integration Layer                           │
- ┬─────────────┬────────────────┬───────────────┤
- Web      │   Queue     │   Database     │    Cloud      │
- ┴─────────────┴────────────────┴───────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Sentry Backend                           │
- ┘

##### Important Relationships
- Event flow from application code through SDK components
- Integration points with various frameworks
- Data transformation and enrichment pipeline
- Communication patterns with Sentry backend

##### Additional Elements
- Version compatibility information
- Configuration flow
- Error handling paths
- Async vs sync operations

##### Implementation Details
- Numbered sequence indicators for event flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Application["Application Layer"]
        AppCode[Application Code]
    end

    subgraph Core["Core Components"]
        Client["Client"]:::core
        Hub["Hub"]:::core
        Scope["Scope"]:::core
        Transport["Transport"]:::core
        Serializer["Serializer"]:::core
    end

    subgraph Features["Feature Modules"]
        Tracing["Tracing"]:::feature
        Profiler["Profiler"]:::feature
        Metrics["Metrics"]:::feature
        Sessions["Sessions"]:::feature
        AI["AI Monitoring"]:::feature
        Crons["Crons"]:::feature
    end

    subgraph Integrations["Integration Layer"]
        direction TB
        subgraph Web["Web Frameworks"]
            Django["Django"]:::integration
            Flask["Flask"]:::integration
            FastAPI["FastAPI"]:::integration
        end

        subgraph Queue["Task Queues"]
            Celery["Celery"]:::integration
            Huey["Huey"]:::integration
            RQ["RQ"]:::integration
        end

        subgraph DB["Databases"]
            SQLAlchemy["SQLAlchemy"]:::integration
            Redis["Redis"]:::integration
            MongoDB["MongoDB"]:::integration
        end

        subgraph Cloud["Cloud Platforms"]
            AWS["AWS Lambda"]:::integration
            GCP["GCP"]:::integration
        end

        subgraph AIML["AI/ML"]
            OpenAI["OpenAI"]:::integration
            Anthropic["Anthropic"]:::integration
            LangChain["LangChain"]:::integration
        end
    end

    Backend["Sentry Backend"]:::backend

    %% Relationships
    AppCode --> Client
    Client --> Hub
    Hub --> Scope
    Hub --> Transport
    Client --> Serializer
    Transport --> Backend

    Client --> Features
    Features --> Transport

    Web --> Hub
    Queue --> Hub
    DB --> Hub
    Cloud --> Hub
    AIML --> Hub

    %% Click Events
    click Client "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/client.py"
    click Hub "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/hub.py"
    click Scope "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/scope.py"
    click Transport "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/transport.py"
    click Serializer "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/serializer.py"
    click Tracing "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/tracing.py"
    click Profiler "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/profiler/"
    click Metrics "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/metrics.py"
    click Sessions "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/sessions.py"
    click AI "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/ai/"
    click Crons "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/crons/"
    click Django "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/integrations/django/"
    click Flask "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/flask.py"
    click FastAPI "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/fastapi.py"
    click Celery "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/integrations/celery/"
    click Huey "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/huey.py"
    click RQ "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/rq.py"
    click SQLAlchemy "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/sqlalchemy.py"
    click Redis "https://github.com/getsentry/sentry-python/tree/master/sentry_sdk/integrations/redis/"
    click MongoDB "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/pymongo.py"
    click AWS "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/aws_lambda.py"
    click GCP "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/gcp.py"
    click OpenAI "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/openai.py"
    click Anthropic "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/anthropic.py"
    click LangChain "https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/langchain.py"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef feature fill:#4CAF50,stroke:#2E7D32,color:white
    classDef integration fill:#FF9800,stroke:#EF6C00,color:white
    classDef backend fill:#9E9E9E,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        CoreLegend["Core Component"]:::core
        FeatureLegend["Feature Module"]:::feature
        IntegrationLegend["Integration"]:::integration
        BackendLegend["Backend"]:::backend
    end
```
