Search code examples
pythonazureazure-web-app-serviceplotly-dashopen-telemetry

Azure monitor open telemetry python package raising exception when python app deployed on Azure


I have a Python web application built with Plotly Dash and deployed on Azure App Service using Python 3.12. As Azure App Service has not yet enabled Python 3.12 version to have application insight enabled, I have utilized the package:

azure-monitor-opentelemetry==1.6.2

within my application to log exceptions into my application insight resource.

However, as I deploy my web application on Azure App Service, and when someone is accessing the web app, my application logs the following exception onto the application insight:

Failed to derive Resource from Tracer Provider: 'ProxyTracerProvider' object has no attribute 'resource'

Traceback (most recent call last):
  File "/tmp/8dcd22e385c2da5/antenv/lib/python3.12/site-packages/azure/monitor/opentelemetry/exporter/export/trace/_exporter.py", line 91, in export
    resource = tracer_provider.resource # type: ignore

AttributeError: 'ProxyTracerProvider' object has no attribute 'resource'

I have implemented the azure-monitor-opentelemetry in my application simply as following:

appopentelemetry.py:

from azure.monitor.opentelemetry import configure_azure_monitor
from models.environmentmanager.environmentmanager import EnvironmentManager


def azure_monitoring_open_telemetry():
    environment_manager = EnvironmentManager()
    connection_string = environment_manager.get_connection_string() # The app insight connection string 

    return configure_azure_monitor(
        connection_string=connection_string,
        enable_live_metrics=True,
    )

and in my app.py:

...imports...

environment_manager = EnvironmentManager()

# This should be executed if the environment is not local, this is set in .env if ran locally
# and set in environment variables of the app service on Azure when deployed
if not environment_manager.get_is_local():
    from functions.app.appopentelemetry import azure_monitoring_open_telemetry
    azure_monitoring_open_telemetry()

...

app = Dash(__name__, use_pages=True, external_stylesheets=stylesheets)

...
app.layout = dmc.MantineProvider(...)

if __name__ == '__main__':
    app.run(debug=True, port=8000)

Can I know what I am doing wrong?


Solution

  • Version 1.6.2 also upgrades azure-monitor-opentelemetry-exporter to "1.0.0b29" and it has the braking changes. Just downgrade to azure-monitor-opentelemetry-exporter = "1.0.0b28" and maybe to azure-monitor-opentelemetry = "1.6.1". It will solve the issue for now.

    In general, I think that config should be done differntly rather then using configure_azure_monitor but it is not that clear from the documentation. Try to read here https://opentelemetry.io/docs/languages/python/getting-started/