Skip to main content

Push logs from your Python app to the Sentry dashboard — AI-powered service health monitoring

Project description

Sentry Logger SDK (Python)

Push logs from your Python app to the Sentry dashboard — zero code changes required.

Installation

pip install sentry-logger

Step 1 — Link your app (one-time)

sentry-logger init --app-name "my-service"

This opens a browser sign-in, registers your app, and saves credentials to ~/.sentry_logger/config.json. Check the linked app anytime with:

sentry-logger status

Step 2 — Add one line to main.py

from sentry_logger import init
init()  # that's it — nothing else to change anywhere

After this single call, everything flows to Sentry automatically:

Source Captured?
logging.info/warning/error/critical(...) in any module
print() anywhere in your app
Uvicorn / Gunicorn request logs
Unhandled exceptions (crashes)

You do not need to add logging.xxx() calls to individual functions or routes.

FastAPI example (zero changes to routes)

from sentry_logger import init
init()  # must be before FastAPI import so uvicorn loggers are hooked

from fastapi import FastAPI
app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}          # uvicorn logs this request automatically

@app.get("/items/{item_id}")
def read_item(item_id: int):
    print("processing item")           # print() is also captured
    return {"item_id": item_id}

How it works

init() attaches to the root Python logger, which means every library and module in your app already propagates logs to it. It also:

  • Redirects stdout/stderr through logging so print() is captured
  • Installs a sys.excepthook to log unhandled exceptions as CRITICAL
  • Flushes batches every 5 seconds or every 50 log lines (configurable)

Service grouping

Name your loggers after services to group them in the dashboard:

import logging
logger = logging.getLogger("PaymentService")
logger.warning("Payment retry attempt")   # shows under "PaymentService" tab

Uvicorn access logs appear under the uvicorn.access service group automatically.

Configuration reference

Parameter Default Description
api_key API key (sk_...). If omitted, loaded from CLI config
dsn Backend URL. Falls back to SENTRY_INGEST_URL env or production endpoint
batch_size 50 Send when buffer reaches this size
flush_interval_seconds 5.0 Auto-flush interval in seconds
redirect_print True Capture print() / stdout / stderr
capture_exceptions True Log unhandled crashes as CRITICAL

Explicit configuration

from sentry_logger import init

init(
    api_key="sk_...",
    dsn="http://localhost:9000",
    redirect_print=True,       # default
    capture_exceptions=True,   # default
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentry_logger-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sentry_logger-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file sentry_logger-0.1.1.tar.gz.

File metadata

  • Download URL: sentry_logger-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sentry_logger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 33b1f1e6bec27b3c777c88357083f4e12b8c42904c14e072a166cbd4613788eb
MD5 c1e74924aa8b6f3688f6de1d00a92cf6
BLAKE2b-256 5db31b4c289b199381e28f0f0afb619ba0a73ef52d7764602c32603b7b83d5b5

See more details on using hashes here.

File details

Details for the file sentry_logger-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sentry_logger-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sentry_logger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e971727a2a0ad71eb9b585203102bf9716e89586005758b58b05052b953ab550
MD5 09116120ae0bbe7f592093a2309aab05
BLAKE2b-256 696e6e0460435bc9421dfa88f9192c2aec9b9dddd4ca5c807bd5b9734300c808

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page