-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Micrometer Observation Support (#585)
This PR instruments: https://micrometer.io/docs/observation for metrics and traces. --------- Co-authored-by: Denis Stepanov <[email protected]> Co-authored-by: Graeme Rocher <[email protected]>
- Loading branch information
1 parent
d5ec9f3
commit b437b8c
Showing
39 changed files
with
2,804 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
49 changes: 49 additions & 0 deletions
49
...src/main/java/io/micronaut/micrometer/annotation/processing/ObservedAnnotationMapper.java
This file contains 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,49 @@ | ||
/* | ||
* Copyright 2017-2021 original authors | ||
* | ||
* 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.micronaut.micrometer.annotation.processing; | ||
|
||
import io.micrometer.observation.annotation.Observed; | ||
import io.micronaut.aop.InterceptorBinding; | ||
import io.micronaut.aop.InterceptorKind; | ||
import io.micronaut.core.annotation.AnnotationValue; | ||
import io.micronaut.inject.annotation.TypedAnnotationMapper; | ||
import io.micronaut.inject.visitor.VisitorContext; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Adds interceptor binding to {@link Observed}. | ||
* | ||
* @since 3.4.0 | ||
* @author Nemanja Mikic | ||
*/ | ||
public class ObservedAnnotationMapper implements TypedAnnotationMapper<Observed> { | ||
@Override | ||
public Class<Observed> annotationType() { | ||
return Observed.class; | ||
} | ||
|
||
@Override | ||
public List<AnnotationValue<?>> map(AnnotationValue<Observed> annotation, VisitorContext visitorContext) { | ||
return Collections.singletonList( | ||
AnnotationValue.builder(InterceptorBinding.class) | ||
.value(Observed.class) | ||
.member("kind", InterceptorKind.AROUND) | ||
.build() | ||
); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...tion/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
io.micronaut.micrometer.annotation.processing.CountedAnnotationMapper | ||
io.micronaut.micrometer.annotation.processing.TimedSetAnnotationMapper | ||
io.micronaut.micrometer.annotation.processing.TimedSetAnnotationMapper | ||
io.micronaut.micrometer.annotation.processing.ObservedAnnotationMapper |
This file contains 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 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 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 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
37 changes: 37 additions & 0 deletions
37
...rc/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsClientCondition.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* 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.micronaut.configuration.metrics.binder.web; | ||
|
||
import io.micronaut.context.condition.Condition; | ||
import io.micronaut.context.condition.ConditionContext; | ||
import io.micronaut.core.reflect.ClassUtils; | ||
|
||
/** | ||
* A custom {@link Condition} that defines if {@link ClientRequestMetricRegistryFilter} should be created. | ||
*/ | ||
public class WebMetricsClientCondition implements Condition { | ||
@Override | ||
public boolean matches(ConditionContext context) { | ||
boolean isClassPresent = ClassUtils.isPresent("io.micronaut.micrometer.observation.http.client.ObservationClientFilter", context.getBeanContext().getClassLoader()); | ||
|
||
if (!context.containsProperty("micrometer.observation.http.client.enabled") && isClassPresent) { | ||
return false; | ||
} | ||
|
||
return !context.containsProperty("micrometer.observation.client.server.enabled") || !context.getProperty("micrometer.observation.http.client.enabled", Boolean.class).orElse(false); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...rc/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsServerCondition.java
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* 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.micronaut.configuration.metrics.binder.web; | ||
|
||
import io.micronaut.context.condition.Condition; | ||
import io.micronaut.context.condition.ConditionContext; | ||
import io.micronaut.core.reflect.ClassUtils; | ||
|
||
/** | ||
* A custom {@link Condition} that defines if {@link ServerRequestMeterRegistryFilter} should be created. | ||
*/ | ||
public class WebMetricsServerCondition implements Condition { | ||
@Override | ||
public boolean matches(ConditionContext context) { | ||
boolean isClassPresent = ClassUtils.isPresent("io.micronaut.micrometer.observation.http.server.ObservationServerFilter", context.getBeanContext().getClassLoader()); | ||
|
||
if (!context.containsProperty("micrometer.observation.http.server.enabled") && isClassPresent) { | ||
return false; | ||
} | ||
|
||
return !context.containsProperty("micrometer.observation.server.server.enabled") || !context.getProperty("micrometer.observation.http.server.enabled", Boolean.class).orElse(false); | ||
} | ||
} |
This file contains 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,37 @@ | ||
plugins { | ||
id 'io.micronaut.build.internal.micrometer-module' | ||
} | ||
|
||
dependencies { | ||
annotationProcessor mn.micronaut.graal | ||
|
||
api projects.micronautMicrometerAnnotation | ||
api projects.micronautMicrometerObservation | ||
|
||
implementation libs.managed.micrometer.observation | ||
compileOnly mn.micronaut.http.server.netty | ||
implementation mn.reactor | ||
compileOnly(libs.managed.micrometer.tracing) | ||
|
||
testAnnotationProcessor mn.micronaut.inject.java | ||
testAnnotationProcessor projects.micronautMicrometerAnnotation | ||
testImplementation mn.micronaut.http.client | ||
testImplementation mn.micronaut.http.server.netty | ||
testImplementation mnReactor.micronaut.reactor | ||
testImplementation mnReactor.micronaut.reactor.http.client | ||
testImplementation mnRxjava2.micronaut.rxjava2 | ||
testImplementation mnRxjava2.micronaut.rxjava2.http.client | ||
testImplementation mnSerde.micronaut.serde.jackson | ||
testImplementation libs.managed.micrometer.observation.test | ||
testImplementation projects.micronautMicrometerCore | ||
testImplementation(libs.managed.micrometer.tracing) | ||
} | ||
|
||
micronautBuild { | ||
binaryCompatibility { | ||
def dash = version.indexOf('-') | ||
def v = dash > 0 ? version.substring(0, dash) : version | ||
def (major, minor, patch) = v.split('[.]').collect { it.toInteger() } | ||
enabled = major > 5 || (major == 5 && minor > 1) || (major == 5 && minor == 1 && patch > 0) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ttp/src/main/java/io/micronaut/micrometer/observation/http/AbstractObservationFilter.java
This file contains 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,55 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* 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.micronaut.micrometer.observation.http; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.annotation.Nullable; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Abstract filter used for Micrometer Observation. | ||
*/ | ||
@Internal | ||
public abstract class AbstractObservationFilter { | ||
|
||
public static final String CLIENT_PATH = "${micrometer.observation.http.client.path:/**}"; | ||
public static final String SERVER_PATH = "${micrometer.observation.http.server.path:/**}"; | ||
public static final String MICROMETER_OBSERVATION_ATTRIBUTE_KEY = "micrometer.observation"; | ||
|
||
@Nullable | ||
private final Predicate<String> pathExclusionTest; | ||
|
||
/** | ||
* Configure observation in the filter for span creation and propagation across | ||
* arbitrary transports. | ||
* | ||
* @param pathExclusionTest for excluding URI paths from observation | ||
*/ | ||
protected AbstractObservationFilter(@Nullable Predicate<String> pathExclusionTest) { | ||
this.pathExclusionTest = pathExclusionTest; | ||
} | ||
|
||
/** | ||
* Tests if the defined path should be excluded from observation. | ||
* | ||
* @param path the path | ||
* @return {@code true} if the path should be excluded | ||
*/ | ||
protected boolean shouldExclude(@Nullable String path) { | ||
return pathExclusionTest != null && path != null && pathExclusionTest.test(path); | ||
} | ||
} |
Oops, something went wrong.