FastAPI integration for capturing LogBrew request spans and exceptions.
Project description
logbrew-fastapi
FastAPI integration for capturing LogBrew request spans and exceptions with the public Python SDK.
Install
python3 -m pip install logbrew-sdk logbrew-fastapi
The package is typed, ships py.typed, depends on the core logbrew-sdk, and keeps FastAPI as a normal framework dependency instead of bundling or monkeypatching the user's app.
Example
from fastapi import FastAPI
from logbrew_fastapi import add_logbrew_middleware
from logbrew_sdk import LogBrewClient, RecordingTransport
client = LogBrewClient.create(
api_key="LOGBREW_API_KEY",
sdk_name="logbrew-fastapi",
sdk_version="0.1.0",
)
transport = RecordingTransport.always_accept()
app = FastAPI()
add_logbrew_middleware(
app,
client=client,
transport=transport,
span_id_factory=lambda: "b7ad6b7169203331",
)
@app.get("/health")
def health() -> dict[str, bool]:
return {"ok": True}
add_logbrew_middleware() records successful requests as span events, records unhandled handler exceptions as issue plus error-span events, and flushes through the provided transport after each response. If no transport is provided, events stay queued on the core client so the app can flush them itself.
When an incoming request has a valid W3C traceparent header, request capture continues that trace by using the incoming traceId and parent span id while creating a fresh child span id. Missing or malformed traceparent headers keep the existing synthetic request span behavior so bad client headers do not break the app. Automatic metadata uses the request path without query text.
Request duration metrics are opt-in. Set capture_request_metrics=True to emit an explicit http.server.duration histogram for completed requests:
add_logbrew_middleware(
app,
client=client,
transport=transport,
capture_request_metrics=True,
)
The metric includes primitive, low-cardinality metadata: framework, method, routeTemplate, statusCode, and statusCodeClass. Query strings and URL hashes are omitted. Set capture_successful_requests=False with capture_request_metrics=True when you only want duration metrics and not successful request spans. Avoid user IDs, request payloads, headers, or free-form text in custom metric metadata.
By default, transport failures do not break the FastAPI response path. Set raise_flush_errors=True only when your app wants delivery failures to surface as request errors.
Use a clearly fake placeholder like LOGBREW_API_KEY in examples.
Project details
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 logbrew_fastapi-0.1.2.tar.gz.
File metadata
- Download URL: logbrew_fastapi-0.1.2.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
307c6ff9895d0261d0602dfba49753b05823d0aded2ffd795d2f44bf1fa87947
|
|
| MD5 |
4ffcfbad82e6f80932a27ba25f9acc5f
|
|
| BLAKE2b-256 |
2f5faf11da1aff94c84b0ace5c2af4f69e46614cffef9eafaa3b78ec7d0c7b70
|
Provenance
The following attestation bundles were made for logbrew_fastapi-0.1.2.tar.gz:
Publisher:
publish-packages.yml on LogBrewCo/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logbrew_fastapi-0.1.2.tar.gz -
Subject digest:
307c6ff9895d0261d0602dfba49753b05823d0aded2ffd795d2f44bf1fa87947 - Sigstore transparency entry: 1803567727
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@25602ef6d516d404c668487c5fcc5c0b09fd875b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LogBrewCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-packages.yml@25602ef6d516d404c668487c5fcc5c0b09fd875b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file logbrew_fastapi-0.1.2-py3-none-any.whl.
File metadata
- Download URL: logbrew_fastapi-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd577e9b3b8d41ada1458af187d70d7040d053c16d4549741af2a7614246fd7a
|
|
| MD5 |
880c31875ae387d753e8f41c97018baf
|
|
| BLAKE2b-256 |
8fac0c91867f764c3713f6e57e2376419cff10e1912903e9483f5a0f146bc38b
|
Provenance
The following attestation bundles were made for logbrew_fastapi-0.1.2-py3-none-any.whl:
Publisher:
publish-packages.yml on LogBrewCo/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logbrew_fastapi-0.1.2-py3-none-any.whl -
Subject digest:
cd577e9b3b8d41ada1458af187d70d7040d053c16d4549741af2a7614246fd7a - Sigstore transparency entry: 1803567738
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@25602ef6d516d404c668487c5fcc5c0b09fd875b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LogBrewCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-packages.yml@25602ef6d516d404c668487c5fcc5c0b09fd875b -
Trigger Event:
workflow_dispatch
-
Statement type: