Skip to main content

Error tracking and LLM monitoring for Python applications

Project description

FailSense Python SDK

PyPI version Python 3.8+ License: MIT

Error tracking and LLM monitoring for Python applications.

Features

  • Error Tracking - Automatic exception capture with stack traces
  • Monitor Tracking - Cron job and uptime monitoring
  • AI Tracer - LLM API call monitoring (tokens, cost, latency)
  • Session Replay - User session recording
  • Breadcrumbs - Track user actions before errors
  • Zero Config - Works out of the box

Installation

pip install failsense

Quick Start

1. Get Your API Key

Sign up at failsense.com and get your API key from Settings.

2. Initialize the SDK

from failsense import Client

fs = Client(
    dsn="https://api.failsense.com",
    api_key="fs_live_..."  # Your API key
)

3. Track Errors

try:
    1 / 0
except Exception:
    fs.capture_exception()

4. Monitor LLM Calls

from openai import OpenAI

# Wrap your LLM client
raw_client = OpenAI(api_key="sk-...")
client = fs.monitor(raw_client, tracer_id=1)

# Use normally - automatically tracked!
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Usage Examples

Error Tracking

from failsense import Client

fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

# Automatic exception capture
try:
    risky_operation()
except Exception:
    fs.capture_exception()

# With additional context
try:
    process_user(user_id=123)
except Exception:
    fs.capture_exception(context={"user_id": 123, "action": "process"})

Breadcrumbs

# Track user actions
fs.add_breadcrumb("navigation", "User clicked checkout")
fs.add_breadcrumb("http", "API call to /payment", data={"amount": 99.99})

# Breadcrumbs are automatically attached to errors
try:
    process_payment()
except Exception:
    fs.capture_exception()  # Includes breadcrumbs

Monitor Tracking

# Cron job monitoring
from failsense import Client

fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

def daily_backup():
    try:
        backup_database()
        fs.check_in_monitor(monitor_id=1, status="ok")
    except Exception as e:
        fs.check_in_monitor(monitor_id=1, status="error", metadata={"error": str(e)})

AI Tracer (LLM Monitoring)

from failsense import Client
from openai import OpenAI

fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

# Wrap your LLM client
raw_client = OpenAI(api_key="sk-...")
client = fs.monitor(raw_client, tracer_id=1)

# All calls are automatically tracked
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Explain quantum physics"}]
)

# Tracks:
# - Tokens used (input/output)
# - Latency
# - Cost estimation
# - Errors (with full prompt for debugging)

Configuration

DSN Options

# Production
fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

# Self-hosted
fs = Client(dsn="https://failsense.yourcompany.com", api_key="...")

# Local development
fs = Client(dsn="http://localhost:8000", api_key="...")

Graceful Shutdown

import atexit

fs = Client(dsn="...", api_key="...")

# Flush pending events on exit
atexit.register(fs.close)

Framework Integration

Django

# settings.py
FAILSENSE_DSN = "https://api.failsense.com"
FAILSENSE_API_KEY = "fs_live_..."

# middleware.py
from failsense import Client

fs = Client(dsn=settings.FAILSENSE_DSN, api_key=settings.FAILSENSE_API_KEY)

class FailsenseMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        try:
            response = self.get_response(request)
            return response
        except Exception:
            fs.capture_exception(context={"path": request.path})
            raise

Flask

from flask import Flask
from failsense import Client

app = Flask(__name__)
fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

@app.errorhandler(Exception)
def handle_exception(e):
    fs.capture_exception()
    return "Internal Server Error", 500

FastAPI

from fastapi import FastAPI, Request
from failsense import Client

app = FastAPI()
fs = Client(dsn="https://api.failsense.com", api_key="fs_live_...")

@app.middleware("http")
async def failsense_middleware(request: Request, call_next):
    try:
        response = await call_next(request)
        return response
    except Exception:
        fs.capture_exception(context={"path": request.url.path})
        raise

Supported LLM Providers

  • ✅ OpenAI (GPT-3.5, GPT-4)
  • ✅ Anthropic (Claude 3)
  • ✅ Google (Gemini)
  • ✅ Any provider with chat.completions.create() interface

Requirements

  • Python 3.8 or higher
  • requests>=2.25.0

License

MIT License - see LICENSE file for details.

Links

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

0.1.0 (2026-01-17)

  • Initial release
  • Error tracking
  • Monitor tracking
  • AI Tracer (LLM monitoring)
  • Breadcrumbs
  • Session replay support

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

failsense-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

failsense-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file failsense-0.1.0.tar.gz.

File metadata

  • Download URL: failsense-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for failsense-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad0746440e04bbdb8702672a65a5b37607b6f4586e9e09cd7375629dc0a6e46e
MD5 a20967174f62211874a412314b20e2e4
BLAKE2b-256 2c230b854cbc0ce73f6e074f99173d1f3bdf91016fd09632f1ede86e6266c276

See more details on using hashes here.

File details

Details for the file failsense-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: failsense-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for failsense-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bad215b427d4a6fa456b0b3184a3f310449cc0c92b583f3cf41c15c60d8b6a7
MD5 c009282fe28c92e9dba220042979449a
BLAKE2b-256 acaa26ea1f38bc95eb3f6b09406ddcd18787d3d06007ff17da7754e61bdd5a70

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