# When using log4j AsyncLoggerContextSelector , trace.id and transaction.id is not injected into the MDC context

**URL:** <https://discuss.elastic.co/t/when-using-log4j-asyncloggercontextselector-trace-id-and-transaction-id-is-not-injected-into-the-mdc-context/343796>\
**Category:** Logs\
**Tags:** elastic-stack-monitoring, elastic-stack-alerting, java\
**Created:** [September 25, 2023, 5:48pm UTC](https://discuss.elastic.co/t/when-using-log4j-asyncloggercontextselector-trace-id-and-transaction-id-is-not-injected-into-the-mdc-context/343796 "2023-09-25T17:48:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkg1201](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkg1201/32/120316_2.png) [@rkg1201](https://discuss.elastic.co/u/rkg1201)\
**Post date:** [September 25, 2023, 5:48pm UTC](https://discuss.elastic.co/t/when-using-log4j-asyncloggercontextselector-trace-id-and-transaction-id-is-not-injected-into-the-mdc-context/343796/1 "2023-09-25T17:48:46Z")

</div>

Hi , we are setting -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector in our jvm proprties and using elastic agent version 1.42.0 .  
When using the above mentioned log4j async context selector , we are not getting trace.id and transaction.id in the MDC context.

But when we remove the above jvm arg , it works fine.  
Is there any solution for it?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [September 26, 2023, 7:22am UTC](https://discuss.elastic.co/t/when-using-log4j-asyncloggercontextselector-trace-id-and-transaction-id-is-not-injected-into-the-mdc-context/343796/2 "2023-09-26T07:22:19Z")

</div>

Hi,

Unfortunately this is not supported, and we already have an issue to implement this: [Add instrumentation for Log4j2 with AsyncLoggerContextSelector that enables log correlation · Issue #3132 · elastic/apm-agent-java · GitHub](https://github.com/elastic/apm-agent-java/issues/3132)

Make sure to subscribe to the issue notifications to know when progress is made on this.

For now, it's not in our short-term roadmap, thus there is no ETA when this will be implemented.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 24, 2023, 7:23am UTC](https://discuss.elastic.co/t/when-using-log4j-asyncloggercontextselector-trace-id-and-transaction-id-is-not-injected-into-the-mdc-context/343796/3 "2023-10-24T07:23:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
