micronaut-projects / micronaut-projects/micronaut-micrometer

Evaluated expressions not working in all annotations they should be (ex: `io.micrometer.core.annotation.Timed`)

Open
#1,237 1 comment 0 reactions 0 assignees View on GitHub
lang: kotlin status: awaiting validation type: bug
Dominant language
Java
Stars
43
Forks
69
Avg merge
1d 8h
Merged PRs (30d)
13

Description

### Discussed in https://github.com/micronaut-projects/micronaut-core/discussions/10531

Originally posted by **hrothwell** February 22, 2024
Was playing around with expression language usage (which also gave way to https://github.com/micronaut-projects/micronaut-core/issues/10529) and figured this specific question might be better suited as a discussion:

does expression evaluation only work in Micronaut annotations? ie can I not do something like `@Timed(value = "my_metric", extraTags = ["custom", "#{this.someProperty}"])` in the core micrometer annotation? (`io.micrometer.core.annotation.Timed`)

If that is the case, can the annotation processor be configured such that it does look at other annotations to perform expression evaluation on?

## Expected behavior

When using an evaluated expression in annotations such as micrometer's `@Timed` the expression should be evaluated when it is intercepted via `io.micronaut.aop.chain.InterceptorChain`.

There seem to possibly be two issues at hand:
1. If the expression is in an array value of the annotation, the annotation metadata is not flagged/marked as being an `EvaluatedAnnotationMetadata`
2. Even when the annotation metadata is properly flagged as `EvaluatedAnnotationMetadata`, the value is not evaluated. This might be due to something unrelated, but it seems to me like it might be an issue where the annotation metadata actually contains other annotation data
a. While debugging, `@Timed` seemed to turn into `@TimedSet` as it is repeatable, and I feel like there is something in `EvaluatedAnnotationValue` that is part of the cause but after a day of digging I cannot quite find what it might be on my own.
b. ![image](https://github.com/micronaut-projects/micronaut-micrometer/assets/46227616/62cf4284-5552-43cd-9ffc-7a602175329a)

## version
4.3.6+

## example application
https://github.com/hrothwell/micronaut-demo/tree/timed-annotation-expression

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with io.micronaut.aop.chain.InterceptorChain, then trace EvaluatedAnnotationMetadata and EvaluatedAnnotationValue for the repeatable @Timed/@TimedSet annotation. Use the linked example application to reproduce an expression in an array-valued @Timed attribute; done means the metadata is marked for evaluation and the expression resolves when the interceptor runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.