cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Connecting log with traces using Log4J 1.x

sanjivj
Visitor

Hi,

I'd like to connect logs with traces and I'm on Log4J 1.x for a subcomponent that cannot be upgraded to Log4J 2.x. I see Dynatrace supports automatic log enrichment for Log4j 2.x but not for Log4J 1.x. I verified the logs and don't see dt.span_id, dt.trace_id, dt.trace_sampled and dt.entity.process_group_instance in the log files

 

https://www.dynatrace.com/support/help/observe-and-explore/logs/log-monitoring/log-monitoring-config...

How can I manually enrich the logs from log4j 1.x so that they are associated with a trace? I tried adding dt.span_id, dt.trace_id, dt.trace_sampled and dt.entity.process_group_instance using a log4j pattern layout like below but the log files have empty values for these variables.

<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} dt.trace_id=%X{dt.trace_id} dt.span_id=%X{dt.span_id} dt.entity.process_group_instance=%X{dt.entity.process_group_instance} - %msg%n"/>

 

I suspect with Log4J 1.x these values are not set as MDC variables so the logs don't have them as well. How do I associate the logs from Log4J 1.x to traces?

 

Thanks

2 REPLIES 2

Fin_Ubels
Dynatrace Champion
Dynatrace Champion

Hey Sanjivj,

While not ideal and not for log4j 1.x but just generally for logs not being automatically linked to traces, I do remember being able to set this up using OpenTelemetry as shown here: Connecting log data to traces | Dynatrace Docs

Another example in Lambda functions can be seen here: AWS Lambda logs in context of traces | Dynatrace Docs

Hope this helps get you in the right direction!

Julius_Loman
DynaMight Legend
DynaMight Legend

In general - there is no way of enriching the log entries for unsupported log frameworks without modifying the application code. The approach is to retrieve the trace context information using OpenTelemetry (or OneAgent SDK which can provide that in the latest versions of the SDK) and log it along with log entries from the application.

Certified Dynatrace Master | Alanata a.s., Slovakia, Dynatrace Master Partner

Featured Posts