Django
Django is autoinstrumented!
Just add our code snippet to the top of your server’s entrypoint and you’re good to go.
Install the Python client
pip install iudex
Create a write-only API key 🔑
Click settings in the top left corner of the IUDEX dashboard and create a write-only API key.
Add IUDEX into your app 🚀
Find the entrypoint for your app, typically manage.py
for Django.
Add the highlighted code as shown below.
import
at the very top of the file, before all other importsinstrument(...)
just after loading your Django site settings, but before any other code
from iudex import instrument
# ^ Must run above all imports
...
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
# ^ IUDEX instrument call must run right after you load settings
instrument(
service_name="YOUR_SERVICE_NAME", # Highly encouraged
iudex_api_key="WRITE_ONLY_IUDEX_KEY", # Only ever commit your WRITE ONLY key
github_url="GITHUB_URL_TO_YOUR_REPO", # Optional, this sets up code linking
env="prod", # Optional, dev, local, etc
)
# v The rest of your main() function is unchanged
try:
from django.core.management import execute_from_command_line
...
Set up Slack alerts 📣
Click the Slack logo in the top right of the dashboard and follow the prompts.
Note: you must have admin permissions to add apps to your workspace.
Create a log 🪵
Add code to emit a log in your app. You can use print
or Python’s logging
module.
If you’re using logging
, you likely need to set the global logging level to INFO
, as shown below.
Find out more on how you can configure this in the Django docs.
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
...
logger.info("Hello IUDEX!", extra={"iudex.slack_channel_id": "YOUR_SLACK_CHANNEL_ID"})
(In Slack, open the channel and click its name in the top left, then find its ID at the bottom of the dialog.)
Then simply run your Django app as usual to emit the log.
Verify 🧐
You should see the log in Slack and in your IUDEX dashboard log view.
Go in-depth 👉
Check out more in-depth guides on how to get the most out of IUDEX for your stack.