Skip to content

Conversation

shakuzen
Copy link
Member

@shakuzen shakuzen commented Jan 6, 2022

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

@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module labels Jan 6, 2022
@shakuzen shakuzen added this to the 2.0.0 backlog milestone Jan 6, 2022
* @param exception the exception, may be {@code null}
* @return the exception tag derived from the exception
*/
public static Tag exception(Throwable exception) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fyi In tracing we'll need to remap this. Remove it from tags and add exception to do the span.

@jonatan-ivanov
Copy link
Member

Checkstyle is not happy. :)

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.
@jonatan-ivanov jonatan-ivanov merged commit a5d6846 into micrometer-metrics:2.0.x Jan 10, 2022
@shakuzen shakuzen deleted the http-tags branch January 11, 2022 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants