Skip to content

Commit d4a862c

Browse files
authored
Merge pull request #4 from newrelic-experimental/updates_12-24
Updates 12 24
2 parents ae002b7 + 2f1b3e3 commit d4a862c

File tree

24 files changed

+539
-243
lines changed

24 files changed

+539
-243
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
rootProject.name = 'java-instrumentation-template'
2-
include 'spring-cloud-gateway'
2+
include 'spring-cloud-gateway-reactive'
3+
include 'spring-cloud-gateway-mvc-4.1'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// Build.gradle generated for instrumentation module spring-cloud-gateway-mvc
3+
4+
apply plugin: 'java'
5+
6+
sourceCompatibility = JavaVersion.VERSION_17
7+
targetCompatibility = JavaVersion.VERSION_17
8+
9+
dependencies {
10+
implementation 'org.springframework.cloud:spring-cloud-gateway-server-mvc:4.1.0'
11+
implementation 'org.springframework:spring-webmvc:5.3.16'
12+
13+
implementation fileTree(include: ['*.jar'], dir: '../libs')
14+
}
15+
16+
jar {
17+
manifest {
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-cloud-gateway-mvc-4.1'
19+
attributes 'Implementation-Vendor': 'New Relic'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic'
21+
attributes 'Implementation-Version': 1.0
22+
}
23+
}
24+
25+
verifyInstrumentation {
26+
passes 'org.springframework.cloud:spring-cloud-gateway-server-mvc:[4.1.0,)'
27+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.springframework.cloud.gateway.server.mvc.handler;
2+
3+
import java.net.URI;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
import org.springframework.web.servlet.function.ServerRequest;
8+
import org.springframework.web.servlet.function.ServerResponse;
9+
10+
import com.newrelic.api.agent.NewRelic;
11+
import com.newrelic.api.agent.Trace;
12+
import com.newrelic.api.agent.TransactionNamePriority;
13+
import com.newrelic.api.agent.weaver.Weave;
14+
import com.newrelic.api.agent.weaver.Weaver;
15+
16+
@Weave
17+
public abstract class HandlerFunctions {
18+
19+
@Weave
20+
static class LookupProxyExchangeHandlerFunction {
21+
22+
private final URI uri = Weaver.callOriginal();
23+
24+
@Trace
25+
public ServerResponse handle(ServerRequest serverRequest) {
26+
if(uri != null) {
27+
String path = uri.getPath();
28+
StringBuffer sb = new StringBuffer(path);
29+
30+
Map<String, String> pathVars = serverRequest.pathVariables();
31+
if(pathVars != null && !pathVars.isEmpty()) {
32+
sb.append('?');
33+
Set<String> keys = pathVars.keySet();
34+
for(String key : keys) {
35+
sb.append(key);
36+
sb.append("=?");
37+
}
38+
}
39+
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, false, "SoringGateway", "handle", sb.toString(),serverRequest.methodName());
40+
}
41+
42+
return Weaver.callOriginal();
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.springframework.cloud.gateway.server.mvc.handler;
2+
3+
import java.net.URI;
4+
5+
import org.springframework.web.servlet.function.ServerRequest;
6+
import org.springframework.web.servlet.function.ServerResponse;
7+
8+
import com.newrelic.api.agent.NewRelic;
9+
import com.newrelic.api.agent.Trace;
10+
import com.newrelic.api.agent.TracedMethod;
11+
import com.newrelic.api.agent.weaver.Weave;
12+
import com.newrelic.api.agent.weaver.Weaver;
13+
14+
@Weave
15+
public class ProxyExchangeHandlerFunction {
16+
17+
@Trace
18+
public ServerResponse handle(ServerRequest serverRequest) {
19+
URI uri = serverRequest.uri();
20+
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
21+
traced.addCustomAttribute("RequestURI", uri.toASCIIString());
22+
traced.addCustomAttribute("Method", serverRequest.methodName());
23+
return Weaver.callOriginal();
24+
}
25+
}

spring-cloud-gateway/build.gradle renamed to spring-cloud-gateway-reactive/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ dependencies {
1818

1919
jar {
2020
manifest {
21-
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-cloud-gateway-core'
21+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-cloud-gateway-reactive'
2222
attributes 'Implementation-Vendor': 'New Relic Labs'
2323
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
2424
attributes 'Implementation-Version': 1.1
2525
}
2626
}
2727

2828
verifyInstrumentation {
29-
passes("org.springframework.cloud:spring-cloud-gateway-core:[2.2.6.RELEASE,)") {
30-
compile 'org.springframework:spring-web:5.3.2'
31-
compile 'org.springframework:spring-web:5.3.2'
32-
33-
}
29+
// passes("org.springframework.cloud:spring-cloud-gateway-core:[2.2.6.RELEASE,)") {
30+
// compile 'org.springframework:spring-web:5.3.2'
3431

32+
// }
33+
passes("org.springframework.cloud:spring-cloud-gateway-server:[2.2.6.RELEASE,)") {
34+
compile 'org.springframework:spring-web:5.3.2'
35+
}
3536
}
3637

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.newrelic.instrumentation.labs.spring.cloud.gw;
2+
3+
import java.util.function.Consumer;
4+
5+
public class NRCompletionConsumer implements Consumer<Void> {
6+
7+
private NRHolder holder = null;
8+
9+
public NRCompletionConsumer(NRHolder h) {
10+
holder = h;
11+
}
12+
13+
14+
@Override
15+
public void accept(Void t) {
16+
if(holder != null) {
17+
holder.end();
18+
}
19+
}
20+
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.newrelic.instrumentation.labs.spring.cloud.gw;
2+
3+
import java.util.function.Consumer;
4+
5+
import com.newrelic.api.agent.NewRelic;
6+
7+
public class NRErrorConsumer implements Consumer<Throwable> {
8+
9+
private NRHolder holder = null;
10+
11+
public NRErrorConsumer(NRHolder h) {
12+
holder = h;
13+
}
14+
15+
16+
@Override
17+
public void accept(Throwable t) {
18+
if(t != null) {
19+
NewRelic.noticeError(t);
20+
}
21+
if(holder != null) {
22+
holder.ignore();
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)