# How to enrich logs with the EDOT Java?

**URL:** <https://discuss.elastic.co/t/how-to-enrich-logs-with-the-edot-java/383286>\
**Category:** Elastic Observability\
**Created:** [November 7, 2025, 9:08am UTC](https://discuss.elastic.co/t/how-to-enrich-logs-with-the-edot-java/383286 "2025-11-07T09:08:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilsen/32/146631_2.png) [@nilsen](https://discuss.elastic.co/u/nilsen)\
**Post date:** [November 7, 2025, 9:08am UTC](https://discuss.elastic.co/t/how-to-enrich-logs-with-the-edot-java/383286/1 "2025-11-07T09:08:09Z")

</div>

I'm using the [EDOT Java agent](https://www.elastic.co/docs/reference/opentelemetry/edot-sdks/java), which automatically _generates and exports_ logs/metrics/tracing from my Java application to Elastic. However, I'm having a hard time enriching the log documents.

**The goal is to be able to query the index with some sort of id to retrieve all logs related to a task.**

I have tried to get MDC attributes to be exported with the logs, but that does not seem to work with the EDOT SDK.

Anyone have any idea how this would usually be done?

_Pseudo example of concept:_

```java
while (true) {
  // main program loop
  Task task = getNextTask();
  Logger.current().setAttribute("task.id", task.id);
  task.run();
}

```

If I then want all logs related a task, I would just query my index with the task.id.

* * *

The only solution I have found so far is _(Pseudo)_ :

```java
while (true) {
  // main program loop
  Task task = getNextTask();
  Span.current().setAttribute("task.id", task.id);
  task.run();
}

```

First query the trace index with with a `task.id` to fetch the `trace.id`, and then use the `trace.id` on the log index to get all log documents related to my task.
