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

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

I tried to setup with APM setup Manual setup with -javaagent flag then I am getting %X{} as blank.

java -javaagent:elastic-apm-agent-1.18.0.RC1.jar -jar -Delastic.apm.service_name=TEST-SERVICE -Delastic.apm.server_urls= -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 then I am getting %X{}.

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.


Have you already enabled log correlation as this is off by default?

Best regards

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


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.