Skip to main content

TraceForge Python SDK for unhandled panic logging

Project description

TraceForge SDK for Python

TraceForge is a powerful exception tracking and unhandled panic logging platform. This SDK allows you to seamlessly integrate TraceForge into any Python application, with native support for FastAPI and Django.

Installation

Install the SDK via pip:

pip install usetraceforge python-dotenv

Basic Configuration (Any Python App)

You can use TraceForge in any standard Python script. It automatically hooks into sys.excepthook to capture all unhandled exceptions across your entire application.

First, create a .env file in the root of your project:

TRACEFORGE_API_KEY="your_api_key_here"
TRACEFORGE_INGEST_URL="http://localhost:3001/ingest" # Your TraceForge backend URL

Then, initialize the SDK as early as possible in your application lifecycle:

import traceforge
from dotenv import load_dotenv

load_dotenv() # Load your .env file

# Automatically reads TRACEFORGE_API_KEY from the environment
traceforge.init() 

FastAPI Integration

If you are building a FastAPI application, TraceForge provides a native exception handler.

from fastapi import FastAPI
from traceforge.integrations import fastapi
import traceforge
from dotenv import load_dotenv

load_dotenv()
traceforge.init()

app = FastAPI()

# Register the TraceForge FastAPI exception handler
fastapi.init(app)

(Note: If you use completely custom exception handlers that catch Exception and return a JSONResponse, you can manually capture errors inside your handler by calling traceforge.capture_exception(exc)).


Django Integration

For Django applications, TraceForge provides a native Middleware.

  1. Initialize TraceForge at the top of your settings.py:
import traceforge
from dotenv import load_dotenv

load_dotenv()
traceforge.init()
  1. Add the TraceForge middleware to the END of your MIDDLEWARE list in settings.py:
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    # ... your other middlewares ...
    
    # Must be at the end to catch exceptions thrown by views
    'traceforge.integrations.django.TraceForgeMiddleware',
]

Manual Capturing

You can manually capture handled exceptions anywhere in your codebase without crashing your application:

import traceforge

try:
    1 / 0
except Exception as e:
    traceforge.capture_exception(e)

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

usetraceforge-1.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

usetraceforge-1.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file usetraceforge-1.0.2.tar.gz.

File metadata

  • Download URL: usetraceforge-1.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for usetraceforge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6e54df835c11444d3998a7a983c731e83aa020b70d966611ab58cf47366f25ad
MD5 e15344f713dc66ea7fad99b55d5d43e9
BLAKE2b-256 36eaa00c2065e4578df64511653c1dbce28064a70466722bb54a9d4ea0aa7520

See more details on using hashes here.

File details

Details for the file usetraceforge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: usetraceforge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for usetraceforge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d31891661be72775d872e5dbe2b35fd19d4d6fc8be637f2f853bdcfec8c5d7a3
MD5 d7cd42ea1fe4f73f46c81980df30a3e8
BLAKE2b-256 9d6e13252a583070c7729dc5b7fce48e2bf10772d23447c4aa317c33d38771bc

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