Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus enhancement #6

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@

Provides instrumentation for the Quarkus framework. This includes the following Quarkus implemented frameworks: Resteasy, Resteasy Reactive and Vert.x

## Installation
# Installation

This use this instrumentation.
1. Download the latest release.
2. In the New Relic Java Agent directory (directory containing newrelic.jar), create a directory named extensions if it doe not already exist.
3. Copy the jars into the extensions directory.
4. Restart the application.
## Instructions for Using This Instrumentation

1. **Download the Latest Release**
- Ensure you have the latest version of the instrumentation package.

2. **Prepare the New Relic Java Agent Directory**
- Navigate to the New Relic Java Agent directory where `newrelic.jar` is located.
- If it doesn't already exist, create a directory named `extensions` within the Java Agent directory.

3. **Copy the JAR Files**
- Copy the JAR files from the downloaded release into the newly created `extensions` directory.

4. **Restart Your Application**
- Restart your application to apply the new instrumentation.

5. **Run Transactions**
- Execute the transactions you want to monitor.

6. **Verify in New Relic**
- Go to the 'APM and Services' tab in New Relic.
- Explore the 'Transactions' and 'Distributed Traces' sections to view traces related to your application.


## Building
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
}

plugins {
id "de.undercouch.download" version "1.2"
id "de.undercouch.download" version "5.0.0"
}

project.ext {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
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-6.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,53 @@

import java.util.Map;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TransactionNamePriority;

import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

public class Utils {

public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if (route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}
}

public static void setTransactionName(Map<String, Object> attributes, Route route) {
if (route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}
}

public static void setTransactionName(RoutingContext request) {
String name = " ";
String route = request.currentRoute().getName();
if (route != null & route.length() > 0) {
name += route;
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if(route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}
String path = request.currentRoute().getPath();
if (path != null & path.length() > 0) {
name += ":" + path;
}
String method = request.request().method().name();
if (method != null & method.length() > 0) {
name += " (" + method + ")";
}
System.out.println(name);
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
"resteasy", name);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
@Weave
public abstract class RequestDispatcher {

@Trace
public void service(Context context,
HttpServerRequest req,
HttpServerResponse resp,
HttpRequest vertxReq, HttpResponse vertxResp, boolean handleNotFound) {
Weaver.callOriginal();
}
@Trace
public void service(Context context, HttpServerRequest req, HttpServerResponse resp, HttpRequest vertxReq,
HttpResponse vertxResp, boolean handleNotFound) {
Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
@Weave
public class VertxRequestHandler {

@Trace
public void handle(RoutingContext request) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", request.normalizedPath());
Utils.addRoute(attributes, request.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

Weaver.callOriginal();
}

@Trace
private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput output) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", routingContext.normalizedPath());
Utils.addRoute(attributes, routingContext.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
Weaver.callOriginal();
}
@Trace
public void handle(RoutingContext request) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", request.normalizedPath());
Utils.addRoute(attributes, request.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
Utils.setTransactionName(request);
Weaver.callOriginal();
}

@Trace
private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput output) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", routingContext.normalizedPath());
Utils.addRoute(attributes, routingContext.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

Weaver.callOriginal();
}

}
2 changes: 1 addition & 1 deletion quarkus-resteasy-2.11/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.quarkus-resteasy-2.0'
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.quarkus-resteasy-2.11.0'
attributes 'Implementation-Vendor': 'New Relic Labs'
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
attributes 'Implementation-Version': 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@

import java.util.Map;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TransactionNamePriority;

import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

public class Utils {

public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if (route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if(route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}
}

public static void setTransactionName(RoutingContext request) {
String name = " ";
String route = request.currentRoute().getName();
if (route != null & route.length() > 0) {
name += route;
}
String path = request.currentRoute().getPath();
if (path != null & path.length() > 0) {
name += ":" + path;
}
String method = request.request().method().name();
if (method != null & method.length() > 0) {
name += " (" + method + ")";
}
System.out.println(name);
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
"resteasy", name);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
@Weave
public abstract class RequestDispatcher {

@Trace
public void service(Context context,
HttpServerRequest req,
HttpServerResponse resp,
HttpRequest vertxReq, HttpResponse vertxResp, boolean handleNotFound) {
Weaver.callOriginal();
}
@Trace
public void service(Context context, HttpServerRequest req, HttpServerResponse resp, HttpRequest vertxReq,
HttpResponse vertxResp, boolean handleNotFound) {

Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
@Weave
public class VertxRequestHandler {

@Trace
public void handle(RoutingContext request) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", request.normalizedPath());
Utils.addRoute(attributes, request.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

Weaver.callOriginal();
}

@Trace
private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput output) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", routingContext.normalizedPath());
Utils.addRoute(attributes, routingContext.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
Weaver.callOriginal();
}
@Trace
public void handle(RoutingContext request) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", request.normalizedPath());
Utils.addRoute(attributes, request.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
Utils.setTransactionName(request);
Weaver.callOriginal();
}

@Trace
private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput output) {
HashMap<String, Object> attributes = new HashMap<String, Object>();
Utils.addAttribute(attributes, "RoutingContext-NormalizedPath", routingContext.normalizedPath());
Utils.addRoute(attributes, routingContext.currentRoute());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

Weaver.callOriginal();
}

}
2 changes: 1 addition & 1 deletion quarkus-resteasy-2.14.1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.quarkus-resteasy-2.0'
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.quarkus-resteasy-2.14.1'
attributes 'Implementation-Vendor': 'New Relic Labs'
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
attributes 'Implementation-Version': 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@

import java.util.Map;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TransactionNamePriority;

import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

public class Utils {

public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
public static final String NEWRELIC_TOKEN = "NewRelic-Token";

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);
}
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if (route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}

public static void addRoute(Map<String, Object> attributes, Route route) {
if(route != null) {
addAttribute(attributes, "Route-Name", route.getName());
addAttribute(attributes, "Route-Path", route.getPath());
}
}

public static void setTransactionName(RoutingContext request) {
String name = " ";
String route = request.currentRoute().getName();
if (route != null & route.length() > 0) {
name += route;
}
String path = request.currentRoute().getPath();
if (path != null & path.length() > 0) {
name += ":" + path;
}
String method = request.request().method().name();
if (method != null & method.length() > 0) {
name += " (" + method + ")";
}
System.out.println(name);
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Quarkus",
"resteasy", name);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
@Weave
public abstract class RequestDispatcher {

@Trace
public void service(Context context,
HttpServerRequest req,
HttpServerResponse resp,
HttpRequest vertxReq, HttpResponse vertxResp, boolean handleNotFound, Throwable t) {
if(t != null) {
NewRelic.noticeError(t);
}
Weaver.callOriginal();
@Trace
public void service(Context context, HttpServerRequest req, HttpServerResponse resp, HttpRequest vertxReq,
HttpResponse vertxResp, boolean handleNotFound, Throwable t) {
if (t != null) {
NewRelic.noticeError(t);
}

Weaver.callOriginal();
}
}
Loading
Loading