Metadata-Version: 2.4
Name: bugle-sdk
Version: 0.1.1
Summary: Automatic request reporting middleware for Bugle
Author: Joe Georgeo Slamie
Project-URL: Homepage, https://jgeeking.com/
Keywords: bugle,wsgi,middleware,monitoring,fly
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# Bugle SDK

`bugle-sdk` is lightweight WSGI middleware that reports completed application
requests to a [Bugle](https://buggle.fly.dev) server. It works with Flask,
Django, and other WSGI applications. Reporting runs asynchronously and is
best-effort, so a reporting failure does not change the application's response.

## Install

```sh
pip install bugle-sdk
```

## Usage

Wrap your WSGI application once during startup. For Flask:

```python
from flask import Flask
from bugle_sdk import BugleMiddleware

app = Flask(__name__)
app.wsgi_app = BugleMiddleware(app.wsgi_app)
```

For Django, wrap the WSGI application in your WSGI entry point (commonly
`config/wsgi.py`):

```python
from django.core.wsgi import get_wsgi_application
from bugle_sdk import BugleMiddleware

application = get_wsgi_application()
application = BugleMiddleware(application)
```

## Configuration

On Fly.io, the SDK obtains a short-lived machine identity token automatically.
The app, machine, and organization are identified from that token.

For local testing or other non-Fly environments, configure the Bugle server URL,
the app name registered in Bugle, and the ingestion key using environment
variables:

```sh
export BUGLE_URL="http://localhost:8000"
export BUGLE_APP="my-app"
export BUGLE_INGESTION_KEY="your-local-ingestion-key"
```

`BUGLE_URL` is optional on Fly and defaults to the SDK's configured Bugle URL.
`BUGLE_APP` defaults to `FLY_APP_NAME`. `BUGLE_INGESTION_KEY` is intended only
as a shared-secret fallback outside Fly; keep it secret. Without Fly identity or
this key, the SDK does not send reports.

For direct configuration, `BugleMiddleware` also accepts `bugle_url`,
`app_name`, `machine`, and `ingestion_key` keyword arguments.

## Reported data

For each completed request, the SDK sends the app name, machine ID, HTTP method,
URL path, response status code, and duration in milliseconds to the Bugle
`/api/hit` endpoint. It does not include request or response bodies.

## Links

- [Bugle](https://buggle.fly.dev)
- [Source code](https://github.com/jgeeking/bugle-sdk)
- [Author website](https://jgeeking.com/)
