Metadata-Version: 2.5
Name: trailscope
Version: 0.1.0
Summary: Trailscope SDK for Python: non-blocking API request logging for Django, FastAPI/Starlette and Celery
Project-URL: Homepage, https://trailscope.pro
Project-URL: Source, https://github.com/karaa1122/trailscope
Project-URL: Documentation, https://trailscope.pro/docs/sdk-python/
Author: Trailscope contributors
License-Expression: Apache-2.0
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Logging
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: celery
Requires-Dist: celery>=5.3; extra == 'celery'
Provides-Extra: dev
Requires-Dist: celery>=5.6; extra == 'dev'
Requires-Dist: django<6,>=5.2; (python_version < '3.12') and extra == 'dev'
Requires-Dist: django>=6.1; (python_version >= '3.12') and extra == 'dev'
Requires-Dist: fastapi>=0.162; extra == 'dev'
Requires-Dist: httpx>=0.28; extra == 'dev'
Requires-Dist: mypy>=2.4; extra == 'dev'
Requires-Dist: pytest-asyncio>=1.4; extra == 'dev'
Requires-Dist: pytest>=9.1; extra == 'dev'
Requires-Dist: ruff>=0.17; extra == 'dev'
Requires-Dist: starlette<1.9,>=1.0; (python_version < '3.11') and extra == 'dev'
Requires-Dist: starlette>=1.9; (python_version >= '3.11') and extra == 'dev'
Provides-Extra: django
Requires-Dist: django>=4.2; extra == 'django'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.110; extra == 'fastapi'
Provides-Extra: starlette
Requires-Dist: starlette>=0.37; extra == 'starlette'
Description-Content-Type: text/markdown

# trailscope

The [Trailscope](https://github.com/karaa1122/trailscope) SDK for Python 3.10+: logs every request with its route, timing, user, journey keys and (on errors) bodies and stack, plus Celery jobs and log lines, without blocking your request path. No dependencies beyond the standard library.

```bash
pip install trailscope
```

## FastAPI / Starlette

```python
import trailscope
from trailscope.asgi import TrailscopeMiddleware

trailscope.init(service="orders-api")  # reads TRAILSCOPE_ENDPOINT and TRAILSCOPE_INGEST_KEY
app = FastAPI()
app.add_middleware(TrailscopeMiddleware)  # add it last, so it runs first
```

## Django

```python
MIDDLEWARE = ["trailscope.django.TrailscopeMiddleware", ...]  # first
TRAILSCOPE = {"service": "orders-api"}
```

## Celery and logging

```python
from trailscope.celery import instrument

instrument()  # in the web process and the worker, after trailscope.init()
logging.getLogger().addHandler(trailscope.TrailscopeHandler())
```

In request code: `trailscope.set_user(user_id)`, `trailscope.set_correlation("order_id", order_id)`.

Full documentation: [docs/sdk-python.md](https://github.com/karaa1122/trailscope/blob/main/docs/sdk-python.md).

## License

Apache-2.0
