generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from newrelic/version4Updates
Version4 updates
- Loading branch information
Showing
43 changed files
with
1,188 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,29 @@ | ||
|
||
// Build.gradle generated for instrumentation module micronaut-http-netty | ||
|
||
apply plugin: 'java' | ||
|
||
targetCompatibility=JavaVersion.VERSION_17 | ||
|
||
dependencies { | ||
implementation 'io.micronaut:micronaut-http-netty:4.1.0' | ||
|
||
// New Relic Java Agent dependencies | ||
implementation 'com.newrelic.agent.java:newrelic-agent:7.4.0' | ||
implementation 'com.newrelic.agent.java:newrelic-api:7.4.0' | ||
implementation fileTree(include: ['*.jar'], dir: '../libs') | ||
implementation fileTree(include: ['*.jar'], dir: '../test-lib') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.micronaut-http-netty' | ||
attributes 'Implementation-Vendor': 'New Relic Labs' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'io.micronaut:micronaut-http-netty:[4.1.0,)' | ||
} |
7 changes: 7 additions & 0 deletions
7
...onaut-http-netty-4.1/src/main/java/io/micronaut/http/netty/reactive/HandlerPublisher.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,7 @@ | ||
package io.micronaut.http.netty.reactive; | ||
|
||
import com.newrelic.api.agent.weaver.SkipIfPresent; | ||
|
||
@SkipIfPresent | ||
public abstract class HandlerPublisher<T> { | ||
} |
25 changes: 25 additions & 0 deletions
25
...naut-http-netty-4.1/src/main/java/io/micronaut/http/netty/reactive/HandlerSubscriber.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,25 @@ | ||
package io.micronaut.http.netty.reactive; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave | ||
public abstract class HandlerSubscriber<T> { | ||
|
||
@Trace(dispatcher = true) | ||
public void onComplete() { | ||
Weaver.callOriginal(); | ||
} | ||
|
||
public void onError(final Throwable error) { | ||
NewRelic.noticeError(error); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(dispatcher = true) | ||
public void onNext(T t) { | ||
Weaver.callOriginal(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ty-4.1/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.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,35 @@ | ||
package io.micronaut.http.netty.websocket; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import io.micronaut.core.bind.BoundExecutable; | ||
import io.micronaut.inject.MethodExecutionHandle; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.http.websocketx.WebSocketFrame; | ||
|
||
@Weave(type = MatchType.BaseClass) | ||
public abstract class AbstractNettyWebSocketHandler { | ||
|
||
@Trace(dispatcher = true) | ||
protected void channelRead0(ChannelHandlerContext ctx, Object msg) { | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","NettyWebSocketHandler",getClass().getSimpleName(),"channelRead0"); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(dispatcher = true) | ||
protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame msg) { | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","NettyWebSocketHandler",getClass().getSimpleName(),"handleWebSocketFrame"); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Trace(dispatcher = true) | ||
protected Object invokeExecutable(BoundExecutable boundExecutable, MethodExecutionHandle<?, ?> messageHandler) { | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","NettyWebSocketHandler",getClass().getSimpleName(),"invokeExecutable"); | ||
return Weaver.callOriginal(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nstrumentation/micronaut/netty/Utils.java → ...trumentation/micronaut/netty_2/Utils.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
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
2 changes: 1 addition & 1 deletion
2
...nstrumentation/micronaut/netty/Utils.java → ...trumentation/micronaut/netty_3/Utils.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
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,32 @@ | ||
|
||
// Build.gradle generated for instrumentation module micronaut-http-netty-2 | ||
|
||
apply plugin: 'java' | ||
|
||
targetCompatibility=JavaVersion.VERSION_17 | ||
|
||
dependencies { | ||
implementation 'io.micronaut:micronaut-http-server-netty:4.3.0' | ||
implementation group: 'io.projectreactor', name: 'reactor-core', version: '3.5.11' | ||
|
||
// New Relic Java Agent dependencies | ||
implementation 'com.newrelic.agent.java:newrelic-agent:7.4.0' | ||
implementation 'com.newrelic.agent.java:newrelic-api:7.4.0' | ||
implementation fileTree(include: ['*.jar'], dir: '../libs') | ||
implementation fileTree(include: ['*.jar'], dir: '../test-lib') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.micronaut-http-server-netty-4' | ||
attributes 'Implementation-Vendor': 'New Relic Labs' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'io.micronaut:micronaut-http-server-netty:[4.3.0,)' | ||
excludeRegex '.*RC.' | ||
excludeRegex '.*M.' | ||
} |
40 changes: 40 additions & 0 deletions
40
....3/src/main/java/com/newrelic/instrumentation/micronaut/netty_43/NRBiConsumerWrapper.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,40 @@ | ||
package com.newrelic.instrumentation.micronaut.netty_43; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
public class NRBiConsumerWrapper<R> implements BiConsumer<R, Throwable> { | ||
|
||
BiConsumer<R, Throwable> delegate = null; | ||
private Token token = null; | ||
private static boolean isTransformed = false; | ||
|
||
public NRBiConsumerWrapper(BiConsumer<R, Throwable> d, Token t) { | ||
delegate = d; | ||
token = t; | ||
if(!isTransformed) { | ||
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); | ||
isTransformed = true; | ||
} | ||
} | ||
|
||
@Override | ||
@Trace(async = true) | ||
public void accept(R t, Throwable u) { | ||
if(token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
if(u != null) { | ||
NewRelic.noticeError(u); | ||
} | ||
if(delegate != null) { | ||
delegate.accept(t, u); | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...server-netty-4.3/src/main/java/com/newrelic/instrumentation/micronaut/netty_43/Utils.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,46 @@ | ||
package com.newrelic.instrumentation.micronaut.netty_43; | ||
|
||
import java.util.Map; | ||
|
||
import io.micronaut.web.router.RouteMatch; | ||
|
||
public class Utils { | ||
|
||
public static void decorateWithRoute(RouteMatch<?> routeMatch) { | ||
// TracedMethod traced = NewRelic.getAgent().getTracedMethod(); | ||
// if(routeMatch instanceof BasicObjectRouteMatch) { | ||
// BasicObjectRouteMatch objMatch = (BasicObjectRouteMatch)routeMatch; | ||
// Class<?> declaringClass = objMatch.getDeclaringType(); | ||
// traced.setMetricName("Custom","Micronaut","Netty","Route","Object", declaringClass.getSimpleName()); | ||
// traced.addCustomAttribute("Declaring-Class", declaringClass.getName()); | ||
// } else if(routeMatch instanceof UriRouteMatch) { | ||
// UriRouteMatch<?,?> uriRouteMatch = (UriRouteMatch<?, ?>)routeMatch; | ||
// | ||
// | ||
// | ||
// String uri = uriRouteMatch.getUri(); | ||
// UriMatchTemplate matchTemplate = uriRouteMatch.getRoute().getUriMatchTemplate(); | ||
// String pathString = matchTemplate != null ? matchTemplate.toPathString() : null; | ||
// | ||
// String uriTemplate = uriRouteMatch.toString(); | ||
// String methodName = uriRouteMatch.getMethodName(); | ||
// String name = uriRouteMatch.getName(); | ||
// | ||
// HashMap<String, Object> attributes = new HashMap<String, Object>(); | ||
// addAttribute(attributes, "PathString", pathString); | ||
// addAttribute(attributes, "Method-Name", methodName); | ||
// addAttribute(attributes, "URI", uri); | ||
// addAttribute(attributes, "URITemplate", uriTemplate); | ||
// addAttribute(attributes, "Name", name); | ||
// traced.addCustomAttributes(attributes); | ||
// | ||
// traced.setMetricName("Custom","Micronaut","Netty","Route","URI"); | ||
// } | ||
} | ||
|
||
public static void addAttribute(Map<String, Object> attributes, String key, Object value) { | ||
if(attributes != null && key != null && !key.isEmpty() && value != null) { | ||
attributes.put(key, value); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...etty-4.3/src/main/java/io/micronaut/http/reactive/execution/ReactorExecutionFlowImpl.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,39 @@ | ||
package io.micronaut.http.reactive.execution; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
import org.reactivestreams.Publisher; | ||
|
||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.newrelic.instrumentation.micronaut.netty_43.NRBiConsumerWrapper; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
@Weave | ||
abstract class ReactorExecutionFlowImpl { | ||
|
||
@NewField | ||
protected Token token = null; | ||
|
||
<K> ReactorExecutionFlowImpl(Publisher<K> value) { | ||
} | ||
|
||
<K> ReactorExecutionFlowImpl(Mono<K> value) { | ||
} | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
@Trace(async = true) | ||
public void onComplete(BiConsumer<? super Object, Throwable> fn) { | ||
if(token != null) { | ||
token.link(); | ||
NRBiConsumerWrapper wrapper = new NRBiConsumerWrapper(fn, token); | ||
token = null; | ||
fn = wrapper; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...-netty-4.3/src/main/java/io/micronaut/http/server/netty/AbstractHttpContentProcessor.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,16 @@ | ||
package io.micronaut.http.server.netty; | ||
|
||
import java.util.Collection; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
import io.netty.buffer.ByteBufHolder; | ||
|
||
@Weave(type=MatchType.BaseClass) | ||
public abstract class AbstractHttpContentProcessor<T> { | ||
|
||
@Trace(dispatcher = true) | ||
protected abstract void onData(ByteBufHolder message, Collection<Object> out); | ||
} |
18 changes: 18 additions & 0 deletions
18
...-server-netty-4.3/src/main/java/io/micronaut/http/server/netty/RoutingInBoundHandler.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,18 @@ | ||
package io.micronaut.http.server.netty; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import io.micronaut.http.server.netty.body.ByteBody; | ||
import io.micronaut.http.server.netty.handler.PipeliningServerHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
@Weave | ||
public abstract class RoutingInBoundHandler { | ||
|
||
@Trace(dispatcher = true) | ||
public void accept(ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest request, ByteBody body, PipeliningServerHandler.OutboundAccess outboundAccess) { | ||
Weaver.callOriginal(); | ||
} | ||
} |
Oops, something went wrong.