diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/build.gradle b/dd-java-agent/instrumentation/commons-httpclient-2.0/build.gradle index b406619e198..49ef91fbad4 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/build.gradle +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/build.gradle @@ -2,20 +2,10 @@ muzzle { pass { group = "commons-httpclient" module = "commons-httpclient" - versions = "[2.0,]" - skipVersions += "20020423" // ancient pre-release version + versions = "[2.0,4.0)" skipVersions += '2.0-final' // broken metadata on maven central assertInverse = true } - pass { - name = 'commons-http-client-x' // for IAST instrumenters valid for 1.x - group = "commons-httpclient" - module = "commons-httpclient" - versions = "[2.0,]" - skipVersions += "20020423" // ancient pre-release version - skipVersions += '2.0-final' // broken metadata on maven central - assertInverse = false - } } apply from: "$rootDir/gradle/java.gradle" @@ -27,5 +17,5 @@ dependencies { testImplementation group: 'commons-httpclient', name: 'commons-httpclient', version: '2.0' - latestDepTestImplementation group: 'commons-httpclient', name: 'commons-httpclient', version: '(2.0,20000000]' + latestDepTestImplementation group: 'commons-httpclient', name: 'commons-httpclient', version: '2.+' } diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/gradle.lockfile b/dd-java-agent/instrumentation/commons-httpclient-2.0/gradle.lockfile index ae2e9a50da7..e69de29bb2d 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/gradle.lockfile +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/gradle.lockfile @@ -1,133 +0,0 @@ -# This is a Gradle generated file for dependency locking. -# Manual edits can break the build and are not advised. -# This file is expected to be part of source control. -# To regenerate this file, run: ./gradlew :dd-java-agent:instrumentation:commons-httpclient-2.0:dependencies --write-locks -cafe.cryptography:curve25519-elisabeth:0.1.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -cafe.cryptography:ed25519-elisabeth:0.1.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -ch.qos.logback:logback-classic:1.2.13=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -ch.qos.logback:logback-core:1.2.13=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.blogspot.mydailyjava:weak-lock-free:0.17=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.datadoghq.okhttp3:okhttp:3.12.15=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.datadoghq.okio:okio:1.17.6=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.datadoghq:dd-instrument-java:0.0.4=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleBootstrap,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.datadoghq:dd-javac-plugin-client:0.2.2=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleBootstrap,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.datadoghq:java-dogstatsd-client:4.4.5=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.datadoghq:sketches-java:0.8.3=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.javaparser:javaparser-core:3.25.6=codenarc -com.github.jnr:jffi:1.3.15=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-a64asm:1.0.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-constants:0.10.4=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-enxio:0.32.20=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-ffi:2.2.19=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-posix:3.1.22=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-unixsocket:0.38.25=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.jnr:jnr-x86asm:1.0.2=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.github.spotbugs:spotbugs-annotations:4.9.8=compileClasspath,spotbugs -com.github.spotbugs:spotbugs:4.9.8=spotbugs -com.github.stephenc.jcip:jcip-annotations:1.0-1=spotbugs -com.google.auto.service:auto-service-annotations:1.1.1=annotationProcessor,compileClasspath,latestDepTestAnnotationProcessor,latestDepTestCompileClasspath,testAnnotationProcessor,testCompileClasspath -com.google.auto.service:auto-service:1.1.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.auto:auto-common:1.2.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,compileClasspath,latestDepTestAnnotationProcessor,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,spotbugs,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath -com.google.code.gson:gson:2.13.2=spotbugs -com.google.errorprone:error_prone_annotations:2.18.0=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.errorprone:error_prone_annotations:2.41.0=spotbugs -com.google.errorprone:error_prone_annotations:2.47.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.google.guava:failureaccess:1.0.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.guava:failureaccess:1.0.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.google.guava:guava:32.0.1-jre=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.guava:guava:33.6.0-jre=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,latestDepTestAnnotationProcessor,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath -com.google.j2objc:j2objc-annotations:2.8=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -com.google.j2objc:j2objc-annotations:3.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.google.re2j:re2j:1.8=latestDepTestRuntimeClasspath,testRuntimeClasspath -com.squareup.moshi:moshi:1.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.squareup.okhttp3:logging-interceptor:3.12.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.squareup.okhttp3:okhttp:3.12.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.squareup.okio:okio:1.17.5=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.thoughtworks.qdox:qdox:1.12.1=codenarc -commons-codec:commons-codec:1.2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath -commons-fileupload:commons-fileupload:1.5=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -commons-httpclient:commons-httpclient:2.0=compileClasspath,testCompileClasspath,testRuntimeClasspath -commons-httpclient:commons-httpclient:3.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath -commons-io:commons-io:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -commons-io:commons-io:2.20.0=spotbugs -commons-lang:commons-lang:1.0.1=compileClasspath,testCompileClasspath,testRuntimeClasspath -commons-logging:commons-logging:1.0.3=compileClasspath,testCompileClasspath,testRuntimeClasspath -commons-logging:commons-logging:1.0.4=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath -de.thetaphi:forbiddenapis:3.10=compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -io.leangen.geantyref:geantyref:1.3.16=latestDepTestRuntimeClasspath,testRuntimeClasspath -io.sqreen:libsqreen:17.3.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -javax.servlet:javax.servlet-api:3.1.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -jaxen:jaxen:2.0.0=spotbugs -junit:junit:4.13.2=latestDepTestRuntimeClasspath,testRuntimeClasspath -net.bytebuddy:byte-buddy-agent:1.18.10=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -net.bytebuddy:byte-buddy:1.18.10=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -net.java.dev.jna:jna-platform:5.8.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -net.java.dev.jna:jna:5.8.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -net.sf.saxon:Saxon-HE:12.9=spotbugs -org.apache.ant:ant-antlr:1.10.14=codenarc -org.apache.ant:ant-junit:1.10.14=codenarc -org.apache.bcel:bcel:6.11.0=spotbugs -org.apache.commons:commons-lang3:3.19.0=spotbugs -org.apache.commons:commons-text:1.14.0=spotbugs -org.apache.logging.log4j:log4j-api:2.25.2=spotbugs -org.apache.logging.log4j:log4j-core:2.25.2=spotbugs -org.apiguardian:apiguardian-api:1.1.2=latestDepTestCompileClasspath,testCompileClasspath -org.checkerframework:checker-qual:3.33.0=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor -org.codehaus.groovy:groovy-ant:3.0.23=codenarc -org.codehaus.groovy:groovy-docgenerator:3.0.23=codenarc -org.codehaus.groovy:groovy-groovydoc:3.0.23=codenarc -org.codehaus.groovy:groovy-json:3.0.23=codenarc -org.codehaus.groovy:groovy-json:3.0.25=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codehaus.groovy:groovy-templates:3.0.23=codenarc -org.codehaus.groovy:groovy-xml:3.0.23=codenarc -org.codehaus.groovy:groovy:3.0.23=codenarc -org.codehaus.groovy:groovy:3.0.25=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codenarc:CodeNarc:3.7.0=codenarc -org.dom4j:dom4j:2.2.0=spotbugs -org.gmetrics:GMetrics:2.1.0=codenarc -org.hamcrest:hamcrest-core:1.3=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.hamcrest:hamcrest:3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jctools:jctools-core-jdk11:4.0.6=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.jctools:jctools-core:4.0.6=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.jspecify:jspecify:1.0.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-api:5.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-engine:5.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-params:5.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter:5.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-commons:1.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-engine:1.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-launcher:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-runner:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-suite-api:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-suite-commons:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.junit:junit-bom:5.14.0=spotbugs -org.junit:junit-bom:5.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.mockito:mockito-core:4.4.0=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.objenesis:objenesis:3.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.opentest4j:opentest4j:1.3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.ow2.asm:asm-analysis:9.7.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.ow2.asm:asm-analysis:9.9=spotbugs -org.ow2.asm:asm-commons:9.9=spotbugs -org.ow2.asm:asm-commons:9.9.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.ow2.asm:asm-tree:9.9=spotbugs -org.ow2.asm:asm-tree:9.9.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.ow2.asm:asm-util:9.7.1=latestDepTestRuntimeClasspath,testRuntimeClasspath -org.ow2.asm:asm-util:9.9=spotbugs -org.ow2.asm:asm:9.9=spotbugs -org.ow2.asm:asm:9.9.1=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:jcl-over-slf4j:1.7.30=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:jul-to-slf4j:1.7.30=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:log4j-over-slf4j:1.7.30=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:slf4j-api:1.7.30=buildTimeInstrumentationPlugin,compileClasspath,muzzleBootstrap,muzzleTooling,runtimeClasspath -org.slf4j:slf4j-api:1.7.32=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:slf4j-api:2.0.17=spotbugs,spotbugsSlf4j -org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j -org.snakeyaml:snakeyaml-engine:2.9=buildTimeInstrumentationPlugin,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath -org.spockframework:spock-bom:2.4-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.spockframework:spock-core:2.4-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.tabletest:tabletest-junit:1.2.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.tabletest:tabletest-parser:1.2.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.xmlresolver:xmlresolver:5.3.3=spotbugs -empty=spotbugsPlugins diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientDecorator.java b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientDecorator.java index a7596e2f2ea..7bea9731356 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientDecorator.java +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientDecorator.java @@ -7,9 +7,9 @@ import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.StatusLine; -import org.apache.commons.httpclient.URIException; public class CommonsHttpClientDecorator extends HttpClientDecorator { + public static final CharSequence COMMONS_HTTP_CLIENT = UTF8BytesString.create("commons-http-client"); public static final CommonsHttpClientDecorator DECORATE = new CommonsHttpClientDecorator(); @@ -34,16 +34,19 @@ protected String method(final HttpMethod httpMethod) { @Override protected URI url(final HttpMethod httpMethod) throws URISyntaxException { try { - // org.apache.commons.httpclient.URI -> java.net.URI return new URI(httpMethod.getURI().toString()); - } catch (final URIException e) { + } catch (final Exception e) { throw new URISyntaxException("", e.getMessage()); } } @Override - protected HttpMethod sourceUrl(final HttpMethod httpMethod) { - return httpMethod; + protected URI sourceUrl(final HttpMethod httpMethod) { + try { + return new URI(httpMethod.getURI().toString()); + } catch (final Exception e) { + return null; + } } @Override @@ -53,8 +56,8 @@ protected int status(final HttpMethod httpMethod) { } @Override - protected String getRequestHeader(HttpMethod request, String headerName) { - Header header = request.getRequestHeader(headerName); + protected String getRequestHeader(final HttpMethod httpMethod, final String headerName) { + Header header = httpMethod.getRequestHeader(headerName); if (null != header) { return header.getValue(); } @@ -62,8 +65,8 @@ protected String getRequestHeader(HttpMethod request, String headerName) { } @Override - protected String getResponseHeader(HttpMethod response, String headerName) { - Header header = response.getResponseHeader(headerName); + protected String getResponseHeader(final HttpMethod httpMethod, final String headerName) { + Header header = httpMethod.getResponseHeader(headerName); if (null != header) { return header.getValue(); } diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientInstrumentation.java b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientInstrumentation.java index 6a9d07fe749..01b1cab6ca7 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientInstrumentation.java +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/CommonsHttpClientInstrumentation.java @@ -4,16 +4,15 @@ import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; -import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext; +import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.COMMONS_HTTP_CLIENT; import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.DECORATE; import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.HTTP_REQUEST; import static datadog.trace.instrumentation.commonshttpclient.HttpHeadersInjectAdapter.SETTER; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import com.google.auto.service.AutoService; -import datadog.appsec.api.blocking.BlockingException; +import datadog.context.Context; import datadog.trace.agent.tooling.Instrumenter; import datadog.trace.agent.tooling.InstrumenterModule; import datadog.trace.agent.tooling.annotation.AppliesOn; @@ -29,7 +28,7 @@ public class CommonsHttpClientInstrumentation extends InstrumenterModule.Tracing implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { public CommonsHttpClientInstrumentation() { - super("commons-http-client"); + super("commons-http-client", "commons-httpclient-2.0"); } @Override @@ -40,7 +39,8 @@ public String instrumentedType() { @Override public String[] helperClassNames() { return new String[] { - packageName + ".CommonsHttpClientDecorator", packageName + ".HttpHeadersInjectAdapter", + packageName + ".CommonsHttpClientDecorator", + packageName + ".HttpHeadersInjectAdapter", }; } @@ -49,34 +49,30 @@ public void methodAdvice(MethodTransformer transformer) { transformer.applyAdvices( isMethod() .and(named("executeMethod")) - .and(takesArguments(3)) - .and(takesArgument(1, named("org.apache.commons.httpclient.HttpMethod"))), - CommonsHttpClientInstrumentation.class.getName() + "$ExecAdvice", - CommonsHttpClientInstrumentation.class.getName() + "$ContextPropagationAdvice"); + .and( + takesArgument( + 0, named("org.apache.commons.httpclient.HostConfiguration"))) + .and(takesArgument(1, named("org.apache.commons.httpclient.HttpMethod"))) + .and(takesArgument(2, named("org.apache.commons.httpclient.HttpState"))), + CommonsHttpClientInstrumentation.class.getName() + "$ExecuteMethodAdvice", + CommonsHttpClientInstrumentation.class.getName() + "$InjectContextAdvice"); } - public static class ExecAdvice { + public static class ExecuteMethodAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static AgentScope methodEnter(@Advice.Argument(1) final HttpMethod httpMethod) { + final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(HttpClient.class); + if (callDepth > 0) { + return null; + } - try { - final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(HttpClient.class); - if (callDepth > 0) { - return null; - } - - final AgentSpan span = startSpan("commons-http-client", HTTP_REQUEST); - final AgentScope scope = activateSpan(span); + final AgentSpan span = startSpan(COMMONS_HTTP_CLIENT.toString(), HTTP_REQUEST); + final AgentScope scope = activateSpan(span); - DECORATE.afterStart(span); - DECORATE.onRequest(span, httpMethod); + DECORATE.afterStart(span); + DECORATE.onRequest(span, httpMethod); - return scope; - } catch (BlockingException e) { - CallDepthThreadLocalMap.reset(HttpClient.class); - // re-throw blocking exceptions - throw e; - } + return scope; } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) @@ -84,7 +80,6 @@ public static void methodExit( @Advice.Enter final AgentScope scope, @Advice.Argument(1) final HttpMethod httpMethod, @Advice.Thrown final Throwable throwable) { - if (scope == null) { return; } @@ -102,10 +97,10 @@ public static void methodExit( } @AppliesOn(CONTEXT_TRACKING) - public static class ContextPropagationAdvice { + public static class InjectContextAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void methodEnter(@Advice.Argument(1) final HttpMethod httpMethod) { - DECORATE.injectContext(currentContext(), httpMethod, SETTER); + DECORATE.injectContext(Context.current(), httpMethod, SETTER); } } } diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/HttpHeadersInjectAdapter.java b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/HttpHeadersInjectAdapter.java index f35bb0eb8af..88297d95d3c 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/HttpHeadersInjectAdapter.java +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/HttpHeadersInjectAdapter.java @@ -2,7 +2,6 @@ import datadog.context.propagation.CarrierSetter; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethod; @ParametersAreNonnullByDefault @@ -12,6 +11,6 @@ public class HttpHeadersInjectAdapter implements CarrierSetter { @Override public void set(final HttpMethod carrier, final String key, final String value) { - carrier.setRequestHeader(new Header(key, value)); + carrier.setRequestHeader(key, value); } } diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/IastHttpMethodBaseInstrumentation.java b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/IastHttpMethodBaseInstrumentation.java deleted file mode 100644 index fc6f09dfb11..00000000000 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/main/java/datadog/trace/instrumentation/commonshttpclient/IastHttpMethodBaseInstrumentation.java +++ /dev/null @@ -1,61 +0,0 @@ -package datadog.trace.instrumentation.commonshttpclient; - -import static net.bytebuddy.matcher.ElementMatchers.isConstructor; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; - -import com.google.auto.service.AutoService; -import datadog.trace.agent.tooling.Instrumenter; -import datadog.trace.agent.tooling.InstrumenterModule; -import datadog.trace.agent.tooling.bytebuddy.iast.TaintableVisitor; -import datadog.trace.api.iast.InstrumentationBridge; -import datadog.trace.api.iast.Propagation; -import datadog.trace.api.iast.propagation.PropagationModule; -import net.bytebuddy.asm.Advice; - -@AutoService(InstrumenterModule.class) -public class IastHttpMethodBaseInstrumentation extends InstrumenterModule.Iast - implements Instrumenter.ForSingleType, - Instrumenter.HasTypeAdvice, - Instrumenter.HasMethodAdvice { - - private final String className = IastHttpMethodBaseInstrumentation.class.getName(); - - public IastHttpMethodBaseInstrumentation() { - super("commons-http-client"); - } - - @Override - public String instrumentedType() { - return "org.apache.commons.httpclient.HttpMethodBase"; - } - - @Override - public String muzzleDirective() { - return "commons-http-client-x"; - } - - @Override - public void typeAdvice(TypeTransformer transformer) { - transformer.applyAdvice(new TaintableVisitor(instrumentedType())); - } - - @Override - public void methodAdvice(MethodTransformer transformer) { - transformer.applyAdvice( - isConstructor().and(takesArguments(1)).and(takesArgument(0, String.class)), - className + "$CtorAdvice"); - } - - public static class CtorAdvice { - @Advice.OnMethodExit(suppress = Throwable.class) - @Propagation - public static void afterCtor( - @Advice.This final Object self, @Advice.Argument(0) final Object argument) { - final PropagationModule module = InstrumentationBridge.PROPAGATION; - if (module != null) { - module.taintObjectIfTainted(self, argument); - } - } - } -} diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/CommonsHttpClientTest.groovy b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/CommonsHttpClientTest.groovy index 23ded9aa8b0..37bd9101561 100644 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/CommonsHttpClientTest.groovy +++ b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/CommonsHttpClientTest.groovy @@ -1,6 +1,5 @@ import datadog.trace.agent.test.base.HttpClientTest import datadog.trace.agent.test.naming.TestingGenericHttpNamingConventions -import datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator import org.apache.commons.httpclient.HttpClient import org.apache.commons.httpclient.HttpMethod import org.apache.commons.httpclient.methods.DeleteMethod @@ -9,75 +8,77 @@ import org.apache.commons.httpclient.methods.HeadMethod import org.apache.commons.httpclient.methods.OptionsMethod import org.apache.commons.httpclient.methods.PostMethod import org.apache.commons.httpclient.methods.PutMethod -import org.apache.commons.httpclient.methods.TraceMethod import spock.lang.Shared import spock.lang.Timeout -@Timeout(5) abstract class CommonsHttpClientTest extends HttpClientTest { @Shared - HttpClient client = new HttpClient() + def client = new HttpClient() def setupSpec() { - client.setConnectionTimeout(CONNECT_TIMEOUT_MS) - client.setTimeout(READ_TIMEOUT_MS) + client.httpConnectionManager.params.connectionTimeout = CONNECT_TIMEOUT_MS + client.httpConnectionManager.params.soTimeout = READ_TIMEOUT_MS } @Override - int doRequest(String method, URI uri, Map headers, String body, Closure callback) { - HttpMethod httpMethod + CharSequence component() { + return "commons-http-client" + } - switch (method) { - case "GET": - httpMethod = new GetMethod(uri.toString()) - break - case "PUT": - httpMethod = new PutMethod(uri.toString()) - break - case "POST": - httpMethod = new PostMethod(uri.toString()) - break - case "HEAD": - httpMethod = new HeadMethod(uri.toString()) - break - case "DELETE": - httpMethod = new DeleteMethod(uri.toString()) - break - case "OPTIONS": - httpMethod = new OptionsMethod(uri.toString()) - break - case "TRACE": - httpMethod = new TraceMethod(uri.toString()) - break - default: - throw new RuntimeException("Unsupported method: " + method) + @Override + int doRequest(String method, URI uri, Map headers, String body, Closure callback) { + def httpMethod = createHttpMethod(method, uri) + headers.each { key, value -> + httpMethod.setRequestHeader(key, value) + } + if (body && httpMethod instanceof PostMethod) { + ((PostMethod) httpMethod).setRequestBody(body) + } else if (body && httpMethod instanceof PutMethod) { + ((PutMethod) httpMethod).setRequestBody(body) } - headers.each { httpMethod.setRequestHeader(it.key, it.value) } + client.executeMethod(httpMethod) + callback?.call() - try { - client.executeMethod(httpMethod) - callback?.call() - return httpMethod.getStatusCode() - } finally { - httpMethod.releaseConnection() - } + def statusCode = httpMethod.getStatusCode() + httpMethod.releaseConnection() + return statusCode } @Override - CharSequence component() { - return CommonsHttpClientDecorator.DECORATE.component() + boolean testRedirects() { + true } @Override - boolean testRedirects() { - // Generates 4 spans + boolean testRemoteConnection() { false } + + static HttpMethod createHttpMethod(String method, URI uri) { + switch (method) { + case "GET": + return new GetMethod(uri.toString()) + case "POST": + return new PostMethod(uri.toString()) + case "PUT": + return new PutMethod(uri.toString()) + case "DELETE": + return new DeleteMethod(uri.toString()) + case "HEAD": + return new HeadMethod(uri.toString()) + case "OPTIONS": + return new OptionsMethod(uri.toString()) + default: + throw new IllegalArgumentException("Unsupported HTTP method: " + method) + } + } } +@Timeout(5) class CommonsHttpClientV0ForkedTest extends CommonsHttpClientTest implements TestingGenericHttpNamingConventions.ClientV0 { } +@Timeout(5) class CommonsHttpClientV1ForkedTest extends CommonsHttpClientTest implements TestingGenericHttpNamingConventions.ClientV1 { } diff --git a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/IastCommonsHttpClientInstrumentationTest.groovy b/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/IastCommonsHttpClientInstrumentationTest.groovy deleted file mode 100644 index 28c5b56ad46..00000000000 --- a/dd-java-agent/instrumentation/commons-httpclient-2.0/src/test/groovy/IastCommonsHttpClientInstrumentationTest.groovy +++ /dev/null @@ -1,62 +0,0 @@ -import datadog.trace.agent.test.InstrumentationSpecification -import datadog.trace.api.iast.InstrumentationBridge -import datadog.trace.api.iast.propagation.PropagationModule -import datadog.trace.api.iast.sink.SsrfModule -import org.apache.commons.httpclient.HttpClient -import org.apache.commons.httpclient.methods.GetMethod -import spock.lang.AutoCleanup -import spock.lang.Shared - -import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer - -class IastCommonsHttpClientInstrumentationTest extends InstrumentationSpecification { - - @Override - protected void configurePreAgent() { - injectSysConfig('dd.iast.enabled', 'true') - } - - @AutoCleanup - @Shared - def server = httpServer { - handlers { - prefix('/') { - String msg = "Hello." - response.status(200).send(msg) - } - } - } - - @Shared - Map tainteds = new IdentityHashMap<>() - - void setup() { - tainteds.clear() - mockPropagation() - } - - void 'test ssrf'() { - given: - final url = server.address.toString() - tainteds.put(url, null) - final ssrf = Mock(SsrfModule) - InstrumentationBridge.registerIastModule(ssrf) - - when: - new HttpClient().executeMethod(new GetMethod(url)) - - then: - 1 * ssrf.onURLConnection({ value -> tainteds.containsKey(value) }) - } - - private void mockPropagation() { - final propagation = Mock(PropagationModule) { - taintObjectIfTainted(_, _) >> { - if (tainteds.containsKey(it[1])) { - tainteds.put(it[0], null) - } - } - } - InstrumentationBridge.registerIastModule(propagation) - } -} diff --git a/metadata/supported-configurations.json b/metadata/supported-configurations.json index 733f3736cbb..65d90eb84b9 100644 --- a/metadata/supported-configurations.json +++ b/metadata/supported-configurations.json @@ -10185,6 +10185,14 @@ "aliases": [] } ], + "DD_TRACE_SPARKJAVA_2_3_ENABLED": [ + { + "version": "A", + "type": "boolean", + "default": "false", + "aliases": ["DD_TRACE_INTEGRATION_SPARKJAVA_2_3_ENABLED", "DD_INTEGRATION_SPARKJAVA_2_3_ENABLED"] + } + ], "DD_TRACE_SPARKJAVA_2_4_ENABLED": [ { "version": "A", @@ -10193,6 +10201,22 @@ "aliases": ["DD_TRACE_INTEGRATION_SPARKJAVA_2_4_ENABLED", "DD_INTEGRATION_SPARKJAVA_2_4_ENABLED"] } ], + "DD_TRACE_SPARKJAVA_ANALYTICS_ENABLED": [ + { + "version": "A", + "type": "boolean", + "default": "false", + "aliases": ["DD_SPARKJAVA_ANALYTICS_ENABLED"] + } + ], + "DD_TRACE_SPARKJAVA_ANALYTICS_SAMPLE_RATE": [ + { + "version": "A", + "type": "decimal", + "default": "1.0", + "aliases": ["DD_SPARKJAVA_ANALYTICS_SAMPLE_RATE"] + } + ], "DD_TRACE_SPARKJAVA_ENABLED": [ { "version": "A",