Skip to content
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

Micronaut core instrumentatin modules #2219

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions instrumentation/micronaut-core-1.0.0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
dependencies {
implementation(project(":agent-bridge"))
implementation("io.micronaut:micronaut-core:2.4.0")
}

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.micronaut-core-1.0.0',
'Implementation-Title-Alias': 'micronaut-core' }
}

verifyInstrumentation {
passesOnly('io.micronaut:micronaut-core:[1.0.0,4.0.0)')
excludeRegex 'io.micronaut:micronaut-core:.*(RC|M)[0-9]*$'
}

site {
title 'Micronaut'
type 'Framework'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.bind;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.micronaut.core.bind.BoundExecutable", type = MatchType.Interface)
public abstract class BoundExecutable_Instrumentation<T, R> {

@Trace
public R invoke(T instance) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Micronaut", "BoundExecutable", getClass().getSimpleName(), "invoke");
traced.addCustomAttribute("Instance", instance.getClass().getName());
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.type;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.micronaut.core.type.Executable", type = MatchType.Interface)
public abstract class Executable_Instrumentation<T, R> {

@Trace
public R invoke(T instance, Object... arguments) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Micronaut", "Executable", getClass().getSimpleName(), "invoke");
traced.addCustomAttribute("Instance", instance.getClass().getName());
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.type;

import com.newrelic.api.agent.weaver.SkipIfPresent;

@SkipIfPresent(originalName = "io.micronaut.core.type.UnsafeExecutable")
public class UnsafeExecutable_Skip {
}
32 changes: 32 additions & 0 deletions instrumentation/micronaut-core-4.0.0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
dependencies {
implementation(project(":agent-bridge"))
implementation("io.micronaut:micronaut-core:4.0.0")
}

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.micronaut-core-4.0.0',
'Implementation-Title-Alias': 'micronaut-core' }
}

verifyInstrumentation {
passesOnly('io.micronaut:micronaut-core:[4.0.0,4.3.0)')
excludeRegex 'io.micronaut:micronaut-core:.*(RC|M)[0-9]*$'
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

test {
// These instrumentation tests only run on Java 17+ regardless of the -PtestN gradle property that is set.
onlyIf {
!project.hasProperty('test8') && !project.hasProperty('test11')
}
}

site {
title 'Micronaut'
type 'Framework'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package com.nr.agent.instrumentation.micronaut;

import java.util.function.BiConsumer;

import com.newrelic.api.agent.NewRelic;

public class NRBiConsumerWrapper<R> implements BiConsumer<R, Throwable> {
BiConsumer<R, Throwable> delegate = null;

public NRBiConsumerWrapper(BiConsumer<R, Throwable> d) {
delegate = d;
}

@Override
public void accept(R r, Throwable throwable) {
if(throwable != null) {
NewRelic.noticeError(throwable);
}
if(delegate != null) {
delegate.accept(r, throwable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.beans;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.micronaut.core.beans.AbstractBeanMethod", type = MatchType.BaseClass)
public abstract class AbstractBeanMethod_Instrumentation<B, T> {

public abstract String getName();

protected T invokeInternal(B instance, Object... arguments) {
NewRelic.getAgent().getTracedMethod().setMetricName("Micronaut", "AbstractBeanMethod", getClass().getSimpleName(), "invoke");
NewRelic.getAgent().getTracedMethod().addCustomAttribute("Instance", instance.getClass().getName());
NewRelic.getAgent().getTracedMethod().addCustomAttribute("Name", getName());
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.micronaut.core.bind;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.micronaut.core.bind.BoundExecutable", type = MatchType.Interface)
public abstract class BoundExecutable_Instrumentation<T, R> {

@Trace
public R invoke(T instance) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Micronaut", "BoundExecutable", getClass().getSimpleName(), "invoke");
traced.addCustomAttribute("Instance", instance.getClass().getName());
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.execution;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

@Weave(originalName = "io.micronaut.core.execution.CompletableFutureExecutionFlowImpl", type = MatchType.ExactClass)
class CompletableFutureExecutionFlowImpl_Instrumentation {
@NewField
protected Token token = null;

CompletableFutureExecutionFlowImpl_Instrumentation(CompletableFuture<Object> stage) {
Token t = NewRelic.getAgent().getTransaction().getToken();
if (t != null) {
token = t;
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Trace(async = true)
public void onComplete(BiConsumer<? super Object, Throwable> throwable) {
if (token != null) {
token.linkAndExpire();
token = null;
throwable = new NRBiConsumerWrapper(throwable);
}

Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.execution;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;

import java.util.function.BiConsumer;

@Weave(originalName = "io.micronaut.core.execution.DelayedExecutionFlowImpl", type = MatchType.ExactClass)
class DelayedExecutionFlowImpl_Instrumentation<T> {

@NewField
protected Token token = null;

DelayedExecutionFlowImpl_Instrumentation() {
Token t = NewRelic.getAgent().getTransaction().getToken();
if (t != null) {
token = t;
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Trace(async = true)
public void onComplete(BiConsumer<? super Object, Throwable> fn) {
if (token != null) {
token.linkAndExpire();
token = null;
fn = new NRBiConsumerWrapper(fn);
}

Weaver.callOriginal();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.execution;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.agent.instrumentation.micronaut.NRBiConsumerWrapper;

import java.util.function.BiConsumer;

@Weave(originalName = "io.micronaut.core.execution.ImperativeExecutionFlowImpl", type = MatchType.ExactClass)
class ImperativeExecutionFlowImpl_Instrumentation {

@NewField
protected Token token = null;

<T> ImperativeExecutionFlowImpl_Instrumentation(T value, Throwable error) {
Token t = NewRelic.getAgent().getTransaction().getToken();
if (t != null) {
token = t;
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Trace(async = true)
public void onComplete(BiConsumer<? super Object, Throwable> fn) {
if (token != null) {
token.linkAndExpire();
token = null;
fn = new NRBiConsumerWrapper(fn);
}

Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* * Copyright 2025 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package io.micronaut.core.type;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.micronaut.core.type.Executable", type = MatchType.Interface)
public abstract class Executable_Instrumentation<T, R> {

@Trace
public R invoke(T instance, Object... arguments) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Micronaut", "Executable", getClass().getSimpleName(), "invoke");
traced.addCustomAttribute("Instance", instance.getClass().getName());
return Weaver.callOriginal();
}
}
Loading
Loading