Hydrate custom attributes http.server.request.duration #14825
-
Is there a way to add a new attribute to this metric e.g tenant or account id as a low cardinality attribute? I already achieved this form This is how looks the spring boot observation one just for context @Component
@Slf4j
public class CustomHttpServerObservationConvention extends DefaultServerRequestObservationConvention {
/**
* Adds custom low cardinality key values to the observation context.
* Specifically, it adds the account SID from the request attributes if present.
*
* @param context The server request observation context
* @return KeyValues containing the custom tags
*/
@Override
public KeyValues getLowCardinalityKeyValues(final ServerRequestObservationContext context) {
KeyValues keyValues = super.getLowCardinalityKeyValues(context);
final BaggageEntry accountSid = Baggage.current().getEntry(Tags.ACCOUNT_SID);
if (Objects.nonNull(accountSid) && !isBlank(accountSid.getValue())) {
return keyValues.and(Tags.ACCOUNT_SID, accountSid.getValue());
}
log.warn("Account SID is missing in baggage for request");
return keyValues;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You could use the experimental https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/instrumenter/InstrumenterCustomizerProvider.java api to add an |
Beta Was this translation helpful? Give feedback.
You could use the experimental https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/instrumenter/InstrumenterCustomizerProvider.java api to add an
AttributesExtractor
that provides the value you wish to add. This will add the the attribute to the span, to add it to the metric you will need to configure a metric view https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/incubator that includes the new attribute. Currently you can decide whether to customize an instrumenter based on the instrumentation nameopentelemetry-java-instrumentation/instrum…