Search code examples
python-3.xazureazure-application-insightsopen-telemetry

Cannot Find Reference `configure_azure_monitor` from Opentelemetry Library


I'm currently exploring the options of using OpenTelemetry with Azure Application Insights for logging, traces and metrics.

Was following this particular documentation that popped up on Google.

Posting the snippet here, in case if the link expires:

# Import the `configure_azure_monitor()` function from the
# `azure.monitor.opentelemetry` package.
from azure.monitor.opentelemetry import configure_azure_monitor

# Import the tracing api from the `opentelemetry` package.
from opentelemetry import trace

# Configure OpenTelemetry to use Azure Monitor with the 
# APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.
configure_azure_monitor()

so when I try this in my Python application, I get this Cannot find Reference error for the configure_azure_monitor. Also I have azure-monitor-opentelemetry package installed with version 1.6.0

Where am I going wrong? Any help could be appreciated.


Solution

  • integrate opentelemetry with azure app insights, so that i can like push metrics from my application

    The configure_azure_monitor() is not supported in latest versions of Open Telemetry.

    You can use azure.monitor.opentelemetry.exporter to send logs to Application Insights using Open Telemetry Package in python.

    I have followed Microsoft-Document and able to send the logs.

    import logging 
    from opentelemetry.sdk._logs.export import BatchLogRecordProcessor as blrp
    from azure.monitor.opentelemetry.exporter import AzureMonitorLogExporter as amlp
    from opentelemetry._logs import (get_logger_provider as glp,set_logger_provider as slp,)
    from opentelemetry.sdk._logs import (LoggerProvider,LoggingHandler,)
    
    slp(LoggerProvider())
    ri_ex = amlp(
        connection_string="InstrumentationKey=b6*****00;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/;ApplicationId=2e74****ddf63"
    )
    glp().add_log_record_processor(blrp(ri_ex))
    
    ri_han = LoggingHandler()
    ri_lger = logging.getLogger(__name__)
    ri_lger.addHandler(ri_han )
    ri_lger.setLevel(logging.INFO)
    
    ri_lger.warning("Warning Rithwik WARNING ")
    ri_lger.error("Error Rithwik")
    

    Output:

    enter image description here