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.
Subsystem
Client
Motivation
Provide a plugin to instrument Ktor client similarly to how the server lib is instrumented with Micrometer.
Solution
This is basically just a PoC to discuss if the approach is okay or not. If it's okay, then I'll proceed with adding tests etc. If not, then we can discuss it here.
The idea here is to provide a client instrumentation similar to how it's done in OkHttpMetricsEventListener - introduce a timer for client requests.
The implementation is heavily inspired by the Logging plugin.
Since using an expanded URI as the value for the URI tag can lead to cardinality blow up, I had to introduce support for URI templates. This is done in 0e542bd. While those methods could potentially be added as extension functions in the plugin module, it feels like they belong to the core lib more.
( Probably a better option there would be to have a set of explicit builder functions like:
Then it wouldn't be necessary to rebuild the URL. This is the path Spring followed with their client for example: https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java#L400 )
The URI template is stored as a call attribute with the first call to
HttpRequestBuilder.pathParameters
and is later used inMicrometerMetrics
plugin.Here's how using the new methods would look like:
The plugin is implemented in 2e9cab1 and provides configuration to make it flexible enough to cover most of the use cases.
The timer will be started when request has been sent and will be stopped either when an exception has occurred, or when the response has been received.