Skip to content

Commit a71957d

Browse files
committed
added comments and attributions
1 parent cf3e176 commit a71957d

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

instrumentation/aws-sdk/src/main/java/software/amazon/opentelemetry/javaagent/instrumentation/awssdk_v1_11/AwsExperimentalAttributes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@
1515

1616
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11;
1717

18+
/*
19+
* Copyright The OpenTelemetry Authors
20+
* SPDX-License-Identifier: Apache-2.0
21+
*
22+
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
23+
*/
24+
1825
import static io.opentelemetry.api.common.AttributeKey.stringKey;
1926

2027
import io.opentelemetry.api.common.AttributeKey;
2128

2229
final class AwsExperimentalAttributes {
2330

31+
// 2025-07-22: Amazon addition
2432
static final AttributeKey<String> AWS_STREAM_ARN = stringKey("aws.stream.arn");
2533
static final AttributeKey<String> AWS_TABLE_ARN = stringKey("aws.table.arn");
2634
static final AttributeKey<String> AWS_AGENT_ID = stringKey("aws.bedrock.agent.id");
@@ -56,5 +64,7 @@ final class AwsExperimentalAttributes {
5664
stringKey("aws.lambda.resource_mapping.id");
5765
static final AttributeKey<String> AWS_AUTH_ACCESS_KEY = stringKey("aws.auth.account.access_key");
5866

67+
// End of Amazon addition
68+
5969
private AwsExperimentalAttributes() {}
6070
}

instrumentation/aws-sdk/src/main/java/software/amazon/opentelemetry/javaagent/instrumentation/awssdk_v1_11/AwsSdkExperimentalAttributesExtractor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11;
1717

18+
/*
19+
* Copyright The OpenTelemetry Authors
20+
* SPDX-License-Identifier: Apache-2.0
21+
*
22+
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
23+
*/
24+
1825
import static software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AwsExperimentalAttributes.AWS_AGENT_ID;
1926
import static software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AwsExperimentalAttributes.AWS_AUTH_ACCESS_KEY;
2027
import static software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AwsExperimentalAttributes.AWS_BEDROCK_RUNTIME_MODEL_ID;
@@ -52,6 +59,7 @@
5259

5360
class AwsSdkExperimentalAttributesExtractor
5461
implements AttributesExtractor<Request<?>, Response<?>> {
62+
// 2025-07-22: Amazon addition
5563
private static final String BEDROCK_SERVICE = "AmazonBedrock";
5664
private static final String BEDROCK_AGENT_SERVICE = "AWSBedrockAgent";
5765
private static final String BEDROCK_AGENT_RUNTIME_SERVICE = "AWSBedrockAgentRuntime";
@@ -220,6 +228,8 @@ private static boolean isBedrockService(String serviceName) {
220228
|| serviceName.equals(BEDROCK_RUNTIME_SERVICE);
221229
}
222230

231+
// End of Amazon addition
232+
223233
private static void setAttribute(
224234
AttributesBuilder attributes,
225235
AttributeKey<String> key,

instrumentation/aws-sdk/src/main/java/software/amazon/opentelemetry/javaagent/instrumentation/awssdk_v1_11/RequestAccess.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11;
1717

18+
/*
19+
* Copyright The OpenTelemetry Authors
20+
* SPDX-License-Identifier: Apache-2.0
21+
*
22+
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
23+
*/
24+
1825
import java.lang.invoke.MethodHandle;
1926
import java.lang.invoke.MethodHandles;
2027
import java.lang.invoke.MethodType;
@@ -36,6 +43,7 @@ protected RequestAccess computeValue(Class<?> type) {
3643
}
3744
};
3845

46+
// 2025-07-22: Amazon addition
3947
@Nullable
4048
private static BedrockJsonParser.LlmJson parseTargetBody(ByteBuffer buffer) {
4149
try {
@@ -384,6 +392,8 @@ static String getModelId(Object request) {
384392
return invokeOrNull(access.getModelId, request);
385393
}
386394

395+
// End of Amazon addition
396+
387397
@Nullable
388398
private static String invokeOrNull(@Nullable MethodHandle method, Object obj) {
389399
if (method == null) {
@@ -396,6 +406,7 @@ private static String invokeOrNull(@Nullable MethodHandle method, Object obj) {
396406
}
397407
}
398408

409+
// 2025-07-22: Amazon addition
399410
@Nullable
400411
private static <T> T invokeOrNullGeneric(
401412
@Nullable MethodHandle method, Object obj, Class<T> returnType) {
@@ -439,17 +450,44 @@ private RequestAccess(Class<?> clz) {
439450
getLambdaResourceId = findAccessorOrNull(clz, "getUUID", String.class);
440451
}
441452

453+
/**
454+
* Uses Java reflection to find a getter method on a class and create a MethodHandle for it.
455+
*
456+
* @param clz The class to search for the method
457+
* @param methodName The name of the getter method (e.g., "getStreamARN")
458+
* @param returnType The expected return type of the method
459+
* @return A MethodHandle for the method, or null if not found
460+
* <p>Example: For class PutRecordRequest with method "getStreamARN":
461+
* findAccessorOrNull(PutRecordRequest.class, "getStreamARN", String.class) Creates a method
462+
* handle that can invoke getStreamARN() on PutRecordRequest instances
463+
*/
442464
@Nullable
443465
private static MethodHandle findAccessorOrNull(
444466
Class<?> clz, String methodName, Class<?> returnType) {
445467
try {
468+
// Uses MethodHandles.publicLookup() to get access to public methods
469+
// findVirtual finds an instance method with the given name and type
470+
// methodType creates a method type with no parameters and the specified return type
446471
return MethodHandles.publicLookup()
447472
.findVirtual(clz, methodName, MethodType.methodType(returnType));
448473
} catch (Throwable t) {
474+
// Returns null if method doesn't exist or can't be accessed
449475
return null;
450476
}
451477
}
452478

479+
/**
480+
* Uses reflection to navigate through nested method calls and extract a String value. Unlike
481+
* using method handles, this supports chained method calls where each method might return a
482+
* different type of object.
483+
*
484+
* @param obj The initial object to start method calls from
485+
* @param methodNames Variable list of method names to call in sequence
486+
* @return The final String value, or null if any method in the chain fails or returns null
487+
* <p>Example: For Lambda ARN: findNestedAccessorOrNull(request, "getConfiguration",
488+
* "getFunctionArn") - First calls request.getConfiguration() to get a Configuration object,
489+
* then calls configuration.getFunctionArn() to get the ARN string
490+
*/
453491
@Nullable
454492
private static String findNestedAccessorOrNull(Object obj, String... methodNames) {
455493
Object current = obj;
@@ -466,4 +504,5 @@ private static String findNestedAccessorOrNull(Object obj, String... methodNames
466504
}
467505
return (current instanceof String) ? (String) current : null;
468506
}
507+
// End of Amazon addition
469508
}

instrumentation/aws-sdk/src/test/groovy/software/amazon/opentelemetry/javaagent/instrumentation/awssdk_v1_11/BedrockJsonParserTest.groovy

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11
217

318
import spock.lang.Specification
419

5-
/*
6-
* This is a new class created during ADOT git patching.
7-
*/
820
class BedrockJsonParserTest extends Specification {
921
def "should parse simple JSON object"() {
1022
given:

0 commit comments

Comments
 (0)