Prometheus is a popular tool for collecting metrics on apps and services hosted in cloud environments. Typical use cases include usage analytics, performance data and health / reliability. This integration provides a slight hack to allow the app developer to write custom metrics using the normal prometheus python SDK which are then exposed on a web server endpoint for scraping.
# Slightly simplified example for reference
from streamlit_extras import prometheus
from prometheus_client import Counter
# For a real usage, put in a separate file and import for persistence
SLIDER_COUNT = Counter(
documentation="Sum of slider values",
latest = st.slider("Latest value", 0, 20, 3)
streamlit run my_slider_app.py
Output of curl (can be picked up by an automated scraper):
# TYPE slider_counter counter
# HELP slider_counter Sum of slider values
You can see a full example here. This works best on Streamlit 1.31.
Note: If you already use OpenTelemetry, it should be possible to run an OTel Collector alongside the Streamlit app to convert from Prometheus to OpenTelemetry format. Here’s an example for Google Cloud Run. I am hoping to write up a short doc on this with a Streamlit specific use case when I have some time
As a product manager for Streamlit I want to explore deeper, native integrations for app telemetry including OpenTelemetry which are geared towards an organization’s internal apps, as well as tools like Google Analytics which have been widely requested. Expect to hear more about this in the coming months.
I see this integration as a quick win and a first step in that direction. If you try it out, I would love to hear from you about how it works and what you’re doing with it! Or what breaks . This will inform our roadmap and how we prioritize any native integrations and telemetry features. Thanks!!