I am exploring using @observed aspect for method level simpler instrumentation code. This sample blog for the Observe API shows an example
https://spring.io/blog/2022/10/12/observability-with-spring-boot-3
@Observed(name = "user.name",
contextualName = "getting-user-name",
lowCardinalityKeyValues = {"userType", "userType2"})
String userName(String userId) {
What if I want to pass userId method parameter as a high cardinality tag as part of metrics and span generated using the @Observed tag. Can the annotation take a dynamic method parameter into ?
Or should I be writing some observationhandler to do this?
Right now you can do this one-liner:
observationRegistry.getCurrentObservation().highCardinalityKeyValue("userId", userId);
ObservationHandler
is for producing an output from Observability data so I would not use it for this purpose but you might be able to use an ObservationFilter
if this information is available in the Context
.
You can also open an iuuse/PR to add support for this, we already have similar for Timer
: https://github.com/micrometer-metrics/micrometer/pull/3727