Integrations
Streamlit

Streamlit

Streamlit works by running a static Python script which means all you need to do is encapsulate the scripts contents.

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.

Create a write-only API key

Add IUDEX into your app 🚀

  1. Import iudex and call instrument() to the top of your Streamlit app file.
  2. Add start_trace and end_trace to the top and bottom of the file, respectively.
from iudex import instrument, start_trace, end_trace, trace
instrument(
    service_name="YOUR_SERVICE_NAME", # highly encouraged
    env="prod", # dev, local, etc
    iudex_api_key="WRITE_ONLY_IUDEX_KEY", # only ever commit your WRITE ONLY key
)
# ^ Must run above all imports
import streamlit as st
 
# call start_trace before your Streamlit app logic
token = start_trace(name="streamlit-app")
 
# your Streamlit app logic...
def generate_text(topic: str, mood: str = "", style: str = ""):
    pass
 
end_trace(token)
# bottom of the file
  1. Add the trace decorator to functions that you want to track. This will show the function and its arguments in the stacktrace.
@trace
def generate_text(topic: str, mood: str = "", style: str = ""):
    ...

Using a main function

If your entire Streamlit app runs a single function, then the setup is a bit easier.

  1. Import iudex and call instrument() to the top of your Streamlit app file.
  2. Add the trace decorator to the main function.
from iudex import instrument, trace
instrument(
    service_name="YOUR_SERVICE_NAME", # highly encouraged
    env="prod", # dev, local, etc
    iudex_api_key="WRITE_ONLY_IUDEX_KEY", # only ever commit your WRITE ONLY key
)
 
# ^ Must run above all imports
import streamlit as st
 
@trace
def main():
    # your Streamlit app logic...
 
main()
  1. We recommend adding the trace decorator to various functions.

Set up Slack alerts 📣

Click the Slack logo in the top right of the dashboard and follow the prompts.

Slack integration button

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.

import logging
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 streamlit app as usual to emit the log.

Verify 🧐

You should see the log in Slack and in your IUDEX dashboard log view.

Slack message

Log in IUDEX

Go in-depth 👉

Check out more in-depth guides on how to get the most out of IUDEX for your stack.