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
httpxclient tracing withtraceparentpropagation - optional SQLAlchemy DB tracing with raw
db.statementcapture - 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 filemax_traces: max number of traces to keepenabled: turn tracing on or offcapture_logs: attach a logging handler that records log events on the active spaninstrument_httpx: record outboundhttpxrequests and injecttraceparentheadersinstrument_sqlalchemy: record SQLAlchemy statements as DBCLIENTspans and capture rawdb.statementtext 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/healthhttp://localhost:8000/usershttp://localhost:8000/db-usershttp://localhost:8000/ordershttp://localhost:8000/errorhttp://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
httpxtracing is optional and only applies if your app useshttpx- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tracewise-0.3.0.tar.gz.
File metadata
- Download URL: tracewise-0.3.0.tar.gz
- Upload date:
- Size: 83.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2efc5a72f27dc1e7f6ff9db4561e1076c446908c2b7d416758d00d09793f24b8
|
|
| MD5 |
f3864fd8199291f5dbbf80a872a5ca70
|
|
| BLAKE2b-256 |
2dd8e97fc0934c82fe4482b11856dbb45b21a9c2860a3f7b7cc5b2d73238d289
|
Provenance
The following attestation bundles were made for tracewise-0.3.0.tar.gz:
Publisher:
release.yml on Tanmoy-Sarkar-Pranto/tracewise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tracewise-0.3.0.tar.gz -
Subject digest:
2efc5a72f27dc1e7f6ff9db4561e1076c446908c2b7d416758d00d09793f24b8 - Sigstore transparency entry: 1238627758
- Sigstore integration time:
-
Permalink:
Tanmoy-Sarkar-Pranto/tracewise@8c154b90eefe079eeb5d022198f4b4dec1a5aa0a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Tanmoy-Sarkar-Pranto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c154b90eefe079eeb5d022198f4b4dec1a5aa0a -
Trigger Event:
push
-
Statement type:
File details
Details for the file tracewise-0.3.0-py3-none-any.whl.
File metadata
- Download URL: tracewise-0.3.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f476f451e5b23d622803a3cf05587c1c94266cd570e70f6c39bf5e4a71aed760
|
|
| MD5 |
d564193b4b190795390267bc80a2bacc
|
|
| BLAKE2b-256 |
69eef28ce0938c064853f9e64470fd6bcacd9eaa9266771f0ca50c8d7958d733
|
Provenance
The following attestation bundles were made for tracewise-0.3.0-py3-none-any.whl:
Publisher:
release.yml on Tanmoy-Sarkar-Pranto/tracewise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tracewise-0.3.0-py3-none-any.whl -
Subject digest:
f476f451e5b23d622803a3cf05587c1c94266cd570e70f6c39bf5e4a71aed760 - Sigstore transparency entry: 1238627764
- Sigstore integration time:
-
Permalink:
Tanmoy-Sarkar-Pranto/tracewise@8c154b90eefe079eeb5d022198f4b4dec1a5aa0a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Tanmoy-Sarkar-Pranto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c154b90eefe079eeb5d022198f4b4dec1a5aa0a -
Trigger Event:
push
-
Statement type: