skip to Main Content

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?

2

Answers


  1. 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/

    Login or Signup to reply.
  2. In addition to @Andrii‘s answer ,

    • Update your packages by running the below command. You can refer this doc for compatibility information.
    pip install dash azure-monitor-opentelemetry==1.6.2 opentelemetry-sdk opentelemetry-exporter-otlp
    
    • As the error message says'ProxyTracerProvider' object has no attribute 'resource' you can create and configure your own Trace provider.
    • You can refer this doc for tracebacks in python.

    This is my appopentelemetry .py

    from azure.monitor.opentelemetry import configure_azure_monitor
    from opentelemetry.sdk.resources import Resource
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor
    from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
    from models.environmentmanager.environmentmanager import EnvironmentManager
    
    def azure_monitoring_open_telemetry():
        
        environment_manager = EnvironmentManager()
        connection_string = environment_manager.get_connection_string()
    
        resource = Resource(attributes={"service.name": "your-app-name"})
        tracer_provider = TracerProvider(resource=resource)
        span_processor = BatchSpanProcessor(OTLPSpanExporter())  tracer_provider.add_span_processor(span_processor)
        
        configure_azure_monitor(
            connection_string=connection_string,
            tracer_provider=tracer_provider,
            enable_live_metrics=True,
        )
        return tracer_provider
    
    • While creating the Azure App Service, select Python 3.10 or Python 3.11, These versions are recommended for better compatibility with most libraries and services.
    • refer this doc for better understanding.

    Here’s the output
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search