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
Log metrics recording failures in CountedAspect and TimedAspectΒ #5820
For Counter/Timer annotation argument extraTags defined as array of string, but requires even items becuase it is key->value pair.
It's not obvious.
I spet half day before until I saw the documentation.
Then I remembered that I had already encountered this a couple of years ago.
Thanks for the issue!
My brain is definitely spoiled here and I cannot unlearn the knowledge that tags are key-value pairs so your input on this would be definitely helpful.
Could you please tell us:
What you tried to do before you looked at the docs?
What was your first impression about the usage of extraTags, what did you think it does?
Why you spent half a day before looking at the docs?
I think we could improve the javadocs and add this fact to even more places but right now you can see this if you look into the docs:
* @param tags Must be an even number of arguments representing key/value pairs of
* tags.
* @return This builder.
*/
publicBtags(String... tags) {
returntags(Tags.of(tags));
}
I think we could add a sentence that the array must have an even number of elements in Counted.java and Timed.java as well but you you should get an exception if you don't:
What you tried to do before you looked at the docs?
First I tried to use single value for tags. It not lead to error or any log, but metric was not presented in actuator.
@Timed("batcher", extraTags = ["write"])
What was your first impression about the usage of extraTags, what did you think it does?
I have some work experience with prometheus and I know what the end result looks like, but I just got stuck :)
Why you spent half a day before looking at the docs?
Half a day is not literally. I tried searching cause in another mechanisms. First I thougt about incorrect using Bean (our code call proxied bean from non-proxied and I spend time to remade it, but it had no effect. Then I thought about incorrect aspectjwaver install and that this problem may related with spring upgrading. I did not focus on this annotation first.
I think it would be a good idea to add a log or fail startup when incorrect items count provided for extraTags.
I think we could add a sentence that the array must have an even number of elements in Counted.java and Timed.java as well but you you should get an exception if you don't
First I tried to use single value for tags. It not lead to error or any log, but metric was not presented in actuator.
@Timed("batcher", extraTags = ["write"])
What was your expectation what should have happened in this case?
Hmm, no. It's not work, no any exceptions.
Do you have a minimal sample project to reproduce this issue? Or could you please check with a debugger where the exception is swallowed so that we can fix this? In usual setups TimedAspect should call Tags.of(String...) which should throw an exception but I'm not sure if you use TimedAspect or something else wraps your annotated methods.
What was your expectation what should have happened in this case?
I didn't think about it :)
In usual setups TimedAspect should call Tags.of(String...) which should throw an exception but I'm not sure if you use TimedAspect or something else wraps your annotated methods.
Yes, I using Timed/Counted aspects. And its has different behavior:
Counted throws this exception IllegalArgumentException("size must be even, it is a set of key=value pairs");
Activity
jonatan-ivanov commentedon Jan 23, 2025
Thanks for the issue!
My brain is definitely spoiled here and I cannot unlearn the knowledge that tags are key-value pairs so your input on this would be definitely helpful.
Could you please tell us:
extraTags, what did you think it does?I think we could improve the javadocs and add this fact to even more places but right now you can see this if you look into the docs:
micrometer/micrometer-core/src/main/java/io/micrometer/core/annotation/Counted.java
Lines 55 to 61 in c39bda3
micrometer/micrometer-core/src/main/java/io/micrometer/core/instrument/Counter.java
Lines 77 to 84 in c39bda3
micrometer/micrometer-core/src/main/java/io/micrometer/core/annotation/Timed.java
Lines 46 to 51 in c39bda3
micrometer/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimerBuilder.java
Lines 54 to 61 in c39bda3
I think we could add a sentence that the array must have an even number of elements in
Counted.javaandTimed.javaas well but you you should get an exception if you don't:micrometer/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java
Lines 362 to 364 in c39bda3
Do you want to open a PR to improve the docs of
Counted.javaandTimed.java?TheHett commentedon Jan 24, 2025
Hi!
First I tried to use single value for tags. It not lead to error or any log, but metric was not presented in actuator.
I have some work experience with prometheus and I know what the end result looks like, but I just got stuck :)
Half a day is not literally. I tried searching cause in another mechanisms. First I thougt about incorrect using Bean (our code call proxied bean from non-proxied and I spend time to remade it, but it had no effect. Then I thought about incorrect
aspectjwaverinstall and that this problem may related with spring upgrading. I did not focus on this annotation first.I think it would be a good idea to add a log or fail startup when incorrect items count provided for
extraTags.TheHett commentedon Jan 24, 2025
Hmm, no. It's not work, no any exceptions.
jonatan-ivanov commentedon Jan 25, 2025
What was your expectation what should have happened in this case?
Do you have a minimal sample project to reproduce this issue? Or could you please check with a debugger where the exception is swallowed so that we can fix this? In usual setups
TimedAspectshould callTags.of(String...)which should throw an exception but I'm not sure if you useTimedAspector something else wraps your annotated methods.TheHett commentedon Jan 27, 2025
I didn't think about it :)
Yes, I using Timed/Counted aspects. And its has different behavior:
IllegalArgumentException("size must be even, it is a set of key=value pairs");I debugged it and found ignoring:
https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java#L275
Sorry, I can't provide PR becuase I don't know why is it implemented so differently. Maybe it should be globally refactored.
Log metrics recording failures in CountedAspect and TimedAspect
izeye commentedon Feb 1, 2025
In general, observability shouldn't interfere with application flow, so it seems that the
CountedAspectneeds to be fixed.I created #5841 to try to resolve it, and also added logging for metrics recoding failures for their discoverability in the PR.
[-]extraTags is array but key->value[/-][+]Log metrics recording failures in CountedAspect and TimedAspect[/+]Log metrics recording failures in CountedAspect and TimedAspect (#5841)