-
Notifications
You must be signed in to change notification settings - Fork 64
Base of AWS SDK v1.11 SPI Implementation #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2fec3f1
Added base v1.11 implementation and updated README
anahatAWS 609e6b1
updated documentation for AdotAwsSdkClientInstrumentation
anahatAWS 1d7fb87
added upstream code reference
anahatAWS 4217429
updated documentation and added references
anahatAWS 4a367c2
added unit tests
anahatAWS 5966e8c
added documentation and updated unit tests
anahatAWS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...opentelemetry/javaagent/instrumentation/awssdk_v1_11/AdotAwsSdkClientInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.*; | ||
|
||
import com.amazonaws.handlers.RequestHandler2; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import java.util.List; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class AdotAwsSdkClientInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
// AmazonWebServiceClient is the base interface for all AWS SDK clients. | ||
// Type matching against it ensures our interceptor is injected as soon as any AWS SDK client is | ||
// initialized. | ||
return named("com.amazonaws.AmazonWebServiceClient") | ||
.and(declaresField(named("requestHandler2s"))); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor(), | ||
AdotAwsSdkClientInstrumentation.class.getName() + "$AdotAwsSdkClientAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class AdotAwsSdkClientAdvice { | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void addHandler( | ||
pxaws marked this conversation as resolved.
Show resolved
Hide resolved
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Advice.FieldValue(value = "requestHandler2s", readOnly = false) | ||
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List<RequestHandler2> handlers) { | ||
|
||
if (handlers == null) { | ||
return; | ||
} | ||
|
||
boolean hasOtelHandler = false; | ||
boolean hasAdotHandler = false; | ||
|
||
// Checks if aws-sdk spans are enabled | ||
for (RequestHandler2 handler : handlers) { | ||
if (handler | ||
.toString() | ||
.contains( | ||
"io.opentelemetry.javaagent.instrumentation.awssdk.v1_11.TracingRequestHandler")) { | ||
hasOtelHandler = true; | ||
} | ||
if (handler instanceof AdotAwsSdkTracingRequestHandler) { | ||
hasAdotHandler = true; | ||
break; | ||
} | ||
} | ||
|
||
// Only adds our handler if aws-sdk spans are enabled. This also ensures upstream | ||
// instrumentation is applied first. | ||
if (hasOtelHandler && !hasAdotHandler) { | ||
handlers.add(new AdotAwsSdkTracingRequestHandler()); | ||
} | ||
} | ||
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...opentelemetry/javaagent/instrumentation/awssdk_v1_11/AdotAwsSdkInstrumentationModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11; | ||
|
||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class AdotAwsSdkInstrumentationModule extends InstrumentationModule { | ||
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public AdotAwsSdkInstrumentationModule() { | ||
super("aws-sdk-adot", "aws-sdk-1.11-adot"); | ||
} | ||
|
||
@Override | ||
public int order() { | ||
// Ensure this runs after OTel (> 0) | ||
return 99; | ||
} | ||
|
||
@Override | ||
public List<String> getAdditionalHelperClassNames() { | ||
return Arrays.asList( | ||
"software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AdotAwsSdkTracingRequestHandler"); | ||
} | ||
|
||
@Override | ||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed("com.amazonaws.AmazonWebServiceClient"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return Collections.singletonList(new AdotAwsSdkClientInstrumentation()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...opentelemetry/javaagent/instrumentation/awssdk_v1_11/AdotAwsSdkTracingRequestHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11; | ||
|
||
import com.amazonaws.Request; | ||
import com.amazonaws.handlers.HandlerAfterAttemptContext; | ||
import com.amazonaws.handlers.RequestHandler2; | ||
|
||
public class AdotAwsSdkTracingRequestHandler extends RequestHandler2 { | ||
|
||
public AdotAwsSdkTracingRequestHandler() {} | ||
|
||
/** | ||
* This is the latest point we can obtain the Sdk Request after it is modified by the upstream | ||
* TracingInterceptor. It ensures upstream handles the request and applies its changes first. | ||
* | ||
* <p>Upstream's last Sdk Request modification: @see <a | ||
* href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java#L58">reference</a> | ||
*/ | ||
@Override | ||
public void beforeRequest(Request<?> request) {} | ||
|
||
/** | ||
* This is the latest point to access the sdk response before the span closes in the upstream | ||
* afterResponse/afterError methods. This ensures we capture attributes from the final, fully | ||
* modified response after all upstream interceptors have processed it. | ||
* | ||
* <p>Upstream's last Sdk Response modification before span closure: @see <a | ||
* href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java#L116">reference</a> | ||
* | ||
* @see <a | ||
* href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java#L131">reference</a> | ||
*/ | ||
@Override | ||
public void afterAttempt(HandlerAfterAttemptContext context) {} | ||
} |
3 changes: 2 additions & 1 deletion
3
...A-INF/services/io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v2_2.AdotAwsSdkInstrumentationModule | ||
software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v2_2.AdotAwsSdkInstrumentationModule | ||
software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AdotAwsSdkInstrumentationModule |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.