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
Document how to customize tags in micrometer-java11 HttpClient instrumentation #4962
Comments
Thank you for opening the issue. How is the For the class MyHttpClientObservationConvention extends DefaultHttpClientObservationConvention {
@Override
public KeyValues getLowCardinalityKeyValues(HttpClientContext context) {
return super.getLowCardinalityKeyValues(context).and("clientName", deriveClientName(context));
}
} When creating the We recently added basic documentation for the Does that answer your questions? |
Hello @shakuzen, Thanks for getting back to me. I tried your suggestion, but I'm still not seeing the custom tags. Also, I set breakpoints to check if the methods are being called, and it seems they aren't. package com.example;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.java11.instrument.binder.jdk.MicrometerHttpClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import java.net.http.HttpClient;
@ApplicationScoped
public class HttpClientProvider {
@Inject MeterRegistry meterRegistry;
@Produces
HttpClient httpClient() {
var httpClient = HttpClient.newBuilder().build();
return MicrometerHttpClient.instrumentationBuilder(httpClient, meterRegistry)
.customObservationConvention(new CustomDefaultHttpClientObservationConvention("theClient"))
.uriMapper((request) -> request.uri().toString())
.build();
}
} package com.example;
import io.micrometer.common.KeyValues;
import io.micrometer.common.lang.NonNull;
import io.micrometer.java11.instrument.binder.jdk.DefaultHttpClientObservationConvention;
import io.micrometer.java11.instrument.binder.jdk.HttpClientContext;
public class CustomDefaultHttpClientObservationConvention
extends DefaultHttpClientObservationConvention {
private final String clientName;
public CustomDefaultHttpClientObservationConvention(String clientName) {
this.clientName = clientName;
}
@Override
@NonNull
public KeyValues getLowCardinalityKeyValues(HttpClientContext context) {
if (context.getCarrier() == null) {
return KeyValues.empty();
}
return super.getLowCardinalityKeyValues(context).and("clientName", clientName);
}
}
Answering your question, Quarkus uses the
So, even if this works, it can also lead issues since the method |
Sorry, I should have mentioned, MicrometerHttpClient.instrumentationBuilder(httpClient, meterRegistry)
.observationRegistry(observationRegistry) // use an ObservationRegistry for instrumentation
.customObservationConvention(new CustomDefaultHttpClientObservationConvention("theClient"))
.uriMapper((request) -> request.uri().toString())
.build(); I'm not sure if Quarkus produces an @Produces
ObservationRegistry observationRegistry() {
ObservationRegistry registry = ObservationRegistry.create();
registry.observationConfig().observationHandler(new DefaultMeterObservationHandler(meterRegistry));
return registry;
} The
The HTTP request is available from |
Amazing @shakuzen, I was able to add the custom metrics. Thank you for your support! |
I'm glad you were able to get it to work. We'll use this issue to track improving the documentation to mention configuring a custom ObservationConvention to customize the tags, then, unless you think there's any other change that needs to be made. |
@shakuzen, I currently don't need this feature, but I suggest an improvement for the HttpClientContext. As of now, access is limited to using the Request builder, which could lead to a large number of objects that later need to be garbage collected. Additionally, there's no way to access the Response. For example, if we need to extract a header from the Response to create a tag, that isn't possible with the current setup. Ideally, access to both the Request and Response objects should be provided within the HttpClientContext. Please let me know if there are existing solutions I might have overlooked. |
As part of instrumentation, we may need to configure a header on the request, which is why we need the builder rather than an immutable request.
There is a |
You are right @shakuzen. Thanks for your explanation. |
Currently my company is transitioning to the Quarkus ecosystem, we've found the integration with Micrometer nothing less than amazing. However, we must continue supporting applications that rely on other frameworks and various external SDKs. Our goal is to standardize metrics across these different libraries and frameworks.
Quarkus provides excellent metrics instrumentation for
http_client_*
using the microprofile-rest-client, as you can see the result below:However, using micrometer-java11, the metrics are slightly different, lacking the
clientName
tag:Despite exploring the library, I have not found a way to customize micrometer-java11 to mirror the
clientName
tag functionality. I am aware of theuriMapper
capability to customize theuri
value.Here are my questions:
The text was updated successfully, but these errors were encountered: