Introduce HttpTagsProvider with default implementation by shakuzen · Pull Request #2945 · micrometer-metrics/micrometer (original) (raw)
This allows us to provide a consistent default set of HTTP tags derived from the abstract request/response API that instrumentation will wrap using their concrete HTTP request/response objects.
It also allows end users (not instrumentors) to provide their own implementation if they want a different set of tags without rewriting the instrumentation provided.
TODO:
- Tests
- Replace existing instrumentation in micrometer that could use this.
It's unfortunate it shares the name and purpose of the TagsProvider interface but does not extend it because it has parameters specific to it. Perhaps this is something to consider evolving in a more clear way later on.
Example usage of this in instrumentation is like the following. Pass an HttpTagsProvider instance to the HttpHandlerContext being used with your Timer.start calls. For convenience, a constructor without HttpTagsProvider is available that will use the default implementation.
HttpClientRequest wrappedRequest = new SpringHttpClientRequest(request); HttpClientHandlerContext handlerContext = new HttpClientHandlerContext(wrappedRequest, this.tagsProvider); Timer.Sample sample = Timer.start(this.meterRegistry, handlerContext);
// do an HTTP operation
HttpClientResponse wrappedResponse = new SpringHttpClientResponse(response, wrappedRequest); handlerContext.setResponse(wrappedResponse); sample.stop(getTimeBuilder(wrappedRequest, wrappedResponse, null)); // a caught exception can be passed here instead of null