|
1 | 1 | package com.newrelic.instrumentation.quarkus.resteasy.reactive; |
2 | 2 |
|
3 | 3 | import java.util.Map; |
| 4 | +import java.util.logging.Level; |
4 | 5 |
|
| 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; |
5 | 13 | import com.newrelic.api.agent.NewRelic; |
6 | 14 | import com.newrelic.api.agent.TransactionNamePriority; |
7 | 15 |
|
|
10 | 18 |
|
11 | 19 | public class Utils { |
12 | 20 |
|
13 | | - public static final String NEWRELIC_TOKEN = "NewRelic-Token"; |
| 21 | + public static final String NEWRELIC_TOKEN = "NewRelic-Token"; |
14 | 22 |
|
15 | | - public static void addAttribute(Map<String, Object> attributes, String key, Object value) { |
16 | | - if (attributes != null && key != null && !key.isEmpty() && value != null) { |
17 | | - attributes.put(key, value); |
| 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 | + } |
18 | 27 | } |
19 | | - } |
20 | 28 |
|
21 | | - public static void addRoute(Map<String, Object> attributes, Route route) { |
22 | | - if (route != null) { |
23 | | - addAttribute(attributes, "Route-Name", route.getName()); |
24 | | - addAttribute(attributes, "Route-Path", route.getPath()); |
| 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 | + } |
25 | 44 | } |
26 | | - } |
27 | | - |
28 | | - public static void setTransactionName(Map<String, Object> attributes, Route route) { |
29 | | - if (route != null) { |
30 | | - addAttribute(attributes, "Route-Name", route.getName()); |
31 | | - addAttribute(attributes, "Route-Path", route.getPath()); |
| 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 | + } |
32 | 54 | } |
33 | | - } |
34 | | - |
35 | | - public static void setTransactionName(RoutingContext request) { |
36 | | - String name = " "; |
37 | | - String route = request.currentRoute().getName(); |
38 | | - if (route != null & route.length() > 0) { |
39 | | - name += route; |
| 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 | + } |
40 | 63 | } |
41 | | - String path = request.currentRoute().getPath(); |
42 | | - if (path != null & path.length() > 0) { |
43 | | - name += ":" + path; |
| 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 | + } |
44 | 70 | } |
45 | | - String method = request.request().method().name(); |
46 | | - if (method != null & method.length() > 0) { |
47 | | - name += " (" + method + ")"; |
| 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()); |
| 76 | + } |
| 77 | + } |
| 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 | + } |
48 | 102 | } |
49 | | - System.out.println(name); |
50 | | - NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus", |
51 | | - "resteasy-reactive", name); |
52 | 103 |
|
53 | | - } |
| 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; |
| 113 | + } |
| 114 | + String method = request.request().method().name(); |
| 115 | + if (method != null & method.length() > 0) { |
| 116 | + name += " (" + method + ")"; |
| 117 | + } |
| 118 | + System.out.println(name); |
| 119 | + NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus", |
| 120 | + "resteasy-reactive", name); |
| 121 | + |
| 122 | + } |
54 | 123 | } |
0 commit comments