# Trace id and span id is not getting appeneded to the logs when using elastic apm Java agent

**URL:** <https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727>\
**Category:** Logs\
**Tags:** java\
**Created:** [September 18, 2024, 11:04am UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727 "2024-09-18T11:04:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apurva12](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@apurva12](https://discuss.elastic.co/u/apurva12)\
**Post date:** [September 18, 2024, 11:04am UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727/1 "2024-09-18T11:04:31Z")

</div>

We have springboot application which uses micrometer tracing bridge otel library to get traces and span. This is working as expected with plain springboot application. When adding elastic apm Java agent trace id, span id is getting disappeared from the logs and not getting appended. Please suggest and let us know if further details

---

<div class="post-metadata">

**Author:** ![Jonas\_Kunz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_kunz/32/110740_2.png) [@Jonas\_Kunz](https://discuss.elastic.co/u/Jonas_Kunz)\
**Post date:** [September 18, 2024, 1:28pm UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727/2 "2024-09-18T13:28:38Z")

</div>

I'm assuming you mean that without the Elastic APM agent, you are seeing trace-IDs and span-IDs in your logs from micrometer, correct?

What you are experiencing is likely the fact that those are overidden from the agent due to its built-in [log-correlation](https://www.elastic.co/guide/en/apm/agent/java/current/logs.html#log-correlation-ids) feature.

You can try disabling this by setting [disable\_instrumentations](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-disable-instrumentations) to `log-correlation`. However, in general I would advice against using micrometer-tracing and the elastic APM agent together, because they are not compatible: e.g. you'll get two distinct traces (one from elastic, one from micrometer) for the same execution. Do you have any reasons for trying to combine those?

---

<div class="post-metadata">

**Author:** ![apurva12](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@apurva12](https://discuss.elastic.co/u/apurva12)\
**Post date:** [September 19, 2024, 3:15am UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727/3 "2024-09-19T03:15:15Z")

</div>

Thank you so much for quick reply.  
We have ask to use micrometer tracing bridge otel library.  
Can you please explain more how this is getting overridden by elastic log correlation feature?  
As you said if Elastic apm agent is contradicting with micrometer otel then do you suggest opentelemetry agent instead elastic apm?

---

<div class="post-metadata">

**Author:** ![Jonas\_Kunz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_kunz/32/110740_2.png) [@Jonas\_Kunz](https://discuss.elastic.co/u/Jonas_Kunz)\
**Post date:** [September 19, 2024, 8:18am UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727/4 "2024-09-19T08:18:35Z")

</div>

> Can you please explain more how this is getting overridden by elastic log correlation feature?

They both try to set the `trace.id` and `span.id` in the [logging MDC](https://www.slf4j.org/api/org/slf4j/MDC.html). Likely because there is no span active from the perspective of the elastic APM agent, it clears out those values.

> As you said if Elastic apm agent is contradicting with micrometer otel then do you suggest opentelemetry agent instead elastic apm?

No, because the opentelemetry agent also doesn't support micrometer tracing, only metrics are "bridged". So you'll have the same problems tehre. You either need to stick with just micrometer tracing or ditch it in favor of the elastic APM Agent or the opentelemetry agent.

---

<div class="post-metadata">

**Author:** ![apurva12](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@apurva12](https://discuss.elastic.co/u/apurva12)\
**Post date:** [September 23, 2024, 10:32am UTC](https://discuss.elastic.co/t/trace-id-and-span-id-is-not-getting-appeneded-to-the-logs-when-using-elastic-apm-java-agent/366727/5 "2024-09-23T10:32:04Z")

</div>

Sorry for replying late as I was sick. I have tried disabling instrumentation for log correlation but tit didn’t work. Thank you once again, I have noted all your suggestion. Please let us know if you get any breakthrough on this
