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

Allow injecting a function into TimedAspect to create tags based on method result #3058

Open
kevinkraus opened this issue Mar 7, 2022 · 11 comments · May be fixed by #5587
Open

Allow injecting a function into TimedAspect to create tags based on method result #3058

kevinkraus opened this issue Mar 7, 2022 · 11 comments · May be fixed by #5587
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module

Comments

@kevinkraus
Copy link

kevinkraus commented Mar 7, 2022

Please describe the feature request.
Update TimedAspect to allow injecting a Function to create tags based on method result, similar to the Function injected to create tags based on ProceedingJoinPoint.

Rationale
I am using the Timed annotation and would like to include information from the Object returned by the target method in the tags.

Additional context
I'm willing to submit a PR for this enhancement.

@axel-malagraba-sw
Copy link

Hi, any news on this? I think that would be really interesting, not just for TimedAspect but for CountedAspect as well. I'm also willing to participate in the implementation.

@marcingrzejszczak
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak added the waiting for feedback We need additional information before we can continue label Dec 20, 2023
Copy link

github-actions bot commented Jan 2, 2024

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
@izeye
Copy link
Contributor

izeye commented Jan 19, 2024

This seems to suggest adding a function that provides tags from the return value of ProceedingJoinPoint.proceed() while Micrometer currently supports a function that provides tags from ProceedingJoinPoint.

@jonatan-ivanov jonatan-ivanov added enhancement A general enhancement module: micrometer-core An issue that is related to our core module and removed waiting for feedback We need additional information before we can continue feedback-reminder closed-as-inactive labels Feb 7, 2024
@jonatan-ivanov jonatan-ivanov reopened this Feb 7, 2024
@MarinaMoiseenko
Copy link
Contributor

Hi @jonatan-ivanov,

Would you be interested in help with this?

@shakuzen
Copy link
Member

I think we would consider a pull request if you're willing to work on this @MarinaMoiseenko.

@jonatan-ivanov
Copy link
Member

Yes please, if you want to file a PR for this, we are happy to review it.
@shakuzen Maybe such a PR would be a good opportunity to have a TagsProvider<T> interface in core?

@shakuzen
Copy link
Member

Maybe such a PR would be a good opportunity to have a TagsProvider<T> interface in core?

I'm not sure. I'd be happy to look at a proposal, but I think it may distract from getting this specific feature merged to do it together. It's not immediately obvious to me at least what the right design for such an interface would be and how it would be incorporated (or wouldn't be incorporated) into existing instrumentation or other parts of the code. I get it feels weird to have unrelated tags provider types for each instrumentation, but I also wonder what would be gained by having a common type. But if someone has a good idea for it, let's look at it.

@MarinaMoiseenko
Copy link
Contributor

If you don't mind, couple of questions:

Q1: Wouldn't it be too "global" having ability to set result tags extractor in TimedAspect?

What I mean is that client's functions vary one from another. Therefore having just one common function across all methods to produce tags based on method result could be cumbersome. So, it looks like having more granular approach would be better. Something similar to @MeterTag, but on method level.

For example, to change "@TimedAspect" code from this:

        if (meterTagAnnotationHandler != null) {
            meterTagAnnotationHandler.addAnnotatedParameters(builder, pjp);
        }

to this (roughly):

        if (meterTagAnnotationHandler != null) {
            meterTagAnnotationHandler.addAnnotatedParameters(builder, pjp);
            meterTagAnnotationHandler.addAnnotatedResult(builder, pjp, methodResult); 
        }

Where meterTagAnnotationHandler.addAnnotatedResult is new method. Alternatively a new similar annotation could be created to have "@MeterMethodTag" (for example) and MeterMethodTagAnnotationHandler. But main idea stays the same.
methodResult - will be passed to private Timer.Builder recordBuilder(...) as an argument.

Then usage of it would look like:

        @Timed
        @MeterTag(key = "test", resolver = ValueResolver.class)
        String getAnnotationForTagValueResolver();

        @Timed
        @MeterTags({
            @MeterTag(key = "value1", expression = "'value1: ' + value1"),
            @MeterTag(key = "value2", expression = "'value2: ' + value2"), @MeterTag(key = "value3",
            expression = "'value3: ' + value1.toUpperCase + value2.toUpperCase") })
        public DataHolder getMultipleAnnotationsWithContainerForTagValueExpression() {
            return new DataHolder("zxe", "qwe");
        }

Q2: Should @ Counted have the same feature?

Q3: Would you consider using Builder pattern for TimedAspect if there is still a need to provide TimedAspect with additional settings.

In the main branch there are different methods for setting up different "tags providers":

  • based on ProceedingJointPoint through constructor
  • based on annotations through setter
    which looks inconsistent.

@shakuzen
Copy link
Member

shakuzen commented Oct 7, 2024

Q1: Wouldn't it be too "global" having ability to set result tags extractor in TimedAspect?

Probably. This is something we should get feedback from the users who want this feature. I think extending @MeterTag to work with result objects makes sense to me.

Q2: Should @ Counted have the same feature?

Sure. @MeterTag works with @Counted as well, so it would make sense for this new feature to work with it as well.

Q3: Would you consider using Builder pattern for TimedAspect if there is still a need to provide TimedAspect with additional settings.

I don't remember the details, but the history is in Git. The default constructor was added because it made it easier to use LTW, according to #1419. The setter was added with #3727:

Adds a setter to TimedAspect (too many constructors already)

I'm not opposed to a builder pattern but we should consider how it will be used (can it be used?) in the different ways the aspect may end up being configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Projects
Status: To do
Development

Successfully merging a pull request may close this issue.

7 participants