Skip to content

Conversation

@laurit
Copy link
Contributor

@laurit laurit commented Oct 29, 2025

Add an option to specify a custom propagator, allow prepending the comment instead of appending, add an experimental api that allows extensions to chose the behavior based on the connection.

@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Oct 29, 2025
});
}

private static void addSqlCommenterCustomizers(ClassLoader extensionClassLoader) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on addHttpServerResponseCustomizers that is right before this method. It supports multiple customizers but really probably works best when there is only once customizers, since since the customizers would most likely end up overwriting what the previous customizer has set.

@laurit laurit marked this pull request as ready for review October 29, 2025 10:41
@laurit laurit requested a review from a team as a code owner October 29, 2025 10:41
Copy link
Member

@zeitlinger zeitlinger left a comment

Choose a reason for hiding this comment

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

great 😄

* @param propagator a function that receives the database connection and whether the query is
* executed only once or could be reused. Connection may be a jdbc Connection, R2DBC
* Connection, or any other connection type used by the data access framework performing the
* operation. If the second argument to the function is true, the query is executed only once
Copy link
Member

Choose a reason for hiding this comment

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

is the second argument called safe above? If so, it sounds like it should be called once to match this description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is the second argument called safe above? If so, it sounds like it should be called once to match this description

yes it is. Open to suggestions for a better name. What I wanted to express is that when you use Connection.prepareStatement then adding dynamic components to the query text isn't always safe as it wouldn't work correctly when the prepared statement is reused (tracing context points to where the query is prepared not where it is executed). In contrast when you use Statement.execute then you won't have that issue. Based on that boolean instrumentations could choose to use different strategies.

Copy link
Member

Choose a reason for hiding this comment

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

safe is a good name - but I wasn't sure if it aligns with the javadoc

if true .. only once

it sounds like safe would allow you to do things more than once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed safe to executed. I had the value flipped for most of the callers, should be corrected now.

* @param connection connection object, e.g. JDBC connection or R2DBC connection, that is used to
* execute the query
* @param sql original query
* @param executed whether the query is immediately executed after being processed, e.g. {@link
Copy link
Member

Choose a reason for hiding this comment

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

maybe it should be an enum since a boolean is so hard to get right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perhaps we should leave it for later when it is clear whether having this information is useful at all

Copy link
Member

Choose a reason for hiding this comment

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

your call - I just find the boolean a bit hard to follow

@laurit laurit added this to the v2.22.0 milestone Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants