Application Real-Time Monitoring Service (ARMS) allows you to associate trace IDs with the logs of a Python application. This way, if an error occurs in the application, you can access the logs associated with the trace IDs to locate and troubleshoot the error.
Prerequisites
The Python application is integrated with ARMS. For more information, see Monitor Python applications.
Logs are collected by using Simple Log Service. For more information, see Data collection overview.
Background information
The capability of associating trace IDs with Python logs in ARMS relies on the instrumentation of log frameworks. Currently, only Logging, the official Python framework, is supported.
Procedure
Log on to the ARMS console. In the left-side navigation pane, choose .
Select a region in the top navigation bar and click the application.
NoteIcons in the Language column indicate the application's programming language:
: Java
: Go
: Python- (Hyphen): an application monitored in Managed Service for OpenTelemetry
In the top navigation bar, choose .
In the Application log Association configuration section of the Custom Configurations tab, set Log Source to Log service SLS. Select the region where your Simple Log Service is deployed, and bind a project and a Logstore.

Configure the ARMS agent for Python.
Set the environment variable
OTEL_PYTHON_LOG_CORRELATIONtotrueto enable the feature for associating business logs with trace IDs in the agent.The default value of
OTEL_PYTHON_LOG_CORRELATIONisfalse.If you set
OTEL_PYTHON_LOG_CORRELATIONtofalseor leave this variable empty, the feature is disabled.
Set the environment variable
OTEL_PYTHON_LOG_LEVELtowarning,debug,info, orerrorbased on your business requirements. This variable specifies the level of the business logs to be associated with trace IDs.Set the environment variable
OTEL_PYTHON_LOG_FORMAT. An example value is%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] [trace_id=%(otelTraceID)s span_id=%(otelSpanID)s resource.service.name=%(otelServiceName)s trace_sampled=%(otelTraceSampled)s] - %(message)s. You can customize the value based on your business requirements.The following defines some of the fields:
otelTraceID: The trace ID.otelSpanID: The ID of the span generated by the current log.otelTraceSampled: The sampling identifier.otelServiceName: The application name.
After you configure the preceding environment variables, the following log is returned:

(Optional) Configure log collection and upload application logs to the project and Logstore.
By default, the ARMS agent for Python does not collect application logs.