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
python3 -m logbrew_fastapi.examples --help
python3 -m logbrew_fastapi.examples --list
python3 -m logbrew_fastapi.examples readme-example
python3 -m logbrew_fastapi.examples real-user-smoke
python3 -m logbrew_fastapi.examples
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. Use span_id_factory only when tests need deterministic child span ids.
By default, transport failures do not break the FastAPI response path. Set raise_flush_errors=True in test environments when you want misconfigured transport behavior to fail loudly.
Use a clearly fake placeholder like LOGBREW_API_KEY in local examples and tests.
Project details
Release history Release notifications | RSS feed
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.0.tar.gz.
File metadata
- Download URL: logbrew_fastapi-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d05c7d6dbf5fd171546254989c1a91bfcbbfbb741ab5d6a02cfcee0346239f57
|
|
| MD5 |
ab89bddf7e4b3767a930b8cffecb63e1
|
|
| BLAKE2b-256 |
0733f9591da2deb9a6ec5fa99dd60b01b72d0ba22ed2d4bcfa0312f46b47b7fa
|
Provenance
The following attestation bundles were made for logbrew_fastapi-0.1.0.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.0.tar.gz -
Subject digest:
d05c7d6dbf5fd171546254989c1a91bfcbbfbb741ab5d6a02cfcee0346239f57 - Sigstore transparency entry: 1740659880
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@d683e2db4c986d443ac0d7d6725f3282d80bcbee -
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@d683e2db4c986d443ac0d7d6725f3282d80bcbee -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file logbrew_fastapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: logbrew_fastapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 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 |
81f7463874b6f22398c9d2e79817608ebdd5067c57662a39b99cdd4d0dbb03b9
|
|
| MD5 |
60c1e9b2cfd791511d14ce505e5c27a2
|
|
| BLAKE2b-256 |
cf64251bc7093e3bfed513ee920ba014c876a1237da35db4561267d8171e053f
|
Provenance
The following attestation bundles were made for logbrew_fastapi-0.1.0-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.0-py3-none-any.whl -
Subject digest:
81f7463874b6f22398c9d2e79817608ebdd5067c57662a39b99cdd4d0dbb03b9 - Sigstore transparency entry: 1740659882
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@d683e2db4c986d443ac0d7d6725f3282d80bcbee -
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@d683e2db4c986d443ac0d7d6725f3282d80bcbee -
Trigger Event:
workflow_dispatch
-
Statement type: