micronaut-projects / micronaut-data

Ahead of Time Data Repositories
Apache License 2.0
464 stars 195 forks source link

Introducing the Observer pattern to SQL execution #2939

Open lcavadas opened 4 months ago

lcavadas commented 4 months ago

Externalising the QUERY_LOG as an observer so the same mechanism can be used for adding the query information to Spans (tracing)

graemerocher commented 4 months ago

Seems like a good idea but needs tests

lcavadas commented 4 months ago

@graemerocher Added tests for the usual suspects (CRUD) and also added a test for @Query annotated methods.

graemerocher commented 4 months ago

I wonder if it makes sense to instrument the DataSource rather than the repository implementation //cc @dstepanov @radovanradic

dstepanov commented 4 months ago

That would require introspecting statements. We have some other issue requesting combining parameters binding logging with the query, so maybe this can be combined.

graemerocher commented 4 months ago

good point, but we should probably at least enhance JdbcOperations to log no?

dstepanov commented 4 months ago

What do you mean by enhance?

lcavadas commented 4 months ago

@dstepanov I took a peek at that other issue you mentioned and while this mechanism would definitely work for that we would need to add some sort of trigger/done function to the observers in order to perform the actual logging. As I am not that familiar with this codebase I am unsure of where that trigger should actually happen. That said I'm happy to add it if you point me in the general direction of where you think it would be best to do it.

CLAassistant commented 3 weeks ago

CLA assistant check
All committers have signed the CLA.