-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added instrumentation for the HttpServlet class in servlet-2.4, servlet-5.0 and servlet-6.0 * added instrumentation for the HttpServlet class in servlet-5.0 * added instrumentation for the HttpServlet class in servlet-6.0 * updated build.gradle
- Loading branch information
1 parent
b028be1
commit 3bbdccc
Showing
14 changed files
with
1,572 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...rumentation/servlet-2.4/src/main/java/javax/servlet/http/HttpServlet_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package javax.servlet.http; | ||
|
||
|
||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
import javax.servlet.ServletException; | ||
import java.io.IOException; | ||
|
||
|
||
@Weave(type = MatchType.BaseClass, originalName = "javax.servlet.http.HttpServlet") | ||
public abstract class HttpServlet_Instrumentation { | ||
|
||
|
||
@Trace | ||
protected abstract void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...mentation/servlet-5.0/src/main/java/jakarta/servlet/http/HttpServlet_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jakarta.servlet.http; | ||
|
||
|
||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import jakarta.servlet.ServletException; | ||
|
||
|
||
import java.io.IOException; | ||
|
||
|
||
@Weave(type = MatchType.BaseClass, originalName = "jakarta.servlet.http.HttpServlet") | ||
public abstract class HttpServlet_Instrumentation { | ||
|
||
|
||
@Trace | ||
protected abstract void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
|
||
|
||
@Trace | ||
protected abstract void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException; | ||
} |
102 changes: 102 additions & 0 deletions
102
...umentation/servlet-5.0/src/test/java/notjavax/servlet/HttpServletInstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package notjavax.servlet; | ||
|
||
import com.newrelic.agent.introspec.*; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(InstrumentationTestRunner.class) | ||
@InstrumentationTestConfig(includePrefixes = "jakarta.servlet", configName = "debug.yml") | ||
public class HttpServletInstrumentationTest { | ||
|
||
@Test | ||
public void doGetShouldAddMetricsForTransaction() throws InterruptedException, ServletException, IOException { | ||
|
||
String currentMethod = "GET"; | ||
String transactionName = "WebTransaction/Uri/Unknown"; | ||
|
||
startTx(currentMethod); | ||
Introspector introspector = InstrumentationTestRunner.getIntrospector(); | ||
Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(transactionName); | ||
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName); | ||
String methodInTrace = traces.iterator().next().getInitialTraceSegment().getChildren().get(0).getMethodName(); | ||
|
||
assertEquals(1, traces.size()); | ||
assertEquals(2, metricsForTransaction.size()); | ||
assertEquals("doGet", methodInTrace); | ||
assertTrue(metricsForTransaction.containsKey("Java/notjavax.servlet.MyServlet/doGet")); | ||
} | ||
|
||
@Test | ||
public void doPostShouldAddMetricsForTransaction() throws InterruptedException, ServletException, IOException { | ||
|
||
String currentMethod = "POST"; | ||
String transactionName = "WebTransaction/Uri/Unknown"; | ||
|
||
startTx(currentMethod); | ||
Introspector introspector = InstrumentationTestRunner.getIntrospector(); | ||
Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(transactionName); | ||
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName); | ||
String methodInTrace = traces.iterator().next().getInitialTraceSegment().getChildren().get(0).getMethodName(); | ||
|
||
assertEquals(1, traces.size()); | ||
assertEquals(2, metricsForTransaction.size()); | ||
assertEquals("doPost", methodInTrace); | ||
assertTrue(metricsForTransaction.containsKey("Java/notjavax.servlet.MyServlet/doPost")); | ||
} | ||
|
||
@Test | ||
public void doPutShouldAddMetricsForTransaction() throws InterruptedException, ServletException, IOException { | ||
|
||
String currentMethod = "PUT"; | ||
String transactionName = "WebTransaction/Uri/Unknown"; | ||
|
||
startTx(currentMethod); | ||
Introspector introspector = InstrumentationTestRunner.getIntrospector(); | ||
Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(transactionName); | ||
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName); | ||
String methodInTrace = traces.iterator().next().getInitialTraceSegment().getChildren().get(0).getMethodName(); | ||
|
||
assertEquals(1, traces.size()); | ||
assertEquals(2, metricsForTransaction.size()); | ||
assertEquals("doPut", methodInTrace); | ||
assertTrue(metricsForTransaction.containsKey("Java/notjavax.servlet.MyServlet/doPut")); | ||
} | ||
|
||
@Test | ||
public void doDeleteShouldAddMetricsForTransaction() throws InterruptedException, ServletException, IOException { | ||
|
||
String currentMethod = "DELETE"; | ||
String transactionName = "WebTransaction/Uri/Unknown"; | ||
|
||
startTx(currentMethod); | ||
Introspector introspector = InstrumentationTestRunner.getIntrospector(); | ||
Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(transactionName); | ||
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName); | ||
String methodInTrace = traces.iterator().next().getInitialTraceSegment().getChildren().get(0).getMethodName(); | ||
|
||
assertEquals(1, traces.size()); | ||
assertEquals(2, metricsForTransaction.size()); | ||
assertEquals("doDelete", methodInTrace); | ||
assertTrue(metricsForTransaction.containsKey("Java/notjavax.servlet.MyServlet/doDelete")); | ||
} | ||
|
||
private void startTx(String currentMethod) throws ServletException, IOException { | ||
|
||
MyServlet myServlet = new MyServlet(); | ||
HttpServletTestRequest request = new HttpServletTestRequest(); | ||
HttpServletTestResponse response = new HttpServletTestResponse(); | ||
|
||
request.setCurrentMethod(currentMethod); | ||
myServlet.service(request, response); | ||
} | ||
} |
Oops, something went wrong.