Skip to main content

Bugle SDK

bugle-sdk is lightweight WSGI middleware that reports completed application requests to a Bugle 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

pip install bugle-sdk

Usage

Wrap your WSGI application once during startup. For Flask:

from flask import Flask
from bugle_sdk import BugleMiddleware

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

Endpoint labels and pseudonymous user fingerprints

The SDK assigns every event a random request_id and a non-empty fingerprint. For Flask route templates (for example, /users/<user_id> instead of /users/42) and a stable pseudonymous user identifier, set request metadata in an after_request hook:

from flask import g, request

@app.after_request
def attach_bugle_context(response):
    request.environ["bugle.endpoint"] = (
        request.url_rule.rule if request.url_rule else request.path
    )

    # Adapt this lookup to the app's authentication system.
    user = getattr(g, "current_user", None)
    user_id = getattr(user, "id", None)
    if user_id is not None:
        request.environ["bugle.identity"] = str(user_id)
    return response

Set BUGLE_FINGERPRINT_SECRET to a long, random secret shared by the app's instances. The SDK combines that secret with the app name and the identity provided by the app, then sends only an HMAC-SHA256 user_fingerprint with fingerprint_scope: "user"; it does not send the raw user ID, IP address, or user-agent. If the app does not supply an identity or the secret is absent, the SDK still sends a unique fingerprint for that request with fingerprint_scope: "request". That fallback does not identify the same anonymous user across requests. For anonymous user tracking, an app may provide a consented, first-party random device ID as bugle.identity.

To keep a real-time or other background polling route out of organic request counts, mark it as browser traffic in the same hook. The SDK marks the standard /socket.io path as browser traffic automatically; custom routes must be identified by the app:

if request.path.startswith(("/api/realtime/", "/api/notifications/poll")):
    request.environ["bugle.traffic_type"] = "browser"

Set request.environ["bugle.traffic_type"] = "user" only when an endpoint should override the backend's browser-route fallback. The backend recognizes browser and user; an unset value uses its safe-method route heuristics.

request_id identifies one request. user_fingerprint is always present; fingerprint_scope says whether it identifies a pseudonymous app user or only that request. Do not derive identity from IP address or browser/device characteristics.

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

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:

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, endpoint label, request ID, fingerprint and its scope, response status code, duration in milliseconds, and an optional traffic_type label to the Bugle /api/hit endpoint. It does not include request or response bodies.

Metadata

Release files for bugle-sdk 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bugle-sdk 1.1.2
File Size Uploaded Provenance Actions
bugle_sdk-1.1.2.tar.gz 5.5 kB Without provenance Details for bugle_sdk-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bugle-sdk 1.1.2
File Interpreter ABI Platform Actions
bugle_sdk-1.1.2-py3-none-any.whl Python 3 none any Details for bugle_sdk-1.1.2-py3-none-any.whl

Total release size: 11.1 kB

Release files / bugle_sdk-1.1.2.tar.gz

Download URL bugle_sdk-1.1.2.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
36a7c7c5a5475e43b803112633f5600331ad4dc011b4ba1bbb3897700339f669
BLAKE2b-256 checksum
How to use checksums
cf821910b91b111d2f1f6e23486331e08bae7d1a34f9ce99024c965f8023104a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / bugle_sdk-1.1.2-py3-none-any.whl

Download URL bugle_sdk-1.1.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23bdc543a480f0cf0d3a18c88981e36f4d54d32a777621a8fbf795384317ef70
BLAKE2b-256 checksum
How to use checksums
e575394e7c55a714eaf1af9c1ae25e7a92bd1c72db12d4fe7a6caf584f20cbc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for bugle-sdk 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page