Metadata-Version: 2.5
Name: utestme
Version: 0.1.0
Summary: uTestMe server errors for Python apps: unhandled exceptions with their request, logged errors, and requests and 5xx per minute. Django, Flask, FastAPI/Starlette.
Project-URL: Homepage, https://utest.me
Author-email: uTestMe <hello@utest.me>
License-Expression: MIT
License-File: LICENSE
Keywords: django,errors,fastapi,flask,logging,monitoring
Classifier: Framework :: Django
Classifier: Framework :: FastAPI
Classifier: Framework :: Flask
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# utestme

uTestMe server errors for Python apps: every exception the app does not handle, with its traceback and the request it happened in, `logging.error` / `logger.exception`, and requests and 5xx per minute. Django, Flask, FastAPI / Starlette, or any script.

It never sends request bodies, headers, cookies or query strings, and uTestMe removes secrets from what it does send. It never changes how the app behaves. No dependencies; Python 3.8+.

## Install

```bash
pip install utestme
```

Get a key in uTestMe: **Logs → Add server or app → An app → Python**. Put it in the app's environment:

```bash
UTESTME_KEY=utm_sk_…
UTESTME_URL=https://utest.me
```

Start it where the app starts:

```python
import utestme

utestme.init(app="shop-api", release=os.environ.get("GIT_SHA"))
```

Then your framework's hook, one of:

```python
# Django — settings.py, first in MIDDLEWARE
MIDDLEWARE = ["utestme.django.UTestMeMiddleware", *MIDDLEWARE]

# Flask
utestme.flask.init_app(app)

# FastAPI / Starlette (any ASGI app)
app.add_middleware(utestme.asgi.UTestMeMiddleware)
```

Check it: `python -m utestme test` sends one test error.

## Anywhere else

```python
try:
    charge(order)
except PaymentError as error:
    utestme.capture_exception(error, tags={"job": "charge"})
    raise

utestme.capture_message("stock below zero", level="warn")
utestme.add_breadcrumb("charging order 12")
utestme.set_user(user.id)   # an id, never an email
utestme.flush()             # before a short-lived script or job ends
```

## Options

| `init(…)`          | Default                           | What it does                                                          |
| ------------------ | --------------------------------- | --------------------------------------------------------------------- |
| `key`              | `UTESTME_KEY`                     | The app's key. Without one, nothing is sent.                          |
| `url`              | `UTESTME_URL`, `https://utest.me` | Where uTestMe is.                                                     |
| `app`              | `UTESTME_APP`, the folder name    | The service's name on each error.                                     |
| `release`          | `UTESTME_RELEASE`                 | The version running, to tie errors to a deploy.                       |
| `environment`      | `UTESTME_ENVIRONMENT`             |                                                                       |
| `flush_interval`   | `5.0`                             | Seconds between sends (from a daemon thread, and at exit).            |
| `capture_uncaught` | `True`                            | `sys.excepthook` and `threading.excepthook`.                          |
| `capture_logging`  | `True`                            | ERROR / CRITICAL records are sent; INFO / WARNING become breadcrumbs. |
| `before_send`      |                                   | Change an event, or return `None` to drop it.                         |

An exception both caught by a framework hook and logged by the framework is sent once.
