# Correlation Id\[Trace.Id\] in logs coming with self-attach API JAVA APM Agent Setup way but not coming with manual -javaagent flag way

**URL:** <https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403>\
**Category:** APM\
**Tags:** java\
**Created:** [October 8, 2020, 9:22am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403 "2020-10-08T09:22:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayush\_Agrahari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayush_agrahari/32/74932_2.png) [@Ayush\_Agrahari](https://discuss.elastic.co/u/Ayush_Agrahari)\
**Post date:** [October 8, 2020, 9:22am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403/1 "2020-10-08T09:22:05Z")

</div>

I have Springboot application. I want to configure log correlation with APM. I have specfied %X{trace.id} in Log pattern to get correlation Id.

I tried to setup with APM setup [Manual setup with `-javaagent` flag](https://www.elastic.co/guide/en/apm/agent/java/current/setup-javaagent.html) then I am getting %X{trace.id} as blank.

```auto
java -javaagent:elastic-apm-agent-1.18.0.RC1.jar -jar -Delastic.apm.service_name=TEST-SERVICE -Delastic.apm.server_urls=http://192.168.0.11:8200 -Denvironment=Development -Dprofiling_inferred_spans_enabled=true -Denable_log_correlation=true target/test-0.0.1-SNAPSHOT.jar

```

Then I thought to setup [Programmatic API setup to self-attach](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-api.html) then I am getting %X{trace.id}.

```auto
java -jar target/test-0.0.1-SNAPSHOT.jar

```

Please help me with this behaviour as I don't want to keep elastic-apm dependency in code and want to go with -javaagent way.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [October 8, 2020, 9:26am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403/2 "2020-10-08T09:26:37Z")

</div>

Hi,

Have you already enabled [log correlation](https://www.elastic.co/guide/en/apm/agent/java/current/config-logging.html#config-enable-log-correlation) as this is off by default?

Best regards  
Wolfram

---

<div class="post-metadata">

**Author:** ![Ayush\_Agrahari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayush_agrahari/32/74932_2.png) [@Ayush\_Agrahari](https://discuss.elastic.co/u/Ayush_Agrahari)\
**Post date:** [October 8, 2020, 9:35am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403/3 "2020-10-08T09:35:54Z")

</div>

Yes @Wolfram_Haussig , I have enabled log correlation in -javaagent way using below passed variable.

```auto
-Denable_log_correlation=true

```

---

<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:** [October 8, 2020, 9:47am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403/4 "2020-10-08T09:47:32Z")

</div>

Thus, if I understand correctly, you get the proper log correlation working when using the programmatic self-attach but not when using `-javaagent` option ?

It seems that you forgot the `co.elastic.apm` prefix for the following configuration options: `environment`, `profiling_inferred_spans_enabled` and `enable_log_correlation`

You can check the configuration read by the agent by setting `log_level=debug`, this will output what configuration is applied by the agent at agent startup. With that, you should be able to see that the options without the prefix listed above are just ignored.

---

<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 29, 2020, 5:47am UTC](https://discuss.elastic.co/t/correlation-id-trace-id-in-logs-coming-with-self-attach-api-java-apm-agent-setup-way-but-not-coming-with-manual-javaagent-flag-way/251403/5 "2020-10-29T05:47:53Z")

</div>

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