-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JUL log correlation #2724
JUL log correlation #2724
Conversation
...ul-plugin/src/main/java/co/elastic/apm/agent/jul/correlation/JulEcsLogCorrelationHelper.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the log correlation instrumentation is independent of the ECS-reformatting one, we need to distinguish between two use cases:
- ECS-logging-JUL is used as an application dependency, in which case we need to update the
JulMdc
that is loaded by the agent CL. - ECS-reformatting - where we need to add to the
JulMdc
that is loaded by the agent plugin CL.
I think the proper way to achieve that is by having two instrumentations (within two plugins):
- one that is only applied if the application CL can load
JulMdc
. Its advice adds to theJulMdc
that is loaded by the application class loader. In order to achieve that, you may need to create a separate plugin (so that the plugin class loader does not contain the ECS logging classes bundled with the agent) AND you may need to update the list that says what's loaded from the agent class loader and what's not. - the second is only applied if the application CL cannot load
JulMdc
, in which case the advice would add to the agent-bundledJulMdc
. This one needs to have theJulMdc
loaded by the plugin CL, which is the case with the current logging plugin, so yourJulEcsLogCorrelationInstrumentation
should be fit for this purpose.
Sorry if I confused or mislead you, it is all based on static code analysis and better be verified with tests of both scenarios.
.../src/main/java/co/elastic/apm/agent/jul/correlation/JulEcsLogCorrelationInstrumentation.java
Outdated
Show resolved
Hide resolved
...src/test/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentationTest.java
Show resolved
Hide resolved
...gin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java
Outdated
Show resolved
Hide resolved
...src/test/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentationTest.java
Outdated
Show resolved
Hide resolved
...gging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/error/LoggerErrorHelper.java
Outdated
Show resolved
Hide resolved
The way I understand it, there are three cases:
So, in a sense, we just need to alter which instance of the |
Exactly, but this may be trickier than it seems. |
If we manage to update the However, if we limit ourselves to the MDC attributes, the other ECS logging attributes In the case of overriding logs, I think it would be simpler to just replace the |
Why is that a problem? User configured values are always the best, we only decorate the logs with the tracing IDs if the user chooses that. Logging correlation is an independent feature from ECS-reformatting, even if they can cooperate.
But the |
PR updated with a different approach:
As a result, when using ECS log formatter in the application, the agent can now automatically inject the log correlation attributes into the logs. |
apm-agent-core/src/main/java/co/elastic/apm/agent/logging/AgentMDC.java
Outdated
Show resolved
Hide resolved
...gent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/logging/jul/JulMdcAccessor.java
Outdated
Show resolved
Hide resolved
.../src/main/java/co/elastic/apm/agent/jul/correlation/JulEcsLogCorrelationInstrumentation.java
Outdated
Show resolved
Hide resolved
...jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/JulEcsReformattingHelper.java
Outdated
Show resolved
Hide resolved
.../java/co/elastic/apm/agent/ecs_logging/EcsLoggingPluginClassLoaderRootPackageCustomizer.java
Outdated
Show resolved
Hide resolved
...ng-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/JulEcsFormatterInstrumentation.java
Outdated
Show resolved
Hide resolved
.../resources/META-INF/services/co.elastic.apm.agent.bci.PluginClassLoaderRootPackageCustomizer
Outdated
Show resolved
Hide resolved
...jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/JulEcsReformattingHelper.java
Show resolved
Hide resolved
...gin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java
Outdated
Show resolved
Hide resolved
Forgot to add to the review comment - what about trace correlation when applying ECS-reformatting? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing - please add JUL support for correlation and error capturing to the supported technologies page.
apm-agent-core/src/main/java/co/elastic/apm/agent/util/ClassLoaderUtils.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/util/ClassLoaderUtils.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
Outdated
Show resolved
Hide resolved
/test |
@@ -77,7 +77,7 @@ | |||
<dependency> | |||
<groupId>co.elastic.logging</groupId> | |||
<artifactId>log4j2-ecs-layout</artifactId> | |||
<version>${version.log4j2-ecs-layout}</version> | |||
<version>${version.ecs.logging}</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] we now have a single version to target ecs-logging
and its sub-modules.
@Override | ||
public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() { | ||
// ECS formatter that is loaded within the agent should not be instrumented | ||
return not(CustomElementMatchers.isInternalPluginClassLoader()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] this filtering means that the agent copy of ecs-logging
won't be instrumented, hence we have to explicitly override co.elastic.logging.jul.EcsFormatter#getMdcEntries
in co.elastic.apm.agent.jul.reformatting.JulEcsReformattingHelper#createEcsFormatter
What does this PR do?
Fixes #2492
Depends on elastic/ecs-logging-java#190 and elastic/ecs-logging-java#193
Checklist
CorrelationIdMapAdapter
.Added an API method or config option? Document in which version this will be introduced