Skip to content

Commit e108ca0

Browse files
committed
fix: fixed transaction name
1 parent 2e179f0 commit e108ca0

File tree

16 files changed

+592
-93
lines changed

16 files changed

+592
-93
lines changed

quarkus-resteasy-reactive-2.11/src/main/java/com/newrelic/instrumentation/quarkus/resteasy/reactive/Utils.java

Lines changed: 96 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -18,106 +18,114 @@
1818

1919
public class Utils {
2020

21-
public static final String NEWRELIC_TOKEN = "NewRelic-Token";
21+
public static final String NEWRELIC_TOKEN = "NewRelic-Token";
2222

23-
public static void addAttribute(Map<String, Object> attributes, String key, Object value) {
24-
if (attributes != null && key != null && !key.isEmpty() && value != null) {
25-
attributes.put(key, value);
26-
}
23+
public static void addAttribute(Map<String, Object> attributes, String key, Object value) {
24+
if (attributes != null && key != null && !key.isEmpty() && value != null) {
25+
attributes.put(key, value);
2726
}
27+
}
28+
29+
public static void addRuntimeResource(Map<String, Object> attributes, RuntimeResource resource) {
30+
if (resource != null) {
31+
Logger logger = NewRelic.getAgent().getLogger();
32+
addAttribute(attributes, "RuntimeResource-HttpMethod", resource.getHttpMethod());
33+
logger.log(Level.FINE, "adding RuntimeResource-HttpMethod: {0}", resource.getHttpMethod());
34+
addAttribute(attributes, "RuntimeResource-JavaMethodName", resource.getJavaMethodName());
35+
logger.log(Level.FINE, "adding RuntimeResource-JavaMethodName: {0}", resource.getJavaMethodName());
36+
URITemplate template = resource.getPath();
37+
logger.log(Level.FINE, "adding RuntimeResource-Path: {0}", resource.getPath());
38+
addAttribute(attributes, "RuntimeResource-Path", template != null ? template.toString() : "null");
39+
template = resource.getClassPath();
40+
logger.log(Level.FINE, "adding RuntimeResource-ClassPath: {0}", resource.getClassPath());
41+
addAttribute(attributes, "RuntimeResource-ClassPath", template != null ? template.toString() : "null");
2842

29-
public static void addRuntimeResource(Map<String,Object> attributes, RuntimeResource resource) {
30-
if(resource != null) {
31-
Logger logger = NewRelic.getAgent().getLogger();
32-
addAttribute(attributes, "RuntimeResource-HttpMethod", resource.getHttpMethod());
33-
logger.log(Level.FINE, "adding RuntimeResource-HttpMethod: {0}", resource.getHttpMethod());
34-
addAttribute(attributes, "RuntimeResource-JavaMethodName", resource.getJavaMethodName());
35-
logger.log(Level.FINE, "adding RuntimeResource-JavaMethodName: {0}", resource.getJavaMethodName());
36-
URITemplate template = resource.getPath();
37-
logger.log(Level.FINE, "adding RuntimeResource-Path: {0}", resource.getPath());
38-
addAttribute(attributes, "RuntimeResource-Path", template != null ? template.toString() : "null");
39-
template = resource.getClassPath();
40-
logger.log(Level.FINE, "adding RuntimeResource-ClassPath: {0}", resource.getClassPath());
41-
addAttribute(attributes, "RuntimeResource-ClassPath", template != null ? template.toString() : "null");
42-
43-
}
44-
}
45-
46-
public static void addRequestContext(Map<String, Object> attributes, ResteasyReactiveRequestContext context) {
47-
if(context != null) {
48-
addAttribute(attributes, "ResteasyReactiveRequestContext-AbsoluteURI", context.getAbsoluteURI());
49-
addAttribute(attributes, "ResteasyReactiveRequestContext-Method", context.getMethod());
50-
addAttribute(attributes, "ResteasyReactiveRequestContext-Path", context.getPath());
51-
UriInfo uriInfo = context.getUriInfo();
52-
addUriInfo(attributes, uriInfo);
53-
}
5443
}
55-
56-
public static void addUriInfo(Map<String,Object> attributes, UriInfo info) {
57-
if(info != null) {
58-
addAttribute(attributes, "UriInfo-Path", info.getPath());
59-
addAttribute(attributes, "UriInfo-BaseUri", info.getBaseUri());
60-
addAttribute(attributes, "UriInfo-MatchedURIs", info.getMatchedURIs());
61-
addAttribute(attributes, "UriInfo-PathSegments", info.getPathSegments());
62-
}
44+
}
45+
46+
public static void addRequestContext(Map<String, Object> attributes, ResteasyReactiveRequestContext context) {
47+
if (context != null) {
48+
addAttribute(attributes, "ResteasyReactiveRequestContext-AbsoluteURI", context.getAbsoluteURI());
49+
addAttribute(attributes, "ResteasyReactiveRequestContext-Method", context.getMethod());
50+
addAttribute(attributes, "ResteasyReactiveRequestContext-Path", context.getPath());
51+
UriInfo uriInfo = context.getUriInfo();
52+
addUriInfo(attributes, uriInfo);
6353
}
64-
65-
public static void addRoute(Map<String, Object> attributes, Route route) {
66-
if (route != null) {
67-
addAttribute(attributes, "Route-Name", route.getName());
68-
addAttribute(attributes, "Route-Path", route.getPath());
69-
}
54+
}
55+
56+
public static void addUriInfo(Map<String, Object> attributes, UriInfo info) {
57+
if (info != null) {
58+
addAttribute(attributes, "UriInfo-Path", info.getPath());
59+
addAttribute(attributes, "UriInfo-BaseUri", info.getBaseUri());
60+
addAttribute(attributes, "UriInfo-MatchedURIs", info.getMatchedURIs());
61+
addAttribute(attributes, "UriInfo-PathSegments", info.getPathSegments());
7062
}
63+
}
7164

72-
public static void setTransactionName(Map<String, Object> attributes, Route route) {
73-
if (route != null) {
74-
addAttribute(attributes, "Route-Name", route.getName());
75-
addAttribute(attributes, "Route-Path", route.getPath());
76-
}
65+
public static void addRoute(Map<String, Object> attributes, Route route) {
66+
if (route != null) {
67+
addAttribute(attributes, "Route-Name", route.getName());
68+
addAttribute(attributes, "Route-Path", route.getPath());
7769
}
78-
79-
public static void setTransactionName(RuntimeResource resource) {
80-
if(resource != null) {
81-
URITemplate path = resource.getPath();
82-
URITemplate classpath = resource.getClassPath();
83-
84-
StringBuffer sb = new StringBuffer();
85-
if(classpath != null) {
86-
String template = classpath.template;
87-
if(template != null && !template.isEmpty()) {
88-
sb.append(template);
89-
}
90-
}
91-
if(path != null) {
92-
String template = path.template;
93-
if(template != null && !template.isEmpty()) {
94-
sb.append(template);
95-
}
96-
}
97-
98-
if(sb.length() > 0) {
99-
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.CUSTOM_LOW, true, "Quarkus-Resteasy", sb.toString());
100-
}
101-
}
70+
}
71+
72+
public static void setTransactionName(Map<String, Object> attributes, Route route) {
73+
if (route != null) {
74+
addAttribute(attributes, "Route-Name", route.getName());
75+
addAttribute(attributes, "Route-Path", route.getPath());
10276
}
77+
}
10378

104-
public static void setTransactionName(RoutingContext request) {
105-
String name = " ";
106-
String route = request.currentRoute().getName();
107-
if (route != null & route.length() > 0) {
108-
name += route;
109-
}
110-
String path = request.currentRoute().getPath();
111-
if (path != null & path.length() > 0) {
112-
name += ":" + path;
79+
public static void setTransactionName(RuntimeResource resource) {
80+
if (resource != null) {
81+
URITemplate path = resource.getPath();
82+
URITemplate classpath = resource.getClassPath();
83+
84+
String method = resource.getHttpMethod();
85+
86+
StringBuffer sb = new StringBuffer();
87+
88+
if (method != null & method.length() > 0) {
89+
sb.append("(" + method + ") ");
90+
}
91+
92+
if (classpath != null) {
93+
String template = classpath.template;
94+
if (template != null && !template.isEmpty()) {
95+
sb.append(template);
11396
}
114-
String method = request.request().method().name();
115-
if (method != null & method.length() > 0) {
116-
name += " (" + method + ")";
97+
}
98+
if (path != null) {
99+
String template = path.template;
100+
if (template != null && !template.isEmpty()) {
101+
sb.append(template);
117102
}
118-
System.out.println(name);
119-
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
120-
"resteasy-reactive", name);
103+
}
121104

105+
if (sb.length() > 0) {
106+
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.CUSTOM_LOW, true,
107+
"Quarkus-Resteasy", sb.toString());
108+
}
122109
}
110+
}
111+
112+
public static void setTransactionName(RoutingContext request) {
113+
String name = " ";
114+
String route = request.currentRoute().getName();
115+
if (route != null & route.length() > 0) {
116+
name += route;
117+
}
118+
String path = request.currentRoute().getPath();
119+
if (path != null & path.length() > 0) {
120+
name += ":" + path;
121+
}
122+
String method = request.request().method().name();
123+
if (method != null & method.length() > 0) {
124+
name += " (" + method + ")";
125+
}
126+
// System.out.println(name);
127+
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
128+
"resteasy-reactive", name);
129+
130+
}
123131
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jboss.resteasy.reactive.server.handlers;
2+
3+
import java.util.HashMap;
4+
5+
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
6+
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
7+
import org.jboss.resteasy.reactive.server.spi.EndpointInvoker;
8+
9+
import com.newrelic.api.agent.NewRelic;
10+
import com.newrelic.api.agent.Trace;
11+
import com.newrelic.api.agent.weaver.Weave;
12+
import com.newrelic.api.agent.weaver.Weaver;
13+
import com.newrelic.instrumentation.quarkus.resteasy.reactive.Utils;
14+
15+
@Weave
16+
public class InvocationHandler {
17+
private final EndpointInvoker invoker = Weaver.callOriginal();
18+
19+
@Trace(dispatcher = true)
20+
public void handle(ResteasyReactiveRequestContext requestContext) {
21+
HashMap<String, Object> attributes = new HashMap<>();
22+
RuntimeResource target = requestContext.getTarget();
23+
24+
Utils.addRuntimeResource(attributes, target);
25+
Utils.addRequestContext(attributes, requestContext);
26+
Utils.addAttribute(attributes, "Invoker", invoker);
27+
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
28+
Utils.setTransactionName(target);
29+
30+
Weaver.callOriginal();
31+
}
32+
33+
}

quarkus-resteasy-reactive-2.6/src/main/java/com/newrelic/instrumentation/quarkus/resteasy/reactive/Utils.java

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package com.newrelic.instrumentation.quarkus.resteasy.reactive;
22

33
import java.util.Map;
4+
import java.util.logging.Level;
45

6+
import javax.ws.rs.core.UriInfo;
7+
8+
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
9+
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
10+
import org.jboss.resteasy.reactive.server.mapping.URITemplate;
11+
12+
import com.newrelic.api.agent.Logger;
513
import com.newrelic.api.agent.NewRelic;
614
import com.newrelic.api.agent.TransactionNamePriority;
715

@@ -18,6 +26,42 @@ public static void addAttribute(Map<String, Object> attributes, String key, Obje
1826
}
1927
}
2028

29+
public static void addRuntimeResource(Map<String, Object> attributes, RuntimeResource resource) {
30+
if (resource != null) {
31+
Logger logger = NewRelic.getAgent().getLogger();
32+
addAttribute(attributes, "RuntimeResource-HttpMethod", resource.getHttpMethod());
33+
logger.log(Level.FINE, "adding RuntimeResource-HttpMethod: {0}", resource.getHttpMethod());
34+
addAttribute(attributes, "RuntimeResource-JavaMethodName", resource.getJavaMethodName());
35+
logger.log(Level.FINE, "adding RuntimeResource-JavaMethodName: {0}", resource.getJavaMethodName());
36+
URITemplate template = resource.getPath();
37+
logger.log(Level.FINE, "adding RuntimeResource-Path: {0}", resource.getPath());
38+
addAttribute(attributes, "RuntimeResource-Path", template != null ? template.toString() : "null");
39+
template = resource.getClassPath();
40+
logger.log(Level.FINE, "adding RuntimeResource-ClassPath: {0}", resource.getClassPath());
41+
addAttribute(attributes, "RuntimeResource-ClassPath", template != null ? template.toString() : "null");
42+
43+
}
44+
}
45+
46+
public static void addRequestContext(Map<String, Object> attributes, ResteasyReactiveRequestContext context) {
47+
if (context != null) {
48+
addAttribute(attributes, "ResteasyReactiveRequestContext-AbsoluteURI", context.getAbsoluteURI());
49+
addAttribute(attributes, "ResteasyReactiveRequestContext-Method", context.getMethod());
50+
addAttribute(attributes, "ResteasyReactiveRequestContext-Path", context.getPath());
51+
UriInfo uriInfo = context.getUriInfo();
52+
addUriInfo(attributes, uriInfo);
53+
}
54+
}
55+
56+
public static void addUriInfo(Map<String, Object> attributes, UriInfo info) {
57+
if (info != null) {
58+
addAttribute(attributes, "UriInfo-Path", info.getPath());
59+
addAttribute(attributes, "UriInfo-BaseUri", info.getBaseUri());
60+
addAttribute(attributes, "UriInfo-MatchedURIs", info.getMatchedURIs());
61+
addAttribute(attributes, "UriInfo-PathSegments", info.getPathSegments());
62+
}
63+
}
64+
2165
public static void addRoute(Map<String, Object> attributes, Route route) {
2266
if (route != null) {
2367
addAttribute(attributes, "Route-Name", route.getName());
@@ -32,6 +76,39 @@ public static void setTransactionName(Map<String, Object> attributes, Route rout
3276
}
3377
}
3478

79+
public static void setTransactionName(RuntimeResource resource) {
80+
if (resource != null) {
81+
URITemplate path = resource.getPath();
82+
URITemplate classpath = resource.getClassPath();
83+
84+
String method = resource.getHttpMethod();
85+
86+
StringBuffer sb = new StringBuffer();
87+
88+
if (method != null & method.length() > 0) {
89+
sb.append("(" + method + ") ");
90+
}
91+
92+
if (classpath != null) {
93+
String template = classpath.template;
94+
if (template != null && !template.isEmpty()) {
95+
sb.append(template);
96+
}
97+
}
98+
if (path != null) {
99+
String template = path.template;
100+
if (template != null && !template.isEmpty()) {
101+
sb.append(template);
102+
}
103+
}
104+
105+
if (sb.length() > 0) {
106+
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.CUSTOM_LOW, true,
107+
"Quarkus-Resteasy", sb.toString());
108+
}
109+
}
110+
}
111+
35112
public static void setTransactionName(RoutingContext request) {
36113
String name = " ";
37114
String route = request.currentRoute().getName();
@@ -46,7 +123,7 @@ public static void setTransactionName(RoutingContext request) {
46123
if (method != null & method.length() > 0) {
47124
name += " (" + method + ")";
48125
}
49-
System.out.println(name);
126+
// System.out.println(name);
50127
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
51128
"resteasy-reactive", name);
52129

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jboss.resteasy.reactive.server.handlers;
2+
3+
import java.util.HashMap;
4+
5+
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
6+
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
7+
import org.jboss.resteasy.reactive.server.spi.EndpointInvoker;
8+
9+
import com.newrelic.api.agent.NewRelic;
10+
import com.newrelic.api.agent.Trace;
11+
import com.newrelic.api.agent.weaver.Weave;
12+
import com.newrelic.api.agent.weaver.Weaver;
13+
import com.newrelic.instrumentation.quarkus.resteasy.reactive.Utils;
14+
15+
@Weave
16+
public class InvocationHandler {
17+
private final EndpointInvoker invoker = Weaver.callOriginal();
18+
19+
@Trace(dispatcher = true)
20+
public void handle(ResteasyReactiveRequestContext requestContext) {
21+
HashMap<String, Object> attributes = new HashMap<>();
22+
RuntimeResource target = requestContext.getTarget();
23+
24+
Utils.addRuntimeResource(attributes, target);
25+
Utils.addRequestContext(attributes, requestContext);
26+
Utils.addAttribute(attributes, "Invoker", invoker);
27+
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
28+
Utils.setTransactionName(target);
29+
30+
Weaver.callOriginal();
31+
}
32+
33+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.jboss.resteasy.reactive.server.spi;
2+
3+
import com.newrelic.api.agent.NewRelic;
4+
import com.newrelic.api.agent.Trace;
5+
import com.newrelic.api.agent.weaver.MatchType;
6+
import com.newrelic.api.agent.weaver.Weave;
7+
import com.newrelic.api.agent.weaver.Weaver;
8+
9+
@Weave(type = MatchType.Interface)
10+
public abstract class EndpointInvoker {
11+
12+
@Trace(dispatcher = true)
13+
public Object invoke(Object instance, Object[] parameters) {
14+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Resteasy","Reactive","EndpointInvoker",getClass().getName(),"invoke");
15+
return Weaver.callOriginal();
16+
}
17+
}

0 commit comments

Comments
 (0)