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?

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/

3

Fixed the issue thanks to @Andrii and @Sirra. Turns out one of azure-monitor-opentelemetry==1.6.2 dependencies packages which is the azure-monitor-opentelemetry-exporter was automatically installing the ‘1.0.0b29’ version, so in my requirements.txt file I stated the following:

azure-monitor-opentelemetry==1.6.1 
azure-monitor-opentelemetry-exporter==1.0.0b28

And this has fixed the issue.

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

4

A new version of the exporter that has a fix for this issue is released: https://pypi.org/project/azure-monitor-opentelemetry-exporter/1.0.0b30/

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật