|
18 | 18 |
|
19 | 19 | public class Utils { |
20 | 20 |
|
21 | | - public static final String NEWRELIC_TOKEN = "NewRelic-Token"; |
| 21 | + public static final String NEWRELIC_TOKEN = "NewRelic-Token"; |
22 | 22 |
|
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); |
27 | 26 | } |
| 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"); |
28 | 42 |
|
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 | 43 | } |
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); |
63 | 53 | } |
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()); |
70 | 62 | } |
| 63 | + } |
71 | 64 |
|
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()); |
77 | 69 | } |
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()); |
102 | 76 | } |
| 77 | + } |
103 | 78 |
|
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); |
113 | 96 | } |
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); |
117 | 102 | } |
118 | | - System.out.println(name); |
119 | | - NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus", |
120 | | - "resteasy-reactive", name); |
| 103 | + } |
121 | 104 |
|
| 105 | + if (sb.length() > 0) { |
| 106 | + NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.CUSTOM_LOW, true, |
| 107 | + "Quarkus-Resteasy", sb.toString()); |
| 108 | + } |
122 | 109 | } |
| 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 | + } |
123 | 131 | } |
0 commit comments