Skip to main content

Local tracing and debugging for FastAPI apps

Project description

TraceWise

PyPI version

TraceWise is a small tracing and debugging tool for FastAPI apps.

It records request spans to a local SQLite database and mounts a built-in viewer at /tracewise so you can inspect traces while developing.

Current scope:

  • inbound FastAPI request tracing
  • manual spans with tracewise.start_span(...)
  • decorator-based spans with @tracewise.trace_span(...)
  • span attributes and events
  • optional log capture
  • optional httpx client tracing with traceparent propagation
  • optional SQLAlchemy DB tracing with raw db.statement capture
  • local SQLite storage and a minimal embedded UI

This is aimed at local development and debugging. It is not trying to be a full APM or a hosted tracing backend.

Install

For local development in this repo:

uv sync --extra dev

Or with pip:

pip install -e .

If you want instrument_httpx=True, install the optional extra:

pip install -e ".[httpx]"

If you want instrument_sqlalchemy=True, install the optional extra:

pip install -e ".[sqlalchemy]"

If you want both optional instrumentations from the Quick Start example:

pip install -e ".[httpx,sqlalchemy]"

For a published package install, the same extra would be:

pip install "tracewise[httpx]"

For a published package install:

pip install "tracewise[sqlalchemy]"

For the published package with both optional instrumentations:

pip install "tracewise[httpx,sqlalchemy]"

Quick Start

from fastapi import FastAPI
import tracewise

app = FastAPI()

tracewise.init(
    app,
    capture_logs=True,
    instrument_httpx=True,
    instrument_sqlalchemy=True,
)


@app.get("/users")
async def list_users():
    async with tracewise.start_span("db.query", table="users", operation="SELECT"):
        pass

    tracewise.set_attribute("result.count", 2)
    tracewise.add_event("users.loaded")

    return {"users": []}

Once the app is running:

  • make a request to one of your routes
  • open /tracewise
  • inspect the recorded trace tree

API Surface

Top-level helpers currently exposed by the package:

  • tracewise.init(app, ...)
  • tracewise.get_current_span()
  • tracewise.start_span(name, **attributes)
  • tracewise.trace_span(name, attributes=...)
  • tracewise.set_attribute(key, value)
  • tracewise.set_attributes({...})
  • tracewise.add_event(name, **attributes)

Main init() options:

  • db_path: path to the SQLite database file
  • max_traces: max number of traces to keep
  • enabled: turn tracing on or off
  • capture_logs: attach a logging handler that records log events on the active span
  • instrument_httpx: record outbound httpx requests and inject traceparent headers
  • instrument_sqlalchemy: record SQLAlchemy statements as DB CLIENT spans and capture raw db.statement text without parameter payloads

If db_path is not provided, TraceWise stores data under ~/.tracewise/traces.db.

You can also disable tracing with:

TRACEWISE_ENABLED=false

Example App

A small example app lives in tests/testapp/main.py.

To run it with Docker:

docker compose -f docker/docker-compose.yml up --build

Then open:

  • http://localhost:8000/health
  • http://localhost:8000/users
  • http://localhost:8000/db-users
  • http://localhost:8000/orders
  • http://localhost:8000/error
  • http://localhost:8000/tracewise

To generate DB spans in the demo app:

curl http://localhost:8000/db-users
curl -X POST http://localhost:8000/db-users \
  -H "Content-Type: application/json" \
  -d '{"name":"Charlie"}'

Current Limitations

  • FastAPI-specific for now
  • local SQLite storage only
  • viewer UI is intentionally minimal
  • httpx tracing is optional and only applies if your app uses httpx
  • not a replacement for OpenTelemetry or a hosted tracing stack

Verification And Releases

Pushes and pull requests run automated verification in GitHub Actions.

Releases are tag-driven: pushing vX.Y.Z only publishes when pyproject.toml already contains X.Y.Z.

The release pipeline reuses the verification workflow, validates built artifacts before publish, publishes to real PyPI via GitHub Actions OIDC / PyPI Trusted Publishing, and creates the matching GitHub release.

Development

Run the tests with:

uv run pytest

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

tracewise-0.2.0.tar.gz (79.1 kB view details)

Uploaded Source

Built Distribution

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

tracewise-0.2.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file tracewise-0.2.0.tar.gz.

File metadata

  • Download URL: tracewise-0.2.0.tar.gz
  • Upload date:
  • Size: 79.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracewise-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bc841482e321d7bdca55a7bfa34eeaef8429075085efa65b0efa0f29866194ce
MD5 5f3d55e0873a84312424f9b6fb59d5c6
BLAKE2b-256 2954c029535794044eee7c6141a4f7f7806fca4994a091ad64a59ce9ff29cee1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracewise-0.2.0.tar.gz:

Publisher: release.yml on Tanmoy-Sarkar-Pranto/tracewise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracewise-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tracewise-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracewise-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d293e6231e1ab36898485950a61eddaa0c8e9a0ea35e92c96b7a03dc9d9cbfa
MD5 9bd3231044091bf31234a660d033bcf7
BLAKE2b-256 9f4a90b82a46c8fec74a16ca0808184a6caa058548ef1f8c63aa75b5d05bfb3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracewise-0.2.0-py3-none-any.whl:

Publisher: release.yml on Tanmoy-Sarkar-Pranto/tracewise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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