tencent cloud

All product documents
Tencent Cloud Observability Platform
OpenTelemetry Enhanced Java Probes
Last updated: 2025-03-12 11:38:40
OpenTelemetry Enhanced Java Probes
Last updated: 2025-03-12 11:38:40
After accessing APM through Tencent Cloud OpenTelemetry enhanced Java probe, it is easy to output context TraceID and SpanID in application logs. Only modifying the pattern in the log configuration file can realize the injection of TraceID and SpanID. The log injection feature of OpenTelemetry enhanced Java probe supports the following logging frameworks:
Log4j 1.2+
Log4j2 2.7+
Logback 1.0+
In the log configuration file, TraceID and SpanID are injected using %X{trace_id} and %X{span_id} fields respectively. If there is no TraceID or SpanID in the context, it will not affect the output of the entire line of logs.

Log4j

Example of modifying log4j.properties file:
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.warn.layout.ConversionPattern=traceId: %X{trace_id} spanId: %X{span_id} - %m%n

Log4j2

Log4j2 supports multiple format configuration files, including XML, JSON, YAML, Properties, etc. Taking XML format as an example, there are multiple ways to write Pattern. Please refer to one of the existing ways:
Method 1
Method 2
Method 3
<PatternLayout pattern="traceId: %X{trace_id} spanId: %X{span_id} - %m%n"/>
<PatternLayout>
<Pattern>traceId: %X{trace_id} spanId: %X{span_id} - %m%n</Pattern>
</PatternLayout>
<Layout type="PatternLayout" pattern="traceId: %X{trace_id} spanId: %X{span_id} - %m%n"/>

Logback

Example of modifying logback.xml file:
<encoder>
<pattern>traceId: %X{trace_id} spanId: %X{span_id} %msg%n</pattern>
</encoder>

Output Effect

When TraceID and SpanID exist in the context:



When TraceID and SpanID do not exist in the context:



Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon