Skip to content

Create baggage scope for method using annotations #1270

@stuartkemp-e

Description

@stuartkemp-e

Please describe the feature request.
I would like to be able to put values into baggage scope for the duration of a method using annotations. I would like to be able to use static values, or values from the method arguments.

Rationale
In my Spring Boot application I have several controllers. For each controller, I want to put some values from the method arguments into baggage. I currently do that by wrapping the whole controller like this:

void doSomething(String value1) {
   try (BaggageInScope scope = this.tracer.createBaggageInScope("customer.id", "value1")) {
   // Business logic
   }
}

This approach pollutes my business logic, as every controller is in a try block related to tracing. It would be good if I could so something like:

@Observed
void doSomething(@BaggageInScope((key = "customer.id") String value1) {
   // Business logic
}

Additional context
I've had a look at @ObservationKeyValue which was added under this ticket micrometer-metrics/micrometer#4030. This seems related to this request, but I don't think @ObservationKeyValue puts anything into Baggage scope.

In my Spring Boot application I have written an Aspect to do pretty much the same thing as described above using a custom annotation. It works well. I was thinking something similar would be a good feature in Micrometer generally?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions