Azure Application Insights for Streamlitt apps

I have a Streamlit app running as a Docker container on Azure App Service. I’d like to start using Azure App Insights to log requests and errors. This requires adding telemetry code to the app, as described here.

To add temeltry to a Flask app, I would add the following to the top of the main file:

from import AzureExporter
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
from opencensus.trace.samplers import ProbabilitySampler

app = Flask(__name__)
middleware = FlaskMiddleware(

Does anyone know how to do this for a Streamlit app? I suspect that I need a different way of defining app in the code above.