Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.apachehttpasyncclient;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate;
Expand All @@ -9,6 +10,7 @@
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

Expand Down Expand Up @@ -38,6 +40,12 @@ public ApacheHttpAsyncClientInstrumentation() {
super("httpasyncclient", "apache-httpasyncclient");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/apache/http/nio/client/HttpAsyncClient.class"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double negatives are somewhat hard to read

}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("org.apache.http.nio.client.HttpAsyncClient"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datadog.trace.instrumentation.apachehttpasyncclient;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
Expand All @@ -29,6 +31,12 @@ public ApacheHttpClientRedirectInstrumentation() {
super("httpasyncclient", "apache-httpasyncclient");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/apache/http/client/RedirectStrategy.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("org.apache.http.client.RedirectStrategy"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.apachehttpclient;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate;
Expand Down Expand Up @@ -41,6 +42,12 @@ public ApacheHttpClientInstrumentation() {
super("httpclient", "apache-httpclient", "apache-http-client");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/apache/http/client/HttpClient.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("org.apache.http.client.HttpClient"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datadog.trace.instrumentation.aws.v0;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.amazonaws.AmazonWebServiceRequest;
Expand All @@ -25,6 +27,12 @@ public RequestInstrumentation() {
super("aws-sdk");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("com/amazonaws/AmazonWebServiceRequest.class"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double negative is a bit hard to read. I think a utility method would help clarity greatly.

}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return nameStartsWith("com.amazonaws.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.cluster.ClusterManager
import com.couchbase.client.java.env.CouchbaseEnvironment
import org.springframework.data.couchbase.core.CouchbaseTemplate
import spock.lang.Retry
import spock.lang.Shared
import spock.lang.Unroll
import util.AbstractCouchbaseTest

import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace

@Retry(count = 5, delay = 1)
@Unroll
class CouchbaseSpringTemplateTest extends AbstractCouchbaseTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package datadog.trace.instrumentation.couchbase.client;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

Expand All @@ -29,6 +31,14 @@ public CouchbaseNetworkInstrumentation() {
super("couchbase");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(
classLoaderHasNoResources(
"com/couchbase/client/core/endpoint/AbstractGenericHandler.class"));
}

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
// Exact class because private fields are used
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.dropwizard.view;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
Expand All @@ -8,6 +9,7 @@
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
Expand All @@ -30,6 +32,12 @@ public DropwizardViewInstrumentation() {
super("dropwizard", "dropwizard-view");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("io/dropwizard/views/ViewRenderer.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("io.dropwizard.views.ViewRenderer"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.lang.reflect.Proxy

import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace

@RetryOnFailure(times = 3, delaySeconds = 1)
@RetryOnFailure(times = 10, delaySeconds = 1)
class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
// Setting up appContext & repo with @Shared doesn't allow
// spring-data instrumentation to applied.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.finatra;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
Expand All @@ -9,6 +10,7 @@
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

Expand Down Expand Up @@ -48,6 +50,12 @@ public String[] helperClassNames() {
};
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("com/twitter/finatra/http/internal/routing/Route.class"));
}

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return nameStartsWith("com.twitter.finatra.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

/**
* This instrumenter prevents a mechanism from GlassFish classloader to produces a class not found
Expand All @@ -39,8 +38,7 @@ public String[] helperClassNames() {

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return ElementMatchers.named(
"com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader");
return named("com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package datadog.trace.instrumentation.hibernate.core.v3_3;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static net.bytebuddy.matcher.ElementMatchers.not;

import datadog.trace.agent.tooling.Instrumenter;
import net.bytebuddy.matcher.ElementMatcher;
import org.hibernate.classic.Validatable;
import org.hibernate.transaction.JBossTransactionManagerLookup;

Expand All @@ -10,6 +14,12 @@ public AbstractHibernateInstrumentation() {
super("hibernate", "hibernate-core");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/hibernate/Session.class"));
}

@Override
public String[] helperClassNames() {
return new String[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package datadog.trace.instrumentation.hibernate.core.v4_0;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static net.bytebuddy.matcher.ElementMatchers.not;

import datadog.trace.agent.tooling.Instrumenter;
import net.bytebuddy.matcher.ElementMatcher;
import org.hibernate.SharedSessionContract;

public abstract class AbstractHibernateInstrumentation extends Instrumenter.Default {
Expand All @@ -9,6 +13,12 @@ public AbstractHibernateInstrumentation() {
super("hibernate", "hibernate-core");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/hibernate/Session.class"));
}

@Override
public String[] helperClassNames() {
return new String[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datadog.trace.instrumentation.hibernate.core.v4_3;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
Expand Down Expand Up @@ -43,6 +45,12 @@ public String[] helperClassNames() {
};
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/hibernate/Session.class"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One observation from the field injection optimization. Often our classLoaderMatchers are really more aim at matching a library or an API, but we don't really have that as a concept in the code.

I think this change also suggest that we should have some notion of a Library go which Instrumenters refer.

}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("org.hibernate.procedure.ProcedureCall"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datadog.trace.instrumentation.hibernate.core.v4_3;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.hasInterface;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.returns;

import com.google.auto.service.AutoService;
Expand Down Expand Up @@ -50,6 +52,12 @@ public String[] helperClassNames() {
};
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("org/hibernate/Session.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("org.hibernate.SharedSessionContract"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package datadog.trace.instrumentation.hystrix;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static datadog.trace.instrumentation.hystrix.HystrixDecorator.DECORATE;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.returns;

import com.google.auto.service.AutoService;
Expand All @@ -27,6 +29,12 @@ public HystrixInstrumentation() {
super("hystrix");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("com/netflix/hystrix/HystrixCommand.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return extendsClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
Expand All @@ -36,7 +37,9 @@ public JaxRsAnnotationsInstrumentation() {
// this is required to make sure instrumentation won't apply to jax-rs 2
@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
return classLoaderHasNoResources("javax/ws/rs/container/AsyncResponse.class");
return classLoaderHasNoResources("javax/ws/rs/container/AsyncResponse.class")
// Optimization for expensive typeMatcher.
.and(not(classLoaderHasNoResources("javax/ws/rs/Path.class")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.jaxrs2;

import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasNoResources;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
Expand All @@ -8,6 +9,7 @@
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

Expand All @@ -26,6 +28,12 @@ public AbstractRequestContextInstrumentation() {
super("jax-rs", "jaxrs", "jax-rs-filter");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
// Optimization for expensive typeMatcher.
return not(classLoaderHasNoResources("javax/ws/rs/container/ContainerRequestContext.class"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("javax.ws.rs.container.ContainerRequestContext"));
Expand Down
Loading