-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opentelemetry
+ streamlit
= Overriding of current TracerProvider is not allowed messages
and Attempting to instrument while already instrumented
#3743
Comments
opentelemetry
+ streamlit
= Overriding of current TracerProvider is not allowed messages
and Attempting to instrument while already instrumented
when using opentelemetry
together with streamlit
opentelemetry
+ streamlit
= Overriding of current TracerProvider is not allowed messages
and Attempting to instrument while already instrumented
+1 |
1 similar comment
+1 |
Hi -- I wasn't familiar with Streamlit but it looks like it can re-run scripts from top to bottom in response to user interactions, reusing a single Python process. So you have to be careful with operations that are designed to happen only once per Python process, such as setting the global tracer provider or setting up an instrumentor. |
As @pmcollins has mentioned above, certain components of OpenTelemtry and in addition components of Azure monitor built on top of OpenTelemetry are not meant to be instantiated more than once. Besides If you really want to get this scenario working, you must ensure that EACH component that is meant to be a singleton is used be only instantiated once. You have attempted to do this with |
Hi @gorkaerana , I have set up the same environment you want by simply following the instructions here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable?tabs=python Then for Streamlit, use the cache_resource decorator: https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource. Example:
Hope this helps. |
Hi @claorden, Your minimal example does indeed work, thank you very much for your help 😃 I'll retrofit it to our code base one of these days and report back with the results. Best, |
Hello,
We have a Streamlit app in production and we are hoping to add observability to it by leveraging
opentelemetry.instrumentation.logging.LoggingInstrumentor
to integrate the current logging and OpenTelemetry to publish logs to Azure Monitor. I believe Streamlit executing the same piece of code more than once at runtime results inOverriding of current TracerProvider is not allowed
messages, which in turn only publishesAttempting to instrument while already instrumented
to Azure Monitor. I have tried to circumvent the issue the following few ways:example.py
and runningstreamlit run example.py
.)opentelemetry._logs
, but the issue I'm hoping to describe seems to be intrinsic to how the OpenTelemetry Python SDK functions, so I don't think that would solve it either. Plus, that part of the API is experimental.opentelemetry.trace._TRACER_PROVIDER
viaopentelemetry.trace.set_tracer_provider
and related functions.Please do let me know if this is not the place to ask such questions. I tried asking in the Streamlit forum but I have received no answers so far. Any help would be very much appreciated 😊
Thank you in advance,
Gorka.
The text was updated successfully, but these errors were encountered: