From 43a17471de02803f11c72f8111a2da52fbe21c5f Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Sun, 5 Jan 2025 19:44:13 +0000 Subject: [PATCH 1/2] Support configuring a different namespace in AWS-SDK module --- .../aws/v0/AWSHttpClientInstrumentation.java | 7 ++++++- .../instrumentation/aws/v0/AwsSdkModule.java | 20 ++++++++++++------- .../HandlerChainFactoryInstrumentation.java | 7 ++++++- .../v0/RequestExecutorInstrumentation.java | 7 ++++++- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AWSHttpClientInstrumentation.java b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AWSHttpClientInstrumentation.java index c31d951d31f..c92b66c68e0 100644 --- a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AWSHttpClientInstrumentation.java +++ b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AWSHttpClientInstrumentation.java @@ -22,10 +22,15 @@ */ public class AWSHttpClientInstrumentation implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { + private final String namespace; + + public AWSHttpClientInstrumentation(String namespace) { + this.namespace = namespace; + } @Override public String instrumentedType() { - return "com.amazonaws.http.AmazonHttpClient"; + return namespace + ".http.AmazonHttpClient"; } @Override diff --git a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkModule.java b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkModule.java index b237a8b70b0..aa3d81da4a8 100644 --- a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkModule.java +++ b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkModule.java @@ -9,10 +9,16 @@ /** Groups the instrumentations for AWS SDK 1.11.0+. */ @AutoService(InstrumenterModule.class) -public final class AwsSdkModule extends InstrumenterModule.Tracing { +public class AwsSdkModule extends InstrumenterModule.Tracing { + private final String namespace; public AwsSdkModule() { - super("aws-sdk"); + this("com.amazonaws", "aws-sdk"); + } + + protected AwsSdkModule(String namespace, String instrumentationName) { + super(instrumentationName); + this.namespace = namespace; } @Override @@ -30,9 +36,9 @@ public String[] helperClassNames() { @Override public Map contextStore() { Map map = new java.util.HashMap<>(); - map.put("com.amazonaws.services.sqs.model.ReceiveMessageResult", "java.lang.String"); + map.put(namespace + ".services.sqs.model.ReceiveMessageResult", "java.lang.String"); map.put( - "com.amazonaws.AmazonWebServiceRequest", + namespace + ".AmazonWebServiceRequest", "datadog.trace.bootstrap.instrumentation.api.AgentSpan"); return map; } @@ -40,8 +46,8 @@ public Map contextStore() { @Override public List typeInstrumentations() { return Arrays.asList( - new AWSHttpClientInstrumentation(), - new RequestExecutorInstrumentation(), - new HandlerChainFactoryInstrumentation()); + new AWSHttpClientInstrumentation(namespace), + new RequestExecutorInstrumentation(namespace), + new HandlerChainFactoryInstrumentation(namespace)); } } diff --git a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/HandlerChainFactoryInstrumentation.java b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/HandlerChainFactoryInstrumentation.java index b7327f42eb5..07dfa82382d 100644 --- a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/HandlerChainFactoryInstrumentation.java +++ b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/HandlerChainFactoryInstrumentation.java @@ -15,10 +15,15 @@ */ public final class HandlerChainFactoryInstrumentation implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { + private final String namespace; + + public HandlerChainFactoryInstrumentation(String namespace) { + this.namespace = namespace; + } @Override public String instrumentedType() { - return "com.amazonaws.handlers.HandlerChainFactory"; + return namespace + ".handlers.HandlerChainFactory"; } @Override diff --git a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestExecutorInstrumentation.java b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestExecutorInstrumentation.java index efb70fc381a..6b93dbe2d82 100644 --- a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestExecutorInstrumentation.java +++ b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestExecutorInstrumentation.java @@ -19,10 +19,15 @@ */ public final class RequestExecutorInstrumentation implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { + private final String namespace; + + public RequestExecutorInstrumentation(String namespace) { + this.namespace = namespace; + } @Override public String instrumentedType() { - return "com.amazonaws.http.AmazonHttpClient$RequestExecutor"; + return namespace + ".http.AmazonHttpClient$RequestExecutor"; } @Override From ae0e15b7122dde824b11d0c447b64cc71e359202 Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Sun, 5 Jan 2025 19:59:28 +0000 Subject: [PATCH 2/2] Instrument EMR's relocated AWS SDK --- .../instrumentation/aws/v0/EmrSdkModule.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/EmrSdkModule.java diff --git a/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/EmrSdkModule.java b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/EmrSdkModule.java new file mode 100644 index 00000000000..042f71f2cdb --- /dev/null +++ b/dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/EmrSdkModule.java @@ -0,0 +1,25 @@ +package datadog.trace.instrumentation.aws.v0; + +import static java.util.Collections.singletonMap; + +import com.google.auto.service.AutoService; +import datadog.trace.agent.tooling.InstrumenterModule; +import java.util.Map; + +/** Repackaged AWS SDK instrumentations for Amazon EMR. */ +@AutoService(InstrumenterModule.class) +public class EmrSdkModule extends AwsSdkModule { + public EmrSdkModule() { + super("com.amazon.ws.emr.hadoop.fs.shaded.com.amazonaws", "emr-aws-sdk"); + } + + @Override + public String muzzleDirective() { + return "emr-aws-sdk"; + } + + @Override + public Map adviceShading() { + return singletonMap("com.amazonaws", "com.amazon.ws.emr.hadoop.fs.shaded.com.amazonaws"); + } +}