Skip to content

Commit ae1cdcd

Browse files
authored
Merge pull request #2280 from gsidhwani-nr/micronaut-core
Micronaut http instrumentation modules
2 parents 6568ac8 + 39ab39f commit ae1cdcd

File tree

133 files changed

+5301
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+5301
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
dependencies {
2+
implementation(project(":agent-bridge"))
3+
implementation("io.micronaut:micronaut-core:2.4.0")
4+
}
5+
6+
jar {
7+
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.micronaut-core-1.0.0',
8+
'Implementation-Title-Alias': 'micronaut-core' }
9+
}
10+
11+
verifyInstrumentation {
12+
passesOnly('io.micronaut:micronaut-core:[1.0.0,4.0.0)')
13+
excludeRegex 'io.micronaut:micronaut-core:.*(RC|M)[0-9]*$'
14+
}
15+
16+
site {
17+
title 'Micronaut'
18+
type 'Framework'
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.bind;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Trace;
12+
import com.newrelic.api.agent.TracedMethod;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.Weave;
15+
import com.newrelic.api.agent.weaver.Weaver;
16+
17+
@Weave(originalName = "io.micronaut.core.bind.BoundExecutable", type = MatchType.Interface)
18+
public abstract class BoundExecutable_Instrumentation<T, R> {
19+
20+
@Trace
21+
public R invoke(T instance) {
22+
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
23+
traced.setMetricName("Micronaut", "BoundExecutable", getClass().getSimpleName(), "invoke");
24+
traced.addCustomAttribute("Instance", instance.getClass().getName());
25+
return Weaver.callOriginal();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.type;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Trace;
12+
import com.newrelic.api.agent.TracedMethod;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.Weave;
15+
import com.newrelic.api.agent.weaver.Weaver;
16+
17+
@Weave(originalName = "io.micronaut.core.type.Executable", type = MatchType.Interface)
18+
public abstract class Executable_Instrumentation<T, R> {
19+
20+
@Trace
21+
public R invoke(T instance, Object... arguments) {
22+
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
23+
traced.setMetricName("Micronaut", "Executable", getClass().getSimpleName(), "invoke");
24+
traced.addCustomAttribute("Instance", instance.getClass().getName());
25+
return Weaver.callOriginal();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.type;
9+
10+
import com.newrelic.api.agent.weaver.SkipIfPresent;
11+
12+
@SkipIfPresent(originalName = "io.micronaut.core.type.UnsafeExecutable")
13+
public class UnsafeExecutable_Skip {
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
dependencies {
2+
implementation(project(":agent-bridge"))
3+
implementation("io.micronaut:micronaut-core:4.0.0")
4+
}
5+
6+
jar {
7+
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.micronaut-core-4.0.0',
8+
'Implementation-Title-Alias': 'micronaut-core' }
9+
}
10+
11+
verifyInstrumentation {
12+
passesOnly('io.micronaut:micronaut-core:[4.0.0,4.3.0)')
13+
excludeRegex 'io.micronaut:micronaut-core:.*(RC|M)[0-9]*$'
14+
}
15+
16+
java {
17+
toolchain {
18+
languageVersion.set(JavaLanguageVersion.of(17))
19+
}
20+
}
21+
22+
test {
23+
// These instrumentation tests only run on Java 17+ regardless of the -PtestN gradle property that is set.
24+
onlyIf {
25+
!project.hasProperty('test8') && !project.hasProperty('test11')
26+
}
27+
}
28+
29+
site {
30+
title 'Micronaut'
31+
type 'Framework'
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package com.nr.agent.instrumentation.micronaut;
9+
10+
import java.util.function.BiConsumer;
11+
12+
import com.newrelic.api.agent.NewRelic;
13+
14+
public class NRBiConsumerWrapper<R> implements BiConsumer<R, Throwable> {
15+
BiConsumer<R, Throwable> delegate = null;
16+
17+
public NRBiConsumerWrapper(BiConsumer<R, Throwable> d) {
18+
delegate = d;
19+
}
20+
21+
@Override
22+
public void accept(R r, Throwable throwable) {
23+
if(throwable != null) {
24+
NewRelic.noticeError(throwable);
25+
}
26+
if(delegate != null) {
27+
delegate.accept(r, throwable);
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.beans;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.weaver.MatchType;
12+
import com.newrelic.api.agent.weaver.Weave;
13+
import com.newrelic.api.agent.weaver.Weaver;
14+
15+
@Weave(originalName = "io.micronaut.core.beans.AbstractBeanMethod", type = MatchType.BaseClass)
16+
public abstract class AbstractBeanMethod_Instrumentation<B, T> {
17+
18+
public abstract String getName();
19+
20+
protected T invokeInternal(B instance, Object... arguments) {
21+
NewRelic.getAgent().getTracedMethod().setMetricName("Micronaut", "AbstractBeanMethod", getClass().getSimpleName(), "invoke");
22+
NewRelic.getAgent().getTracedMethod().addCustomAttribute("Instance", instance.getClass().getName());
23+
NewRelic.getAgent().getTracedMethod().addCustomAttribute("Name", getName());
24+
return Weaver.callOriginal();
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.micronaut.core.bind;
2+
3+
import com.newrelic.api.agent.NewRelic;
4+
import com.newrelic.api.agent.Trace;
5+
import com.newrelic.api.agent.TracedMethod;
6+
import com.newrelic.api.agent.weaver.MatchType;
7+
import com.newrelic.api.agent.weaver.Weave;
8+
import com.newrelic.api.agent.weaver.Weaver;
9+
10+
@Weave(originalName = "io.micronaut.core.bind.BoundExecutable", type = MatchType.Interface)
11+
public abstract class BoundExecutable_Instrumentation<T, R> {
12+
13+
@Trace
14+
public R invoke(T instance) {
15+
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
16+
traced.setMetricName("Micronaut", "BoundExecutable", getClass().getSimpleName(), "invoke");
17+
traced.addCustomAttribute("Instance", instance.getClass().getName());
18+
return Weaver.callOriginal();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.execution;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Token;
12+
import com.newrelic.api.agent.Trace;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.NewField;
15+
import com.newrelic.api.agent.weaver.Weave;
16+
import com.newrelic.api.agent.weaver.Weaver;
17+
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;
18+
19+
import java.util.concurrent.CompletableFuture;
20+
import java.util.function.BiConsumer;
21+
22+
@Weave(originalName = "io.micronaut.core.execution.CompletableFutureExecutionFlowImpl", type = MatchType.ExactClass)
23+
class CompletableFutureExecutionFlowImpl_Instrumentation {
24+
@NewField
25+
protected Token token = null;
26+
27+
CompletableFutureExecutionFlowImpl_Instrumentation(CompletableFuture<Object> stage) {
28+
Token t = NewRelic.getAgent().getTransaction().getToken();
29+
if (t != null) {
30+
token = t;
31+
}
32+
}
33+
34+
@SuppressWarnings({ "unchecked", "rawtypes" })
35+
@Trace(async = true)
36+
public void onComplete(BiConsumer<? super Object, Throwable> throwable) {
37+
if (token != null) {
38+
token.linkAndExpire();
39+
token = null;
40+
throwable = new NRBiConsumerWrapper(throwable);
41+
}
42+
43+
Weaver.callOriginal();
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.execution;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Token;
12+
import com.newrelic.api.agent.Trace;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.NewField;
15+
import com.newrelic.api.agent.weaver.Weave;
16+
import com.newrelic.api.agent.weaver.Weaver;
17+
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;
18+
19+
import java.util.function.BiConsumer;
20+
21+
@Weave(originalName = "io.micronaut.core.execution.DelayedExecutionFlowImpl", type = MatchType.ExactClass)
22+
class DelayedExecutionFlowImpl_Instrumentation<T> {
23+
24+
@NewField
25+
protected Token token = null;
26+
27+
DelayedExecutionFlowImpl_Instrumentation() {
28+
Token t = NewRelic.getAgent().getTransaction().getToken();
29+
if (t != null) {
30+
token = t;
31+
}
32+
}
33+
34+
@SuppressWarnings({ "unchecked", "rawtypes" })
35+
@Trace(async = true)
36+
public void onComplete(BiConsumer<? super Object, Throwable> fn) {
37+
if (token != null) {
38+
token.linkAndExpire();
39+
token = null;
40+
fn = new NRBiConsumerWrapper(fn);
41+
}
42+
43+
Weaver.callOriginal();
44+
}
45+
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.execution;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Token;
12+
import com.newrelic.api.agent.Trace;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.NewField;
15+
import com.newrelic.api.agent.weaver.Weave;
16+
import com.newrelic.api.agent.weaver.Weaver;
17+
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;
18+
19+
import java.util.function.BiConsumer;
20+
21+
@Weave(originalName = "io.micronaut.core.execution.ImperativeExecutionFlowImpl", type = MatchType.ExactClass)
22+
class ImperativeExecutionFlowImpl_Instrumentation {
23+
24+
@NewField
25+
protected Token token = null;
26+
27+
<T> ImperativeExecutionFlowImpl_Instrumentation(T value, Throwable error) {
28+
Token t = NewRelic.getAgent().getTransaction().getToken();
29+
if (t != null) {
30+
token = t;
31+
}
32+
}
33+
34+
@SuppressWarnings({ "unchecked", "rawtypes" })
35+
@Trace(async = true)
36+
public void onComplete(BiConsumer<? super Object, Throwable> fn) {
37+
if (token != null) {
38+
token.linkAndExpire();
39+
token = null;
40+
fn = new NRBiConsumerWrapper(fn);
41+
}
42+
43+
Weaver.callOriginal();
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* * Copyright 2025 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
package io.micronaut.core.type;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Trace;
12+
import com.newrelic.api.agent.TracedMethod;
13+
import com.newrelic.api.agent.weaver.MatchType;
14+
import com.newrelic.api.agent.weaver.Weave;
15+
import com.newrelic.api.agent.weaver.Weaver;
16+
17+
@Weave(originalName = "io.micronaut.core.type.Executable", type = MatchType.Interface)
18+
public abstract class Executable_Instrumentation<T, R> {
19+
20+
@Trace
21+
public R invoke(T instance, Object... arguments) {
22+
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
23+
traced.setMetricName("Micronaut", "Executable", getClass().getSimpleName(), "invoke");
24+
traced.addCustomAttribute("Instance", instance.getClass().getName());
25+
return Weaver.callOriginal();
26+
}
27+
}

0 commit comments

Comments
 (0)