Skip to main content

Local tracing and debugging for FastAPI apps

Project description

TraceWise

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
  • 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]"

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

pip install "tracewise[httpx]"

Quick Start

from fastapi import FastAPI
import tracewise

app = FastAPI()

tracewise.init(
    app,
    capture_logs=True,
    instrument_httpx=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

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/orders
  • http://localhost:8000/error
  • http://localhost:8000/tracewise

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

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.1.0.tar.gz (118.0 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.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tracewise-0.1.0.tar.gz
  • Upload date:
  • Size: 118.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tracewise-0.1.0.tar.gz
Algorithm Hash digest
SHA256 698e9bce3a1adb944a6b9dbd426ca4538bfaec8c391bd1a870683ec8b26e2486
MD5 17f825a441611b22d403a472aa76abf0
BLAKE2b-256 7d8dc6601c19b042c550da736ac72cf6fa839c757819115b5335453eb9b8c7cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tracewise-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tracewise-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8c2013daf863b5912883a58875e73912492123573b8c12eae47b15fa48d1ea
MD5 69aed0f5928a525f4d5bcbf8c4b6661e
BLAKE2b-256 72e86956ce6aa906a66df2fba0cb231ae40cff40b46c6c42eb91b3057125ba58

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