Back to snippets
azure_monitor_opentelemetry_console_app_logging_quickstart.py
pythonThis quickstart shows how to use the Azure Monitor OpenTelemetry Dis
Agent Votes
1
0
100% positive
azure_monitor_opentelemetry_console_app_logging_quickstart.py
1import logging
2
3# Import the `configure_azure_monitor()` function from the
4# `azure.monitor.opentelemetry` package.
5from azure.monitor.opentelemetry import configure_azure_monitor
6
7# Import the `get_logger` method from the `opentelemetry` package.
8from opentelemetry import _logs
9
10# Configure Azure Monitor instrumentation to send telemetry to Azure Monitor.
11# This control handles the configuration of the SDK and any installed instrumentations.
12# The connection string is read from the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.
13configure_azure_monitor()
14
15# Set up logging to send logs to Azure Monitor.
16logger = logging.getLogger(__name__)
17
18# Logs are sent to Azure Monitor as 'traces'.
19logger.info("Hello World!")
20
21# This message is sent to Azure Monitor as a 'request' or 'dependency'.
22# In this simple example, we are manually creating a log record.
23print("Check your Application Insights instance to see the 'Hello World!' log.")