Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Support for ELASTIC_APM_ENABLE_LOG_CORRELATION - log4j2 #6

Open
adrianj opened this issue Jul 7, 2020 · 5 comments
Open

Support for ELASTIC_APM_ENABLE_LOG_CORRELATION - log4j2 #6

adrianj opened this issue Jul 7, 2020 · 5 comments

Comments

@adrianj
Copy link
Contributor

adrianj commented Jul 7, 2020

Hi - this is pretty much a duplicate of a similar issue in the mule3-agent.
michaelhyatt/elastic-apm-mule3-agent#24

Regardless of if I have ELASTIC_APM_ENABLE_LOG_CORRELATION=true, the %X{trace.id} and %X{transaction.id} are always empty. The %X{correlationId} does work.

Mule Kernel 4.2.0
AdoptOpenJDK 1.8
mule4-agent 0.0.2
mule-apikit-module 1.3.3

@michaelhyatt
Copy link
Owner

@adrianj I created a new release that populates MDC with trace.id and transaction.id, please give it a go:

https://github.com/michaelhyatt/elastic-apm-mule4-agent/releases/tag/v0.0.3

@adrianj
Copy link
Contributor Author

adrianj commented Jul 21, 2020

@michaelhyatt sorry I just saw this comment, I'm not accustomed to checking my Github notifications.

I will test it out in the next few days and let you know how it goes 👍

@adrianj
Copy link
Contributor Author

adrianj commented Aug 30, 2020

Hello,
Sorry it has taken me so long. I have come back around to testing version 0.0.3.
Alas, it is still not working for me.

mule kernel log:

**********************************************************************
* Started app                                                        *
* 'mule4.template.project.api-1.0.0-SNAPSHOT-mule-application'       *
* Application plugins:                                               *
*  - Sockets : 1.1.5                                                 *
*  - HTTP : 1.5.3                                                    *
*  - APIKit : 1.3.3                                                  *
* Application libraries:                                             *
*  - apm-agent-attach-1.17.0.jar                                     *
*  - jna-5.3.1.jar                                                   *
*  - jna-platform-5.3.1.jar                                          *
*  - apm-agent-api-1.17.0.jar                                        *
*  - mule4-agent-0.0.3.jar                                           *
**********************************************************************

log4j2.xml

<PatternLayout pattern="%d [%t] %-5p %c - %X{trace.id} %X{transaction.id} CorrelationID=%X{correlationId}, Message=%m%n" />

mule4.template.application.log - trace.id and transaction.id appear as empty strings.

2020-08-31 11:33:14,117 [[MuleRuntime].cpuLight.15: [mule4.template.project.api-1.0.0-SNAPSHOT-mule-application].post:\request:application\json:api-config.CPU_LITE @4dbe76a0] INFO  org.mule.runtime.core.internal.processor.LoggerMessageProcessor -   CorrelationID=e09e847b-b605-4f16-86b0-971698076fcd, Message={"Name":"name","Address":"address"}

@adrianj
Copy link
Contributor Author

adrianj commented Aug 31, 2020

After digging a little deeper and attaching a debugger, I'm finding this behaviour:

  1. The MDC.put is being called for trace.id and transaction.id
  2. Looking at org.apache.logging.log4j.ThreadContext class, the correlationId is put many times within the flow, whereas trace.id is only put once.
  3. On the MDC.remove, the trace.id and transaction.id aren't there anymore, though the correlationId is.

Possibly the thread that put the ids is a different thread to the mule logger component, and different to the thread that ends the transaction.

system property log4j2.isThreadContextMapInheritable=true does not seem to make any difference.

@michaelhyatt
Copy link
Owner

michaelhyatt commented Sep 1, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants