Skip to content
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

Log correlation remake suggestions #4

Conversation

felixbarny
Copy link

Implements suggestions from elastic#2428 (comment)

@felixbarny
Copy link
Author

While LogEvents can be created without a LogEventFactory, it looks like all logger methods (trace, debug, info, ...) always go through a LogEventFactory. So this approach should be as least as good as instrumenting the logger methods. It would be beneficial if someone else could verify that premise, though.

Copy link
Owner

@eyalkoren eyalkoren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for proposing this.
If you don't mind, I will only pick some of the proposed changes, but I won't merge this as a whole.

The CorrelationIdMapAdapter is awesome, but it's very log4j-specific, and that's where I would put it. I'd definitely not treat it as the default implementation holding global constants or affecting the abstract implementation this way.

As we discussed, I will apply the framework-specific instrumentation points, but my intent was to only change the instrumentations and see the tests pass, not to do all these adjustments.

Comment on lines +362 to +367
if (callDepth.isNestedCallAndIncrement()) {
// avoid re-entrancy and stack overflow errors
// may happen when bootstrapping an instrumentation that also gets triggered during the bootstrap
// for example, adding correlation ids to the thread context when executing logger.debug
return null;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that an issue related to us instrumenting our own logging?
If that so, the proper handling is to avoid instrumenting it. I did it through getClassLoaderMatcher.
I am not opposed to this safety check, but it should be treated as such - log an error before returning null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, we'll also want to instrument our logging so that we also have correlation IDs in the agent logs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having correlation IDs within the agent logs is a great idea, but I think the proper way to achieve that is through direct addition to the MDC. We can use an ActivationListener for that.
Instrumenting classes loaded by the agent class loader can open a can of worms. It would create a plugin CL for it and treat the agent CL as the target CL. This deviates from anything our complicated class loading hierarchy is designed for, so I really think we should avoid that.

@felixbarny
Copy link
Author

The CorrelationIdMapAdapter is awesome, but it's very log4j-specific, and that's where I would put it.

++

I'd definitely not treat it as the default implementation holding global constants or affecting the abstract implementation this way.

Right, the constants are better off in a different class.

@eyalkoren eyalkoren merged commit 08870c8 into eyalkoren:log-correlation-remake Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants