spring-boottracemicrometerspring-micrometerobservation

How to put argument values to traces of method annotated with @Observed


I have a method annotated with @Observed annotation:

@Observed(
    name = "foo",
    contextualName = "foo",
)
fun foo(arg1: String, arg2: Integer){...}

When I go to Zipkin I see corresponding trace but it contains only method name and information about spring boot version:

enter image description here

It would be useful to have argument values in the trace. Is there way to achieve it ?


Solution

  • You can do this:

    @Observed(
        name = "test.call",
        contextualName = "test#call",
        lowCardinalityKeyValues = { "abc", "123", "test", "42" }
    )
    

    See the docs: https://docs.micrometer.io/micrometer/reference/observation/components.html#micrometer-observation-annotations

    If you want to attach key-values dynamically, you cannot use the annotation:

    Observation.createNotStarted("foo", registry)
                    .lowCardinalityKeyValue("lowTag", "lowTagValue")
                    .highCardinalityKeyValue("highTag", "highTagValue")
                    .observe(() -> System.out.println("Hello"));
    
    

    See the docs: https://docs.micrometer.io/micrometer/reference/observation/introduction.html