1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Azure monitor open telemetry python package raising exception when python app...

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página