Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding metadata to an observation #5826

Open
JoeLee99 opened this issue Jan 26, 2025 · 3 comments
Open

Adding metadata to an observation #5826

JoeLee99 opened this issue Jan 26, 2025 · 3 comments
Milestone

Comments

@JoeLee99
Copy link

JoeLee99 commented Jan 26, 2025

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.

@jonatan-ivanov
Copy link
Member

This is similar to what we have with @MeterTag, we could have a @...KeyValue... annotation that works the same and also let's you define if the KeyValue is low or high cardinality.

@Observed cannot capture high cardinality values since annotation arguments cannot be dynamic in java.

@jonatan-ivanov
Copy link
Member

Do you want to try implementing it and open a PR for this?
For the reference, you can look at @MeterTag (in Micrometer) and @SpanTag (in Micrometer Tracing).

@JoeLee99
Copy link
Author

Sure, I would love to give it a go.
Thanks I will look at those repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants