Skip to content

Commit ac4de53

Browse files
mdindofferfelixbarny
authored andcommitted
Exclude $view proxies from JAX-RS instrumentation (#600)
1 parent 42e951b commit ac4de53

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public ElementMatcher<? super TypeDescription> getTypeMatcher() {
8181
if (configuration.isEnableJaxrsAnnotationInheritance()) {
8282
return not(isInterface())
8383
.and(not(ElementMatchers.<TypeDescription>nameContains("$Proxy")))
84+
.and(not(ElementMatchers.<TypeDescription>nameContains("$view")))
8485
.and(isAnnotatedWith(named("javax.ws.rs.Path"))
8586
.or(hasSuperType(isAnnotatedWith(named("javax.ws.rs.Path"))))
8687
);

apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTest.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ public void testJaxRsTransactionNameWithJaxrsAnnotationInheritance() {
106106
assertThat(actualTransactions.get(2).getName().toString()).isEqualTo("ResourceWithPathOnAbstract#testMethod");
107107
}
108108

109+
@Test
110+
public void testProxyClassInstrumentationExclusion() {
111+
when(config.getConfig(JaxRsConfiguration.class).isEnableJaxrsAnnotationInheritance()).thenReturn(true);
112+
ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install());
113+
114+
doRequest("testViewProxy");
115+
doRequest("testProxyProxy");
116+
117+
List<Transaction> actualTransactions = reporter.getTransactions();
118+
assertThat(actualTransactions).hasSize(2);
119+
assertThat(actualTransactions.get(0).getName().toString()).isEqualTo("unnamed");
120+
assertThat(actualTransactions.get(1).getName().toString()).isEqualTo("unnamed");
121+
}
122+
109123
@Test
110124
public void testJaxRsTransactionNameNonSampledTransactions() throws IOException {
111125
config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME);
@@ -121,8 +135,13 @@ public void testJaxRsTransactionNameNonSampledTransactions() throws IOException
121135
/**
122136
* @return configuration for the jersey test server. Includes all resource classes in the co.elastic.apm.agent.jaxrs.resources package.
123137
*/
138+
@Override
124139
protected Application configure() {
125-
return new ResourceConfig(ResourceWithPath.class, ResourceWithPathOnInterface.class, ResourceWithPathOnAbstract.class);
140+
return new ResourceConfig(ResourceWithPath.class,
141+
ResourceWithPathOnInterface.class,
142+
ResourceWithPathOnAbstract.class,
143+
ProxiedClass$view.class,
144+
ProxiedClass$Proxy.class);
126145
}
127146

128147
/**
@@ -147,29 +166,38 @@ public interface SuperResourceInterface {
147166
@Path("testInterface")
148167
public interface ResourceInterfaceWithPath extends SuperResourceInterface {
149168
String testMethod();
150-
151169
}
152170

153171
public interface ResourceInterfaceWithoutPath extends SuperResourceInterface {
154172
String testMethod();
155173
}
156174

157175
public abstract static class AbstractResourceClassWithoutPath implements ResourceInterfaceWithoutPath {
158-
159176
}
160177

161178
@Path("testAbstract")
162179
public abstract static class AbstractResourceClassWithPath implements ResourceInterfaceWithoutPath {
180+
}
163181

182+
@Path("testViewProxy")
183+
public static class ProxiedClass$view implements SuperResourceInterface {
184+
public String testMethod() {
185+
return "ok";
186+
}
187+
}
164188

189+
@Path("testProxyProxy")
190+
public static class ProxiedClass$Proxy implements SuperResourceInterface {
191+
public String testMethod() {
192+
return "ok";
193+
}
165194
}
166195

167196
@Path("test")
168197
public static class ResourceWithPath extends AbstractResourceClassWithoutPath {
169198
public String testMethod() {
170199
return "ok";
171200
}
172-
173201
}
174202

175203
public static class ResourceWithPathOnAbstract extends AbstractResourceClassWithPath {

0 commit comments

Comments
 (0)