# Connecting log with traces using Log4J 1.x

**URL:** <https://community.dynatrace.com/t/connecting-log-with-traces-using-log4j-1-x/41189>\
**Category:** Open Q&A\
**Tags:** log4j, distributed-traces-classic\
**Created:** [August 13, 2023, 1:22pm UTC](https://community.dynatrace.com/t/connecting-log-with-traces-using-log4j-1-x/41189 "2023-08-13T13:22:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjivj](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@sanjivj](https://community.dynatrace.com/u/sanjivj)\
**Post date:** [August 13, 2023, 1:22pm UTC](https://community.dynatrace.com/t/connecting-log-with-traces-using-log4j-1-x/41189/1 "2023-08-13T13:22:23Z")

</div>

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&nbsp;dt.span\_id, dt.trace\_id, dt.trace\_sampled and dt.entity.process\_group\_instance in the log files

> **[Connect log data to traces](https://docs.dynatrace.com/docs/analyze-explore-automate/log-monitoring/log-monitoring-configuration/log-enrichment-classic)**
>
> Connect your incoming log data to traces for more precise Dynatrace analysis.

How can I manually enrich the logs from log4j 1.x so that they are associated with a trace? I tried adding&nbsp;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

---

<div class="post-metadata">

**Author:** ![Fin\_Ubels](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/fin_ubels/32/18008_2.png) [@Fin\_Ubels](https://community.dynatrace.com/u/Fin_Ubels)\
**Post date:** [August 14, 2023, 4:41am UTC](https://community.dynatrace.com/t/connecting-log-with-traces-using-log4j-1-x/41189/2 "2023-08-14T04:41:31Z")

</div>

Hey Sanjivj,

While not ideal and&nbsp;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](https://www.dynatrace.com/support/help/observe-and-explore/logs/log-management-and-analytics/lma-log-enrichment#retrieve-span-and-trace-ids)

Another example in Lambda functions can be seen here:&nbsp;[AWS Lambda logs in context of traces | Dynatrace Docs](https://www.dynatrace.com/support/help/setup-and-configuration/setup-on-cloud-platforms/amazon-web-services/amazon-web-services-integrations/aws-lambda-integration/log-enrichment)

Hope this helps get you in the right direction!

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [August 14, 2023, 5:12am UTC](https://community.dynatrace.com/t/connecting-log-with-traces-using-log4j-1-x/41189/3 "2023-08-14T05:12:43Z")

</div>

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.
