in azure_functions_worker/dispatcher.py [0:0]
def initialize_azure_monitor(self):
"""Initializes OpenTelemetry and Azure monitor distro
"""
self.update_opentelemetry_status()
try:
from azure.monitor.opentelemetry import configure_azure_monitor
# Set functions resource detector manually until officially
# include in Azure monitor distro
os.environ.setdefault(
"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS",
"azure_functions",
)
configure_azure_monitor(
# Connection string can be explicitly specified in Appsetting
# If not set, defaults to env var
# APPLICATIONINSIGHTS_CONNECTION_STRING
connection_string=get_app_setting(
setting=APPLICATIONINSIGHTS_CONNECTION_STRING
),
logger_name=get_app_setting(
setting=PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME,
default_value=PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME_DEFAULT
),
)
self._azure_monitor_available = True
logger.info("Successfully configured Azure monitor distro.")
except ImportError:
logger.exception(
"Cannot import Azure Monitor distro."
)
self._azure_monitor_available = False
except Exception:
logger.exception(
"Error initializing Azure monitor distro."
)
self._azure_monitor_available = False