-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Introduce support for connection instrumentation #3864
Merged
weiznich
merged 3 commits into
diesel-rs:master
from
weiznich:feature/connection_instrumentation_support
Dec 22, 2023
Merged
Introduce support for connection instrumentation #3864
weiznich
merged 3 commits into
diesel-rs:master
from
weiznich:feature/connection_instrumentation_support
Dec 22, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds functionality that allows to add a relatively fine instrumentation to our connection types by providing an essentially call back based pattern for instrumentation. The implemented setup calls the provided instrumentation type with different events. This allows the instrumentation to decide on it's own which events are important and which are unimportant. It also enables to skip most of the work (like constructing the sql of an inspected query) if the event is not handled as we just pass down an opaque wrapper that can be evaluated by the instrumentation implementation. This commit includes: * A default instrumentation implementation that does nothing * A global way to set the instrumentation implementation used by new connections * A connection specific setter to change the instrumentation implementation for a specific connection * A wild card instrumentation implementation for closures that accept the event type This commit does not include any "advanced" instrumentation implementations (based on `log` or `tracing`, etc). The idea is that these live in their own crates as it is might depend on the actual use case how the different events should be handled. The implementation of `InstrumentationEvent` is decoupled form specific backend types to allow reusing the same instrumentation for different connection types. The definition of `Instrumentation` does not depend on any connection specific stuff so that it is possible to use the same implementation for `diesel-async` as well.
Ten0
approved these changes
Dec 7, 2023
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.
I really like the design 😊
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds functionality that allows to add a relatively fine instrumentation to our connection types by providing an essentially call back based pattern for instrumentation. The implemented setup calls the provided instrumentation type with different events. This allows the instrumentation to decide on it's own which events are important and which are unimportant. It also enables to skip most of the work (like constructing the sql of an inspected query) if the event is not handled as we just pass down an opaque wrapper that can be evaluated by the instrumentation implementation.
This commit includes:
This commit does not include any "advanced" instrumentation implementations (based on
log
ortracing
, etc). The idea is that these live in their own crates as it is might depend on the actual use case how the different events should be handled.The implementation of
InstrumentationEvent
is decoupled form specific backend types to allow reusing the same instrumentation for different connection types. The definition ofInstrumentation
does not depend on any connection specific stuff so that it is possible to use the same implementation fordiesel-async
as well.This is currently marked as draft as there are some details that needs to be resolved for the row by row based postgres connection implementation. I decided to open this PR anyway to gather some feedback on the design.