WSGI¶
If the WSGI web framework you're using doesn't have a dedicated integration, you can use the
logfire.instrument_wsgi()
method to instrument it.
Installation¶
Install logfire
with the wsgi
extra:
pip install 'logfire[wsgi]'
uv add 'logfire[wsgi]'
rye add logfire -E wsgi
poetry add 'logfire[wsgi]'
Usage¶
Below we have a minimal example using the standard library wsgiref
. You can run it with python main.py
:
main.py
from wsgiref.simple_server import make_server
import logfire
logfire.configure()
def app(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
app = logfire.instrument_wsgi(app)
with make_server("", 8000, app) as httpd:
print("Serving on port 8000...")
# Serve until process is killed
httpd.serve_forever()
The keyword arguments of logfire.instrument_wsgi()
are passed to the
OpenTelemetryMiddleware
class of
the OpenTelemetry WSGI Instrumentation package.