-
Notifications
You must be signed in to change notification settings - Fork 324
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
Broadened catch clause when extracting es query body #2993
Conversation
...ain/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java
Outdated
Show resolved
Hide resolved
…ched logging approach
return new AgentBuilder.Transformer.ForAdvice(withCustomMapping) | ||
.advice(instrumentationStats.shouldMeasureMatching() ? statsCollectingMatcher : matcher, instrumentation.getAdviceClassName()) | ||
.include(ClassLoader.getSystemClassLoader(), PrivilegedActionUtils.getClassLoader(instrumentation.getClass())) | ||
.withExceptionHandler(PRINTING); | ||
.withExceptionHandler(new Advice.ExceptionHandler.Simple(exceptionHandler)); |
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]
I noticed that when an exception is thrown by an advice and suppressed by bytebuddy, it is only printed to stdout and not to the agent logs. I don't know if this already bit us in the past but I think it might in the future: If an advice throws an exception and we only have the agentlogs without the application stdout, we might not see the actual root cause: E.g. we might see messages due to orphaned spans without the actual exception causing this.
I fixed this in this PR by adjusting how exceptions suppressed by bytebuddy are logged. Feel free to object if you don't like it, I have no problem with removing it from this PR.
You can verify the behaviour via the existing InstrumentationTest.testSuppressException
test.
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.
Awesome! We were scratching our heads how to get advice exceptions into the agent logs without manually writing byte code for the stack manipulation. 👏
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.
Ah that's nice to hear! I initially tried a different approach (wrapping the MethodHandles
, see 326db67#diff-2ec63f545539ff7d65f52ef01087a18c7cdd9eb7130de156fb412ae6fe9e580eR465), but then noticed that some Advices might intentionally throw exceptions, at least according to the tests.
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.
Nice!! 👏
/test |
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.
Beautiful addition, well done!
Two minor comments.
apm-agent-bootstrap/src/main/java/bootstrap/dispatcher/IndyBootstrapDispatcher.java
Outdated
Show resolved
Hide resolved
return new AgentBuilder.Transformer.ForAdvice(withCustomMapping) | ||
.advice(instrumentationStats.shouldMeasureMatching() ? statsCollectingMatcher : matcher, instrumentation.getAdviceClassName()) | ||
.include(ClassLoader.getSystemClassLoader(), PrivilegedActionUtils.getClassLoader(instrumentation.getClass())) | ||
.withExceptionHandler(PRINTING); | ||
.withExceptionHandler(new Advice.ExceptionHandler.Simple(exceptionHandler)); |
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.
Nice!! 👏
What does this PR do?
A user reported that our instrumentation of the elasticsearch client triggers an error when using hiberantesearch:
This error is not caught by our current instrumentation. With this PR, we simply make our code more defensive to only fail the recording of the query and not the entire adivce.
I would suggest not implementing any special case handling for hibernatesearch, as the issue has been fixed there since version 6:
hibernate/hibernate-search@8d603b1
Checklist