logbrew-flask 0.1.6 or newer. It captures request spans and unhandled
exceptions. The optional logging handler connects Python logs to the request
trace. Request-duration metrics are also optional.
The package requires Python 3.10 or newer and Flask 3.1 or newer.
Use a project-scoped server ingest key in the application. Do not use the
account credential that authorizes the CLI.
<project_id>, <trace_id>, and <issue_id> with IDs from LogBrew.
Use a development project for the test requests. The shell examples use Bash.
Send the first request
1
Create or select a project key
Sign in with the CLI. Then use a new project or an existing
project. Do not run both examples. For a new project, store its ingest key
in a new owner-only file:For an existing project, get its ID from The CLI stores the ingest key with owner-only permissions. It does not
print the key or its file path. Use your deployment platform’s secret
manager instead of this local file in production.If a creation request has an uncertain result, run the exact command again.
logbrew projects --json. Then
create a separate server key:2
Install the released integration
Create or activate the application’s virtual environment, then install the
framework package. It installs the compatible core SDK dependency.
3
Configure deployment identity
Load the project key locally without printing it. Set a stable service,
environment, and release so every signal has useful deployment context.
init_logbrew() checks explicit arguments first, then Flask application
configuration, then these environment variables. If no service name is
configured, it uses the Flask import name.4
Initialize Flask once
For a new app, save the example as Repeated
app.py. Add the initializer after you
create the Flask application. The logging handler is optional. It lets
application logs share the active request trace and span.init_logbrew(app) calls return the same Flask extension. They do
not install duplicate request or exception hooks. The initializer does not
add logging handlers. Add the handler to the app-owned logger once.5
Run one request
Start the app and call the route from another terminal. Replace Delivery runs on a background worker and does not hold the response open.
app in
the command if your application uses a different module name.6
Verify hosted evidence
Read the exact project and deployment scope. Look for the health request’s
trace and the correlated log from the example’s logging handler.Copy the returned trace ID into the bounded investigation command:A matching read confirms that LogBrew stored the signal. A local
200
response proves only that Flask handled the request.To run this read from a CI job or a coding agent without account sign-in,
use a project read key. See Verify your setup.Choose the signals you need
The initializer starts with request traces and unhandled exceptions enabled. Request metrics and Python log forwarding are separate choices.
Start with the defaults. Add request metrics when you need a latency view.
Add the logging handler only to the loggers that help an investigation.
By default, the initializer owns an HTTP transport. It queues each event, and
a background worker starts delivery as soon as one event is in the queue.
Delivery does not hold the response open. Transport failures do not break the
Flask response.
flush_on_response=True sends queued events on the response path instead.
With that option, raise_flush_errors=True raises delivery errors. Use both
only for a controlled diagnostic.
Control log content
Add oneLogBrewLoggingHandler to the logger that owns the messages you need.
The handler does not replace the app’s console or file handlers. It does not
patch Flask or the Python logging module. Adding the same handler twice
duplicates logs. If the app also uses the root logger, check propagation
before you attach a second handler.
A log inside a request inherits the active trace and span. A log outside a
request has no request trace.
The handler sends the formatted message, logger name, and LogBrew level. It
also sends the source file name, module, function, line, thread, and process
names, but not the full source path. Primitive values from extra={...}
become metadata. Review those values before you log from a user-facing
request.
Python DEBUG records become LogBrew info. WARNING becomes warning, and
CRITICAL becomes critical. The original Python level name and number stay
in metadata. To send fewer records, give the handler its own level, such as
LogBrewLoggingHandler(logbrew.client, level=logging.WARNING).
The console and LogBrew can receive the same record. For example, configure
the console before you create the Flask app:
exc_info includes the exception type and message. The
full exception text is sent only when the handler has
include_exception_text=True. This is separate from automatic exception
capture, which never sends the exception message. Do not put credentials,
personal data, or request bodies in log or exception messages.
What the integration captures
Span names use the HTTP method and the matched route template. For example,
/orders/100 and /orders/200 share GET /orders/<int:order_id>. An
unmatched request uses the fixed <unmatched> label. A missing or invalid
traceparent starts a new trace.
Span metadata contains the method, route template, endpoint, status code, and
duration. It does not contain the concrete path or a query string.
The request span covers the full Flask dispatch.
Before-request hooks, error handlers, and teardown share the request trace. A
streamed response ends its span when the body finishes or closes.
Test exception capture
A4xx or 5xx status appears on the request span. The status alone does not
prove that an exception occurred. Read both traces and issues before you
diagnose a failure. LogBrew does not replace Flask error handlers or change the
response status.
In a development project, add a temporary route. Call it once. Remove it
before you deploy:
500. Find the new issue and the request metric:
local capture check.
Connect outbound work to the request
The Python SDK has app-owned helpers forrequests, urllib, httpx,
aiohttp, database, cache, and queue work. Each helper creates a child span
of the active request trace. The SDK does not patch these libraries globally.
The logbrew-flask package shows
examples.
Give each helper a stable operation name and a route or statement template.
Do not put record IDs, customer values, SQL bind values, or message payloads
in those names. Add child spans only where the dependency matters to the
request. A span for every small call makes the trace harder to read.
Outbound HTTP helpers add one W3C traceparent header. They
do not capture full URLs, query strings, bodies, cookies, or arbitrary
headers. Database, cache, and queue helpers do not capture bind values,
results, cache values, or queue payloads.
Privacy and process lifecycle
Automatic Flask capture omits concrete request paths, query strings, request and response bodies, cookies, arbitrary headers, rawtraceparent values,
baggage, and tracestate.
Automatic exception capture never reads or sends str(error). It uses the
fixed summary Unhandled exception and marks each exception-chain message as
redacted. Frames contain a file basename and bounded code identity. They do
not contain raw traceback text, source code, local variables, or absolute
paths.
Create the app and LogBrew client inside each worker process. Gunicorn’s
default per-worker app loading works. Do not use Gunicorn --preload with a
client created in the parent process. For uWSGI, use per-worker app loading
such as --lazy-apps. The Python client rejects reuse after a process fork.
Call logbrew.client.shutdown() from the process manager’s per-worker
shutdown hook. It sends the remaining queued events and closes the client. Do
not call it after every request. After shutdown, the client rejects new
events from that worker.
A response can finish before the worker sends its last queued events. With
logbrew-sdk 0.1.26 or newer, a normal process exit sends the queued events,
for at most 2 seconds. A forced stop, such as SIGKILL, skips that send. A
graceful shutdown hook gives the queued events the most reliable final
delivery attempt.
Recover from setup problems
For account access, key, and readback errors, see
Troubleshooting. For other runtimes, see
Send SDK telemetry.
