Skip to main content

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.

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

logbrew_fastapi-0.1.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logbrew_fastapi-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file logbrew_fastapi-0.1.1.tar.gz.

File metadata

  • Download URL: logbrew_fastapi-0.1.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for logbrew_fastapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb6ab9292f308b3cbc19bcd142b418a5675a13ea64ff11f485a6aaadb0d870f6
MD5 d535350e99249cfa2b7a6611e051a1ae
BLAKE2b-256 b36919cd01daea21c508861660b5818f2a5e30a9947b9126d01141330fe0a5ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for logbrew_fastapi-0.1.1.tar.gz:

Publisher: publish-packages.yml on LogBrewCo/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logbrew_fastapi-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for logbrew_fastapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df3dd360baf4478ce9477ca8268fe58df9da125f3313a70f93555edf4db09c3d
MD5 32255aa4d93f06ab74cc62b066dfb2da
BLAKE2b-256 d6c21cef23b3a7a90e5360294d5099c528d092ed25b8b634893adcce77c66982

See more details on using hashes here.

Provenance

The following attestation bundles were made for logbrew_fastapi-0.1.1-py3-none-any.whl:

Publisher: publish-packages.yml on LogBrewCo/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page