Prometheus integration for Streamlit app metrics

You can now integrate Prometheus to your Streamlit apps for monitoring and analytics with a new streamlit extra: ๐Ÿ“Š Prometheus - streamlit-extras

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
    documentation="Sum of slider values",

latest = st.slider("Latest value", 0, 20, 3)
if st.button("Submit"):
streamlit run
curl localhost:8501/_stcore/metrics

Output of curl (can be picked up by an automated scraper):

# TYPE slider_counter counter
# HELP slider_counter Sum of slider values
slider_counter_total{} 14.0
slider_counter_created{} 1.7042185907557938e+09

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 :slight_smile:

Whatโ€™s next?

As a product manager for Streamlit :person_with_crown: 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 :sweat_smile: . This will inform our roadmap and how we prioritize any native integrations and telemetry features. Thanks!!