Skip to content

Commit fe52180

Browse files
committed
Apply proper generic signature for Instrumenter.Default transformers()
Previously it was missing the MethodDescription portion.
1 parent 20b134e commit fe52180

77 files changed

Lines changed: 329 additions & 345 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Set;
1818
import lombok.extern.slf4j.Slf4j;
1919
import net.bytebuddy.agent.builder.AgentBuilder;
20+
import net.bytebuddy.description.method.MethodDescription;
2021
import net.bytebuddy.description.type.TypeDescription;
2122
import net.bytebuddy.matcher.ElementMatcher;
2223
import net.bytebuddy.utility.JavaModule;
@@ -161,11 +162,11 @@ public boolean matches(
161162
private class PostMatchHook implements AgentBuilder.RawMatcher {
162163
@Override
163164
public boolean matches(
164-
TypeDescription typeDescription,
165-
ClassLoader classLoader,
166-
JavaModule module,
167-
Class<?> classBeingRedefined,
168-
ProtectionDomain protectionDomain) {
165+
final TypeDescription typeDescription,
166+
final ClassLoader classLoader,
167+
final JavaModule module,
168+
final Class<?> classBeingRedefined,
169+
final ProtectionDomain protectionDomain) {
169170
postMatch(typeDescription, classLoader, module, classBeingRedefined, protectionDomain);
170171
return true;
171172
}
@@ -206,14 +207,14 @@ public ElementMatcher<ClassLoader> classLoaderMatcher() {
206207
* @param protectionDomain protection domain of the class under load.
207208
*/
208209
public void postMatch(
209-
TypeDescription typeDescription,
210-
ClassLoader classLoader,
211-
JavaModule module,
212-
Class<?> classBeingRedefined,
213-
ProtectionDomain protectionDomain) {}
210+
final TypeDescription typeDescription,
211+
final ClassLoader classLoader,
212+
final JavaModule module,
213+
final Class<?> classBeingRedefined,
214+
final ProtectionDomain protectionDomain) {}
214215

215216
/** @return A map of matcher->advice */
216-
public abstract Map<? extends ElementMatcher, String> transformers();
217+
public abstract Map<? extends ElementMatcher<? super MethodDescription>, String> transformers();
217218

218219
/**
219220
* A map of {class-name -> context-class-name}. Keys (and their subclasses) will be associated

dd-java-agent/instrumentation/akka-http-10.0/src/main/scala/datadog/trace/instrumentation/akkahttp/AkkaHttpClientInstrumentation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Map;
3030
import lombok.extern.slf4j.Slf4j;
3131
import net.bytebuddy.asm.Advice;
32+
import net.bytebuddy.description.method.MethodDescription;
3233
import net.bytebuddy.description.type.TypeDescription;
3334
import net.bytebuddy.matcher.ElementMatcher;
3435
import scala.Tuple2;
@@ -63,8 +64,8 @@ public String[] helperClassNames() {
6364
}
6465

6566
@Override
66-
public Map<ElementMatcher, String> transformers() {
67-
final Map<ElementMatcher, String> transformers = new HashMap<>();
67+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
68+
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
6869
// This is mainly for compatibility with 10.0
6970
transformers.put(
7071
named("singleRequest").and(takesArgument(0, named("akka.http.scaladsl.model.HttpRequest"))),

dd-java-agent/instrumentation/akka-http-10.0/src/main/scala/datadog/trace/instrumentation/akkahttp/AkkaHttpServerInstrumentation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727
import lombok.extern.slf4j.Slf4j;
2828
import net.bytebuddy.asm.Advice;
29+
import net.bytebuddy.description.method.MethodDescription;
2930
import net.bytebuddy.description.type.TypeDescription;
3031
import net.bytebuddy.matcher.ElementMatcher;
3132
import scala.Function1;
@@ -58,14 +59,14 @@ public String[] helperClassNames() {
5859
}
5960

6061
@Override
61-
public Map<ElementMatcher, String> transformers() {
62+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
6263
// Instrumenting akka-streams bindAndHandle api was previously attempted.
6364
// This proved difficult as there was no clean way to close the async scope
6465
// in the graph logic after the user's request handler completes.
6566
//
6667
// Instead, we're instrumenting the bindAndHandle function helpers by
6768
// wrapping the scala functions with our own handlers.
68-
final Map<ElementMatcher, String> transformers = new HashMap<>();
69+
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
6970
transformers.put(
7071
named("bindAndHandleSync").and(takesArgument(0, named("scala.Function1"))),
7172
AkkaHttpSyncAdvice.class.getName());

dd-java-agent/instrumentation/apache-httpclient-4/src/main/java/datadog/trace/instrumentation/apachehttpclient/ApacheHttpClientInstrumentation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
44
import static io.opentracing.log.Fields.ERROR_OBJECT;
5+
import static java.util.Collections.singletonMap;
56
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
67
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
78
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -22,10 +23,10 @@
2223
import io.opentracing.util.GlobalTracer;
2324
import java.io.IOException;
2425
import java.net.URI;
25-
import java.util.Collections;
2626
import java.util.Iterator;
2727
import java.util.Map;
2828
import net.bytebuddy.asm.Advice;
29+
import net.bytebuddy.description.method.MethodDescription;
2930
import net.bytebuddy.description.type.TypeDescription;
3031
import net.bytebuddy.implementation.bytecode.assign.Assigner;
3132
import net.bytebuddy.matcher.ElementMatcher;
@@ -57,8 +58,8 @@ public String[] helperClassNames() {
5758
}
5859

5960
@Override
60-
public Map<? extends ElementMatcher, String> transformers() {
61-
return Collections.singletonMap(
61+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
62+
return singletonMap(
6263
isMethod()
6364
.and(not(isAbstract()))
6465
.and(named("execute"))
@@ -137,7 +138,7 @@ public static void methodExit(
137138

138139
if (throwable != null) {
139140
Tags.ERROR.set(span, Boolean.TRUE);
140-
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
141+
span.log(singletonMap(ERROR_OBJECT, throwable));
141142
span.finish();
142143
}
143144
scope.close();

dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AWSClientInstrumentation.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.aws.v0;
22

3+
import static java.util.Collections.singletonMap;
34
import static net.bytebuddy.matcher.ElementMatchers.declaresField;
45
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
56
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -8,10 +9,10 @@
89
import com.google.auto.service.AutoService;
910
import datadog.trace.agent.tooling.Instrumenter;
1011
import io.opentracing.util.GlobalTracer;
11-
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
1414
import net.bytebuddy.asm.Advice;
15+
import net.bytebuddy.description.method.MethodDescription;
1516
import net.bytebuddy.description.type.TypeDescription;
1617
import net.bytebuddy.matcher.ElementMatcher;
1718

@@ -41,10 +42,8 @@ public String[] helperClassNames() {
4142
}
4243

4344
@Override
44-
public Map<ElementMatcher, String> transformers() {
45-
final Map<ElementMatcher, String> transformers = new HashMap<>();
46-
transformers.put(isConstructor(), AWSClientAdvice.class.getName());
47-
return transformers;
45+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
46+
return singletonMap(isConstructor(), AWSClientAdvice.class.getName());
4847
}
4948

5049
public static class AWSClientAdvice {

dd-java-agent/instrumentation/couchbase-2.0/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseBucketInstrumentation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.couchbase.client;
22

33
import static io.opentracing.log.Fields.ERROR_OBJECT;
4+
import static java.util.Collections.singletonMap;
45
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
56
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
67
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -19,10 +20,10 @@
1920
import io.opentracing.tag.Tags;
2021
import io.opentracing.util.GlobalTracer;
2122
import java.lang.reflect.Method;
22-
import java.util.Collections;
2323
import java.util.Map;
2424
import java.util.concurrent.atomic.AtomicReference;
2525
import net.bytebuddy.asm.Advice;
26+
import net.bytebuddy.description.method.MethodDescription;
2627
import net.bytebuddy.description.type.TypeDescription;
2728
import net.bytebuddy.matcher.ElementMatcher;
2829
import rx.Observable;
@@ -54,8 +55,8 @@ public String[] helperClassNames() {
5455
}
5556

5657
@Override
57-
public Map<ElementMatcher, String> transformers() {
58-
return Collections.<ElementMatcher, String>singletonMap(
58+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
59+
return singletonMap(
5960
isMethod().and(isPublic()).and(returns(named("rx.Observable"))),
6061
CouchbaseClientAdvice.class.getName());
6162
}
@@ -152,7 +153,7 @@ public void call(final Throwable throwable) {
152153
final Span span = spanRef.getAndSet(null);
153154
if (span != null) {
154155
Tags.ERROR.set(span, true);
155-
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
156+
span.log(singletonMap(ERROR_OBJECT, throwable));
156157
span.finish();
157158
}
158159
}

dd-java-agent/instrumentation/couchbase-2.0/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseClusterInstrumentation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.couchbase.client;
22

33
import static io.opentracing.log.Fields.ERROR_OBJECT;
4+
import static java.util.Collections.singletonMap;
45
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
56
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
67
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -19,10 +20,10 @@
1920
import io.opentracing.tag.Tags;
2021
import io.opentracing.util.GlobalTracer;
2122
import java.lang.reflect.Method;
22-
import java.util.Collections;
2323
import java.util.Map;
2424
import java.util.concurrent.atomic.AtomicReference;
2525
import net.bytebuddy.asm.Advice;
26+
import net.bytebuddy.description.method.MethodDescription;
2627
import net.bytebuddy.description.type.TypeDescription;
2728
import net.bytebuddy.matcher.ElementMatcher;
2829
import rx.Observable;
@@ -54,8 +55,8 @@ public String[] helperClassNames() {
5455
}
5556

5657
@Override
57-
public Map<ElementMatcher, String> transformers() {
58-
return Collections.<ElementMatcher, String>singletonMap(
58+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
59+
return singletonMap(
5960
isMethod().and(isPublic()).and(returns(named("rx.Observable"))),
6061
CouchbaseClientAdvice.class.getName());
6162
}
@@ -146,7 +147,7 @@ public void call(final Throwable throwable) {
146147
final Span span = spanRef.getAndSet(null);
147148
if (span != null) {
148149
Tags.ERROR.set(span, true);
149-
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
150+
span.log(singletonMap(ERROR_OBJECT, throwable));
150151
span.finish();
151152
}
152153
}

dd-java-agent/instrumentation/datastax-cassandra-2.3/src/main/java/datadog/trace/instrumentation/datastax/cassandra/CassandraClientInstrumentation.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.datastax.cassandra;
22

3+
import static java.util.Collections.singletonMap;
34
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
45
import static net.bytebuddy.matcher.ElementMatchers.isPrivate;
56
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -11,9 +12,9 @@
1112
import io.opentracing.Tracer;
1213
import io.opentracing.util.GlobalTracer;
1314
import java.lang.reflect.Constructor;
14-
import java.util.HashMap;
1515
import java.util.Map;
1616
import net.bytebuddy.asm.Advice;
17+
import net.bytebuddy.description.method.MethodDescription;
1718
import net.bytebuddy.description.type.TypeDescription;
1819
import net.bytebuddy.matcher.ElementMatcher;
1920

@@ -39,12 +40,10 @@ public String[] helperClassNames() {
3940
}
4041

4142
@Override
42-
public Map<ElementMatcher, String> transformers() {
43-
final Map<ElementMatcher, String> transformers = new HashMap<>();
44-
transformers.put(
43+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
44+
return singletonMap(
4545
isMethod().and(isPrivate()).and(named("newSession")).and(takesArguments(0)),
4646
CassandraClientAdvice.class.getName());
47-
return transformers;
4847
}
4948

5049
public static class CassandraClientAdvice {

dd-java-agent/instrumentation/dropwizard/dropwizard-views/src/main/java/datadog/trace/instrumentation/dropwizard/view/DropwizardViewInstrumentation.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
44
import static io.opentracing.log.Fields.ERROR_OBJECT;
5+
import static java.util.Collections.singletonMap;
56
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
67
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
78
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -19,9 +20,9 @@
1920
import io.opentracing.tag.Tags;
2021
import io.opentracing.util.GlobalTracer;
2122
import java.util.Collections;
22-
import java.util.HashMap;
2323
import java.util.Map;
2424
import net.bytebuddy.asm.Advice;
25+
import net.bytebuddy.description.method.MethodDescription;
2526
import net.bytebuddy.description.type.TypeDescription;
2627
import net.bytebuddy.matcher.ElementMatcher;
2728

@@ -38,15 +39,13 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3839
}
3940

4041
@Override
41-
public Map<ElementMatcher, String> transformers() {
42-
final Map<ElementMatcher, String> transformers = new HashMap<>();
43-
transformers.put(
42+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
43+
return singletonMap(
4444
isMethod()
4545
.and(named("render"))
4646
.and(takesArgument(0, named("io.dropwizard.views.View")))
4747
.and(isPublic()),
4848
RenderAdvice.class.getName());
49-
return transformers;
5049
}
5150

5251
public static class RenderAdvice {

dd-java-agent/instrumentation/elasticsearch-rest-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/Elasticsearch5RestClientInstrumentation.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.elasticsearch5;
22

33
import static io.opentracing.log.Fields.ERROR_OBJECT;
4+
import static java.util.Collections.singletonMap;
45
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
56
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
67
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -18,9 +19,9 @@
1819
import io.opentracing.tag.Tags;
1920
import io.opentracing.util.GlobalTracer;
2021
import java.util.Collections;
21-
import java.util.HashMap;
2222
import java.util.Map;
2323
import net.bytebuddy.asm.Advice;
24+
import net.bytebuddy.description.method.MethodDescription;
2425
import net.bytebuddy.description.type.TypeDescription;
2526
import net.bytebuddy.matcher.ElementMatcher;
2627
import org.elasticsearch.client.ResponseListener;
@@ -43,9 +44,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
4344
}
4445

4546
@Override
46-
public Map<ElementMatcher, String> transformers() {
47-
final Map<ElementMatcher, String> transformers = new HashMap<>();
48-
transformers.put(
47+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
48+
return singletonMap(
4949
isMethod()
5050
.and(isPublic())
5151
.and(named("performRequestAsync"))
@@ -54,7 +54,6 @@ public Map<ElementMatcher, String> transformers() {
5454
.and(takesArgument(1, named("java.lang.String"))) // endpoint
5555
.and(takesArgument(5, named("org.elasticsearch.client.ResponseListener"))),
5656
ElasticsearchRestClientAdvice.class.getName());
57-
return transformers;
5857
}
5958

6059
public static class ElasticsearchRestClientAdvice {

0 commit comments

Comments
 (0)