You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow TimedAspect/CountedAspect to create tags based on method result #3058
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.
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.
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.
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.
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?
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.
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);
}
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.
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.
changed the title [-]Allow injecting a function into TimedAspect to create tags based on method result[/-][+]Allow TimedAspect to create tags based on method result[/+]on Feb 12, 2025
changed the title [-]Allow TimedAspect to create tags based on method result[/-][+]Allow TimedAspect/CountedAspect to create tags based on method result[/+]on Feb 12, 2025
Activity
axel-malagraba-sw commentedon Sep 13, 2022
Hi, any news on this? I think that would be really interesting, not just for
TimedAspectbut forCountedAspectas well. I'm also willing to participate in the implementation.marcingrzejszczak commentedon Dec 20, 2023
We already have it since 1.7.0? https://github.com/micrometer-metrics/micrometer/blob/v1.12.1/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java#L156 Or am I missing sth?
github-actions commentedon 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.
github-actions commentedon Jan 10, 2024
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.
izeye commentedon 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 fromProceedingJoinPoint.MarinaMoiseenko commentedon Sep 19, 2024
Hi @jonatan-ivanov,
Would you be interested in help with this?
shakuzen commentedon Sep 20, 2024
I think we would consider a pull request if you're willing to work on this @MarinaMoiseenko.
jonatan-ivanov commentedon Sep 20, 2024
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 commentedon Sep 20, 2024
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 commentedon Sep 20, 2024
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:
to this (roughly):
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:
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":
which looks inconsistent.
shakuzen commentedon Oct 7, 2024
Probably. This is something we should get feedback from the users who want this feature. I think extending
@MeterTagto work with result objects makes sense to me.Sure.
@MeterTagworks with@Countedas well, so it would make sense for this new feature to work with it as well.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:
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.
[-]Allow injecting a function into TimedAspect to create tags based on method result[/-][+]Allow TimedAspect to create tags based on method result[/+][-]Allow TimedAspect to create tags based on method result[/-][+]Allow TimedAspect/CountedAspect to create tags based on method result[/+]Added support for `@MeterTag` annotation on method level (#5827)