Skip to content
Closed
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.agent.tooling.bytebuddy.matcher;

import java.util.regex.Pattern;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

Expand All @@ -14,6 +15,9 @@
public class AdditionalLibraryIgnoresMatcher<T extends TypeDescription>
extends ElementMatcher.Junction.AbstractBase<T> {

private static final Pattern COM_MCHANGE_PROXY =
Pattern.compile("com\\.mchange\\.v2\\.c3p0\\..*Proxy");

public static <T extends TypeDescription> Junction<T> additionalLibraryIgnoresMatcher() {
return new AdditionalLibraryIgnoresMatcher<>();
}
Expand All @@ -28,26 +32,39 @@ public boolean matches(final T target) {
final String name = target.getActualName();

if (name.startsWith("com.beust.jcommander.")
|| name.startsWith("com.carrotsearch.hppc.")
|| name.startsWith("com.couchbase.client.deps.")
|| name.startsWith("com.fasterxml.classmate.")
|| name.startsWith("com.fasterxml.jackson.")
|| name.startsWith("com.github.mustachejava.")
|| name.startsWith("com.jayway.jsonpath.")
|| name.startsWith("com.lightbend.lagom")
|| name.startsWith("com.lightbend.lagom.")
|| name.startsWith("com.netflix.hystrix.") // test this
|| name.startsWith("io.micrometer.")
|| name.startsWith("io.github.classgraph.")
|| name.startsWith("javax.el.")
|| name.startsWith("javax.crypto.")
|| name.startsWith("javax.cache.")
|| name.startsWith("javax.management.")
|| name.startsWith("javax.persistence.")
|| name.startsWith("net.sf.cglib.")
|| name.startsWith("org.apache.lucene")
|| name.startsWith("org.apache.tartarus")
|| name.startsWith("org.json.simple")
|| name.startsWith("org.objectweb.asm.")
|| name.startsWith("org.yaml.snakeyaml")) {
|| name.startsWith("nonapi.io.github.classgraph.")
|| name.startsWith("org.apache.commons.")
|| name.startsWith("org.apache.coyote.")
|| name.startsWith("org.apache.el.")
|| name.startsWith("org.apache.juli.")
|| name.startsWith("org.apache.lucene.")
|| name.startsWith("org.apache.naming.")
|| name.startsWith("org.apache.tartarus.")
|| name.startsWith("org.ehcache.")
|| name.startsWith("org.hibernate.") // test this
|| name.startsWith("org.json.simple.")
|| name.startsWith("org.msgpack.")
|| name.startsWith("org.thymeleaf.")
|| name.startsWith("org.yaml.snakeyaml.")) {
return true;
}

if (name.startsWith("org.springframework.")) {
if (name.startsWith("org.springframework.aop.")
|| name.startsWith("org.springframework.asm.")
|| name.startsWith("org.springframework.cache.")
|| name.startsWith("org.springframework.dao.")
|| name.startsWith("org.springframework.ejb.")
Expand All @@ -60,16 +77,15 @@ public boolean matches(final T target) {
|| name.startsWith("org.springframework.jmx.")
|| name.startsWith("org.springframework.jndi.")
|| name.startsWith("org.springframework.lang.")
|| name.startsWith("org.springframework.mail.")
|| name.startsWith("org.springframework.messaging.")
|| name.startsWith("org.springframework.objenesis.")
|| name.startsWith("org.springframework.orm.")
|| name.startsWith("org.springframework.remoting.")
|| name.startsWith("org.springframework.scheduling.annotation")
|| name.startsWith("org.springframework.scripting.")
|| name.startsWith("org.springframework.stereotype.")
|| name.startsWith("org.springframework.transaction.")
|| name.startsWith("org.springframework.ui.")
|| name.startsWith("org.springframework.util.")
|| name.startsWith("org.springframework.validation.")) {
return true;
}
Expand Down Expand Up @@ -101,7 +117,10 @@ public boolean matches(final T target) {
if (name.startsWith("org.springframework.boot.")) {
// More runnables to deal with
if (name.startsWith("org.springframework.boot.autoconfigure.BackgroundPreinitializer$")
|| name.startsWith("org.springframework.boot.web.embedded.netty.NettyWebServer$")) {
|| name.startsWith("org.springframework.boot.autoconfigure.condition.OnClassCondition$")
|| name.startsWith("org.springframework.boot.web.embedded.netty.NettyWebServer$")
|| name.startsWith(
"org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer$")) {
return false;
}
return true;
Expand Down Expand Up @@ -140,9 +159,17 @@ public boolean matches(final T target) {
return true;
}

if (name.startsWith("org.springframework.util.")) {
if (name.startsWith("org.springframework.util.concurrent.")) {
return false;
}
return true;
}

if (name.startsWith("org.springframework.web.")) {
if (name.startsWith("org.springframework.web.servlet.")
|| name.startsWith("org.springframework.web.reactive.")) {
|| name.startsWith("org.springframework.web.reactive.")
|| name.startsWith("org.springframework.web.context.request.async.")) {
return false;
}
return true;
Expand All @@ -161,7 +188,10 @@ public boolean matches(final T target) {
|| name.startsWith("org.apache.xerces.")
|| name.startsWith("org.apache.xml.")
|| name.startsWith("org.apache.xpath.")
|| name.startsWith("org.xml.")) {
|| name.startsWith("org.xml.")
|| name.startsWith("com.sun.org.apache.xerces.")
|| name.startsWith("com.sun.org.apache.xalan.")
|| name.startsWith("com.sun.xml.")) {
return true;
}

Expand All @@ -182,8 +212,12 @@ public boolean matches(final T target) {
return true;
}

if (name.startsWith("com.datastax.driver.")) {
if (name.startsWith("com.datastax.driver.core.Cluster$")) {
if (name.startsWith("com.couchbase.client.deps.")) {
// Couchbase library includes some packaged dependencies, unfortunately some of them are
// instrumented by java-concurrent instrumentation
if (name.startsWith("com.couchbase.client.deps.io.netty.")
|| name.startsWith("com.couchbase.client.deps.org.LatencyUtils.")
|| name.startsWith("com.couchbase.client.deps.com.lmax.disruptor.")) {
return false;
}
return true;
Expand Down Expand Up @@ -216,7 +250,7 @@ public boolean matches(final T target) {
return true;
}
if (name.startsWith("com.google.api.")) {
if (name.equals("com.google.api.client.http.HttpRequest")) {
if (name.startsWith("com.google.api.client.http.HttpRequest")) {
return false;
}
return true;
Expand All @@ -227,8 +261,66 @@ public boolean matches(final T target) {
|| name.startsWith("org.h2.jdbc.")
|| name.startsWith("org.h2.jdbcx.")
// Some runnables that get instrumented
|| name.equals("org.h2.util.Task")
|| name.equals("org.h2.store.FileLock")
|| name.equals("org.h2.engine.DatabaseCloser")) {
|| name.equals("org.h2.engine.DatabaseCloser")
|| name.equals("org.h2.engine.OnExitDatabaseCloser")) {
return false;
}
return true;
}

if (name.startsWith("com.carrotsearch.hppc.")) {
if (name.startsWith("com.carrotsearch.hppc.HashOrderMixing$")) {
return false;
}
return true;
}

if (name.startsWith("okio.")) {
if (name.equals("okio.AsyncTimeout$Watchdog")) {
return false;
}
return true;
}

if (name.startsWith("org.hsqldb.")) {
if (name.startsWith("org.hsqldb.jdbc.")) {
return false;
}
return true;
}

if (name.startsWith("org.apache.catalina.")) {
if (name.startsWith("org.apache.catalina.connector.")
|| name.startsWith("org.apache.catalina.core.")
|| name.startsWith("org.apache.catalina.servlets.")) {
return false;
}
return true;
}

if (name.startsWith("org.apache.logging.")) {
// We instrument single class in the whole library
// But unfortunately we also instrument some runnables
if (name.equals("org.apache.logging.log4j.ThreadContext")
|| name.equals("org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry")) {
return false;
}
return true;
}

if (name.startsWith("org.apache.tomcat.")) {
if (name.startsWith("org.apache.tomcat.jdbc.")) {
return false;
}
return true;
}

if (name.startsWith("io.grpc.")) {
// We instrument two specific classes
if (name.startsWith("io.grpc.internal.AbstractManagedChannelImplBuilder")
|| name.startsWith("io.grpc.internal.AbstractServerImplBuilder")) {
return false;
}
return true;
Expand All @@ -239,6 +331,10 @@ public boolean matches(final T target) {
return true;
}

if (COM_MCHANGE_PROXY.matcher(name).matches()) {
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.trace.agent.tooling.bytebuddy.matcher;

import java.util.regex.Pattern;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

Expand All @@ -23,9 +22,6 @@
public class GlobalIgnoresMatcher<T extends TypeDescription>
extends ElementMatcher.Junction.AbstractBase<T> {

private static final Pattern COM_MCHANGE_PROXY =
Pattern.compile("com\\.mchange\\.v2\\.c3p0\\..*Proxy");

public static <T extends TypeDescription> ElementMatcher.Junction<T> globalIgnoresMatcher() {
return new GlobalIgnoresMatcher<>();
}
Expand Down Expand Up @@ -144,10 +140,6 @@ public boolean matches(final T target) {
return true;
}

if (COM_MCHANGE_PROXY.matcher(name).matches()) {
return true;
}

if (additionalLibraryIgnoreMatcher.matches(target)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
startSpan("grpc.client").setTag(DDTags.RESOURCE_NAME, method.getFullMethodName());
try (final AgentScope scope = activateSpan(span, false)) {
DECORATE.afterStart(span);
scope.setAsyncPropagation(true);

final ClientCall<ReqT, RespT> result;
try {
Expand Down Expand Up @@ -64,7 +63,6 @@ public void start(final Listener<RespT> responseListener, final Metadata headers
propagate().inject(span, headers, SETTER);

try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
super.start(new TracingClientCallListener<>(span, responseListener), headers);
} catch (final Throwable e) {
DECORATE.onError(span, e);
Expand All @@ -77,7 +75,6 @@ public void start(final Listener<RespT> responseListener, final Metadata headers
@Override
public void sendMessage(final ReqT message) {
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
super.sendMessage(message);
} catch (final Throwable e) {
DECORATE.onError(span, e);
Expand All @@ -104,7 +101,6 @@ public void onMessage(final RespT message) {
.setTag("message.type", message.getClass().getName());
DECORATE.afterStart(messageSpan);
final AgentScope scope = activateSpan(messageSpan, true);
scope.setAsyncPropagation(true);
try {
delegate().onMessage(message);
} catch (final Throwable e) {
Expand All @@ -121,7 +117,6 @@ public void onClose(final Status status, final Metadata trailers) {
DECORATE.onClose(span, status);
// Finishes span.
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onClose(status, trailers);
} catch (final Throwable e) {
DECORATE.onError(span, e);
Expand All @@ -135,7 +130,6 @@ public void onClose(final Status status, final Metadata trailers) {
@Override
public void onReady() {
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onReady();
} catch (final Throwable e) {
DECORATE.onError(span, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
DECORATE.afterStart(span);

final AgentScope scope = activateSpan(span, false);
scope.setAsyncPropagation(true);

final ServerCall.Listener<ReqT> result;
try {
Expand All @@ -53,7 +52,6 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
span.finish();
throw e;
} finally {
scope.setAsyncPropagation(false);
scope.close();
}

Expand All @@ -74,9 +72,7 @@ static final class TracingServerCall<ReqT, RespT>
public void close(final Status status, final Metadata trailers) {
DECORATE.onClose(span, status);
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().close(status, trailers);
scope.setAsyncPropagation(false);
} catch (final Throwable e) {
DECORATE.onError(span, e);
throw e;
Expand All @@ -100,7 +96,6 @@ public void onMessage(final ReqT message) {
.setTag("message.type", message.getClass().getName());
DECORATE.afterStart(span);
final AgentScope scope = activateSpan(span, true);
scope.setAsyncPropagation(true);
try {
delegate().onMessage(message);
} catch (final Throwable e) {
Expand All @@ -109,7 +104,6 @@ public void onMessage(final ReqT message) {
this.span.finish();
throw e;
} finally {
scope.setAsyncPropagation(false);
DECORATE.beforeFinish(span);
scope.close();
}
Expand All @@ -118,9 +112,7 @@ public void onMessage(final ReqT message) {
@Override
public void onHalfClose() {
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onHalfClose();
scope.setAsyncPropagation(false);
} catch (final Throwable e) {
DECORATE.onError(span, e);
DECORATE.beforeFinish(span);
Expand All @@ -133,10 +125,8 @@ public void onHalfClose() {
public void onCancel() {
// Finishes span.
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onCancel();
span.setTag("canceled", true);
scope.setAsyncPropagation(false);
} catch (final Throwable e) {
DECORATE.onError(span, e);
throw e;
Expand All @@ -150,9 +140,7 @@ public void onCancel() {
public void onComplete() {
// Finishes span.
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onComplete();
scope.setAsyncPropagation(false);
} catch (final Throwable e) {
DECORATE.onError(span, e);
throw e;
Expand All @@ -165,9 +153,7 @@ public void onComplete() {
@Override
public void onReady() {
try (final AgentScope scope = activateSpan(span, false)) {
scope.setAsyncPropagation(true);
delegate().onReady();
scope.setAsyncPropagation(false);
} catch (final Throwable e) {
DECORATE.onError(span, e);
DECORATE.beforeFinish(span);
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ subprojects { Project subProj ->
annotationProcessor deps.autoservice
implementation deps.autoservice

// Always include concurrent instrumentation dependency to make sure that all instrumentations are tested with async parts instrumented
testCompile project(':dd-java-agent:instrumentation:java-concurrent')
testCompile project(':dd-java-agent:testing')
testAnnotationProcessor deps.autoservice
testImplementation deps.autoservice
Expand Down
Loading