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.2.tar.gz (9.1 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.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sentry_logger-0.1.2.tar.gz
  • Upload date:
  • Size: 9.1 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.2.tar.gz
Algorithm Hash digest
SHA256 7e184d15d9f83e21c7346471c16276b4bb023606b480cf3d989de2dbfcbd19c2
MD5 d8f12edc60f48c305970c8860ffeece9
BLAKE2b-256 da5576f45f18d0c4308d66833e33585915084d8e87b5b5caad26e612e4f83685

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sentry_logger-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c4e788bac25274882df86f944ba4ceccf1cef8773f1932193acbe45664d108c
MD5 fc511da181ad472ec0ed473b5687adc9
BLAKE2b-256 46fa2225f5727c4dd709c8c3f6d5610bd789c8ae7ffced70e34a9039668681a6

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