Skip to content

Add KeyValues to Observations using annotations #5826

@JoeLee99

Description

@JoeLee99

Please describe the feature request.
I am trying to capture some metadata for my spans, specifically the param keys and values.

I know I can use the @observed annotation but it looks like it only captures lowCardinalityValues and I'm not sure if you can add in param values to them.

The only way I figured out how to capture the param values is to manually wrap the core logic in my service method in an Observation like this:

public List<Recipes> findRecipes(
            String type,
            List<UUID> ownerIds,
            Boolean includeOwner,
            Boolean includeTested,
            String sort,
            Integer limit
) {
        KeyValues lowCardinalityKeyValues = KeyValues.of(
                "type", String.valueOf(type),
                "includeOwner", String.valueOf(includeOwner),
                "includeTested", String.valueOf(includeTested),
                "sort", String.valueOf(sort),
                "limit", String.valueOf(limit)
        );

        return Observation.createNotStarted("test", observationRegistry)
                .contextualName("findRecipes")
                .lowCardinalityKeyValues(lowCardinalityKeyValues)
                .highCardinalityKeyValue("ownerIds", String.valueOf(ownerIds))
                .observe(() -> recipeDao.findRecipes(
                        type,
                        ownerIds,
                        includeTested,
                        sort,
                        limit
                ));
    }

I am looking for a better way to do this. Previously with Sleuth I was using @SpanTag and that used to work, but not any more.
Rationale
Wrapping all of the logic with an Observation works, but it looks messy and adds quite a bit of code.

Additional context
Add any other context about the feature request here, e.g. related issues, prior art.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions