Django¶
The logfire.instrument_django()
method can be used to instrument the Django web framework with Logfire.
Installation¶
Install logfire
with the django
extra:
pip install 'logfire[django]'
uv add 'logfire[django]'
rye add logfire -E django
poetry add 'logfire[django]'
Info
If you use are using the Asynchronous support of Django, you'll also need to
install the asgi
extra:
pip install 'logfire[django,asgi]'
uv add 'logfire[django,asgi]'
rye add logfire -E django -E asgi
poetry add 'logfire[django,asgi]'
Usage¶
In the settings.py
file, add the following lines:
import logfire
# ...All the other settings...
# Add the following lines at the end of the file
logfire.configure()
logfire.instrument_django()
logfire.instrument_django()
uses the
OpenTelemetry Django Instrumentation package,
which you can find more information about here.
Database¶
By default, the Django configuration uses SQLite as the database engine.
To instrument it, you need to call logfire.instrument_sqlite3()
.
If you are using a different database, check the available instrumentation methods in our Integrations section.