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

Introduce support for connection instrumentation #3864

Merged

Conversation

weiznich
Copy link
Member

@weiznich weiznich commented Dec 1, 2023

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.

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.

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.
@weiznich weiznich requested a review from a team December 1, 2023 13:47
@weiznich weiznich added the run-benchmarks Used to indicate that github actions should run our benchmark suite label Dec 1, 2023
Copy link
Member

@Ten0 Ten0 left a 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 😊

@weiznich weiznich added run-benchmarks Used to indicate that github actions should run our benchmark suite and removed run-benchmarks Used to indicate that github actions should run our benchmark suite labels Dec 15, 2023
@weiznich weiznich marked this pull request as ready for review December 15, 2023 12:37
@weiznich weiznich added this pull request to the merge queue Dec 22, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 22, 2023
@weiznich weiznich added this pull request to the merge queue Dec 22, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 22, 2023
@weiznich weiznich added this pull request to the merge queue Dec 22, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 22, 2023
@weiznich weiznich added this pull request to the merge queue Dec 22, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 22, 2023
@weiznich weiznich added this pull request to the merge queue Dec 22, 2023
Merged via the queue into diesel-rs:master with commit ca3ba76 Dec 22, 2023
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-benchmarks Used to indicate that github actions should run our benchmark suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants