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

Improvements and fixes in the SQL trace listener functionality #25088

Merged
merged 10 commits into from
Aug 21, 2024

Conversation

OndroMih
Copy link
Contributor

@OndroMih OndroMih commented Aug 12, 2024

This fixes a few issues and improves the SQL trace listener feature.

Just to remind, the SQL listener feature allows to implement the SQLTraceListener from GlassFish API, package it into a JAR, drop the JAR to domain/lib directory, and configure a connection pool to trigger this listener when SQL is executed. This allows to execute a custom Java code which gets info about SQL executed by the connection pool.

Fixes:

  • SQLTraceRecord received by a listener always returned null from getPoolName()

Improvements:

  • add getSqlQuery() method to SQLTraceRecord - returns the executed SQL query if a query was executed (some JDBC driver methods don't execute a query)
  • add getCallingApplicationMethod() method to SQLTraceRecord - returns the info about the last method in the application that triggered the query

Adds test that verify the behavior and also demonstrate usage of the SQL trace listener feature.

* @return Stack trace element that represents a call to a server component that triggered SQL execution
*/
public Optional<StackTraceElement> getCallingApplicationMethod() {
return Arrays.stream(Thread.currentThread().getStackTrace())
Copy link
Contributor

@avpinchuk avpinchuk Aug 12, 2024

Choose a reason for hiding this comment

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

Why not use StackWalker API with the RETAIN_CLASS_REFERENCE option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion, I forgot about this API. I redesigned my solution using StackWalker and moved the computation outside of the SQLTraceListener. It means that it will be computed even if the listener doesn't need it. I think it's OK because now the computation is more efficient. It's still computed only if there is at least 1 listener.

…ationMethod

- use StackWalker
- eagerly find application method and set it to SQLTraceRecord (only if there are some listeners)

This should be efficient enough and leads to a simpler design.
Copy link
Contributor

@dmatej dmatej left a comment

Choose a reason for hiding this comment

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

Seems good, just those two comments, thanks!

@dmatej dmatej added this to the 7.0.17 milestone Aug 19, 2024
@dmatej dmatej added bug Something isn't working enhancement New feature or request labels Aug 19, 2024
@dmatej dmatej requested a review from avpinchuk August 19, 2024 15:08
@OndroMih
Copy link
Contributor Author

The build is failing because of some failures unrelated to the changes in this PR.

@hs536 hs536 merged commit 0c8a14d into eclipse-ee4j:master Aug 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants