-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add KeyValues to Observations using annotations #6667
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...r-observation/src/main/java/io/micrometer/observation/annotation/ObservationKeyValue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright 2025 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.observation.annotation; | ||
|
|
||
| import io.micrometer.common.annotation.NoOpValueResolver; | ||
| import io.micrometer.common.annotation.ValueExpressionResolver; | ||
| import io.micrometer.common.annotation.ValueResolver; | ||
| import io.micrometer.observation.aop.Cardinality; | ||
| import io.micrometer.observation.aop.ObservationKeyValueAnnotationHandler; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| /** | ||
| * There are 3 different ways to add key-values to an observation. All of them are | ||
| * controlled by the annotation values. Precedence is to first try with the | ||
| * {@link ValueResolver}. If the value of the resolver wasn't set, try to evaluate an | ||
| * expression. If there's no expression just return a {@code toString()} value of the | ||
| * parameter. {@link Cardinality} also can be set by {@link #cardinality()}. default value | ||
| * is {@link Cardinality#HIGH}. | ||
| * | ||
| * @author Seungyong Hong | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Inherited | ||
| @Target({ ElementType.PARAMETER, ElementType.METHOD }) | ||
| @Repeatable(ObservationKeyValues.class) | ||
| public @interface ObservationKeyValue { | ||
|
|
||
| /** | ||
| * The name of the key of the key-value which should be created. This is an alias for | ||
| * {@link #key()}. | ||
| * @return the key-value key name | ||
| */ | ||
| String value() default ""; | ||
|
|
||
| /** | ||
| * The name of the key of the key-value which should be created. | ||
| * @return the key-value key name | ||
| */ | ||
| String key() default ""; | ||
|
|
||
| /** | ||
| * Execute this expression to calculate the key-value value. Will be evaluated if no | ||
| * value of the {@link #resolver()} was set. You need to have a | ||
| * {@link ValueExpressionResolver} registered on the | ||
| * {@link ObservationKeyValueAnnotationHandler} to provide the expression resolution | ||
| * engine. | ||
| * @return an expression | ||
| */ | ||
| String expression() default ""; | ||
|
|
||
| /** | ||
| * Use this object to resolve the key-value value. Has the highest precedence. | ||
| * @return {@link ValueResolver} class | ||
| */ | ||
| Class<? extends ValueResolver> resolver() default NoOpValueResolver.class; | ||
|
|
||
| /** | ||
| * Cardinality of the key-value. | ||
| * @return {@link Cardinality} class | ||
| */ | ||
| Cardinality cardinality() default Cardinality.HIGH; | ||
|
|
||
| } |
38 changes: 38 additions & 0 deletions
38
...-observation/src/main/java/io/micrometer/observation/annotation/ObservationKeyValues.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2025 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.observation.annotation; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| /** | ||
| * Container annotation that aggregates several {@link ObservationKeyValue} annotations. | ||
| * | ||
| * Can be used natively, declaring several nested {@link ObservationKeyValue} annotations. | ||
| * Can also be used in conjunction with Java 8's support for repeatable annotations, where | ||
| * {@link ObservationKeyValue} can simply be declared several times on the same parameter, | ||
| * implicitly generating this container annotation. | ||
| * | ||
| * @author Seungyong Hong | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Inherited | ||
| @Target({ ElementType.PARAMETER, ElementType.METHOD }) | ||
| @Documented | ||
| public @interface ObservationKeyValues { | ||
|
|
||
| ObservationKeyValue[] value(); | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
micrometer-observation/src/main/java/io/micrometer/observation/aop/Cardinality.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2025 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.observation.aop; | ||
|
|
||
| /** | ||
| * Represents the cardinality of a key-value. There are two types of cardinality and | ||
| * treated in different ways. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth clarifying this is for use with the annotation, specifically. There's no way to use it with |
||
| * | ||
| * @author Seungyong Hong | ||
| * @author Jonatan Ivanov | ||
| */ | ||
| public enum Cardinality { | ||
|
|
||
| HIGH, LOW | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.