Skip to content

Commit dbbb26e

Browse files
authored
Merge branch 'main' into dependabot/gradle/org.testcontainers-mysql-1.20.3
2 parents 637c0f7 + 25b2cd8 commit dbbb26e

File tree

12 files changed

+533
-4275
lines changed

12 files changed

+533
-4275
lines changed

.github/actions/patch-dependencies/action.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Patch dependencies"
22
description: |
33
Patches direct dependencies of this project leveraging maven local to publish the results.
44
5-
This workflow supports patching opentelemetry-java and opentelemetry-java-instrumentation repositories by executing
5+
This workflow supports patching opentelemetry-java and opentelemetry-java-contrib repositories by executing
66
the `patch.sh` script that will try to patch those repositories and after that will optionally test and then publish
77
the artifacts to maven local.
88
To add a patch you have to add a file in the `.github/patches/` directory with the name of the repository that must
@@ -49,9 +49,6 @@ runs:
4949
if [[ -f .github/patches/opentelemetry-java.patch ]]; then
5050
echo 'patch_otel_java=true' >> $GITHUB_ENV
5151
fi
52-
if [[ -f .github/patches/opentelemetry-java-instrumentation.patch ]]; then
53-
echo 'patch_otel_java_instrumentation=true' >> $GITHUB_ENV
54-
fi
5552
if [[ -f .github/patches/opentelemetry-java-contrib.patch ]]; then
5653
echo 'patch_otel_java_contrib=true' >> $GITHUB_ENV
5754
fi
@@ -60,7 +57,6 @@ runs:
6057
- name: Clone and patch repositories
6158
run: .github/scripts/patch.sh
6259
if: ${{ env.patch_otel_java == 'true' ||
63-
env.patch_otel_java_instrumentation == 'true' ||
6460
env.patch_otel_java_contrib == 'true' }}
6561
shell: bash
6662

@@ -101,22 +97,3 @@ runs:
10197
run: rm -rf opentelemetry-java-contrib
10298
if: ${{ env.patch_otel_java_contrib == 'true' }}
10399
shell: bash
104-
105-
- name: Build opentelemetry-java-instrumentation with tests
106-
uses: gradle/gradle-build-action@v2
107-
if: ${{ env.patch_otel_java_instrumentation == 'true' && inputs.run_tests != 'false' }}
108-
with:
109-
arguments: check -x spotlessCheck publishToMavenLocal
110-
build-root-directory: opentelemetry-java-instrumentation
111-
112-
- name: Build opentelemetry java instrumentation
113-
uses: gradle/gradle-build-action@v2
114-
if: ${{ env.patch_otel_java_instrumentation == 'true' && inputs.run_tests == 'false' }}
115-
with:
116-
arguments: publishToMavenLocal
117-
build-root-directory: opentelemetry-java-instrumentation
118-
119-
- name: cleanup opentelmetry-java-instrumentation
120-
run: rm -rf opentelemetry-java-instrumentation
121-
if: ${{ env.patch_otel_java_instrumentation == 'true' }}
122-
shell: bash

.github/patches/opentelemetry-java-instrumentation.patch

Lines changed: 0 additions & 4193 deletions
This file was deleted.

.github/scripts/patch.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set -x -e -u
66
# This is used so that we can properly clone the upstream repositories.
77
# This file should define the following variables:
88
# OTEL_JAVA_VERSION. Tag of the opentelemetry-java repository to use. E.g.: JAVA_OTEL_JAVA_VERSION=v1.21.0
9-
# OTEL_JAVA_INSTRUMENTATION_VERSION. Tag of the opentelemetry-java-instrumentation repository to use, e.g.: OTEL_JAVA_INSTRUMENTATION_VERSION=v1.21.0
109
# OTEL_JAVA_CONTRIB_VERSION. Tag of the opentelemetry-java-contrib repository. E.g.: OTEL_JAVA_CONTRIB_VERSION=v1.21.0
1110
# This script will fail if a variable that is supposed to exist is referenced.
1211

@@ -45,16 +44,3 @@ if [[ -f "$OTEL_JAVA_CONTRIB_PATCH" ]]; then
4544
else
4645
echo "Skipping patching opentelemetry-java-contrib"
4746
fi
48-
49-
50-
OTEL_JAVA_INSTRUMENTATION_PATCH=".github/patches/opentelemetry-java-instrumentation.patch"
51-
if [[ -f "$OTEL_JAVA_INSTRUMENTATION_PATCH" ]]; then
52-
git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.git
53-
cd opentelemetry-java-instrumentation
54-
git checkout ${OTEL_JAVA_INSTRUMENTATION_VERSION} -b tag-${OTEL_JAVA_INSTRUMENTATION_VERSION}
55-
patch -p1 < "../${OTEL_JAVA_INSTRUMENTATION_PATCH}"
56-
git commit -a -m "ADOT Patch release"
57-
cd -
58-
else
59-
echo "Skipping patching opentelemetry-java-instrumentation"
60-
fi

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li
2727
val testSnapshots = rootProject.findProperty("testUpstreamSnapshots") == "true"
2828

2929
// This is the version of the upstream instrumentation BOM
30-
val otelVersion = "2.11.0-adot1"
30+
val otelVersion = "2.11.0"
3131
val otelSnapshotVersion = "2.12.0"
3232
val otelAlphaVersion = if (!testSnapshots) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT"
3333
val otelJavaAgentVersion = if (!testSnapshots) otelVersion else "$otelSnapshotVersion-SNAPSHOT"

instrumentation/aws-sdk/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,32 @@ _Class Functionalities:_
152152

153153
### Commands for Running Groovy Tests
154154

155-
To run the BedrockJsonParserTest for aws-sdk v1.11:
155+
#### aws-sdk v1.11
156+
To run the `BedrockJsonParserTest`:
156157
````
157158
./gradlew :instrumentation:aws-sdk:test --tests "software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.BedrockJsonParserTest"
158159
````
159160

160-
To run the BedrockJsonParserTest for aws-sdk v2.2:
161+
#### aws-sdk v2.2
162+
To run the `BedrockJsonParserTest`:
161163
````
162164
./gradlew :instrumentation:aws-sdk:test --tests "software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v2_2.BedrockJsonParserTest"
163-
````
165+
````
166+
167+
### Commands for Running Java Tests
168+
169+
#### aws-sdk v1.11
170+
To run the `AwsSdkExperimentalAttributesInjectionTest`:
171+
````
172+
./gradlew :instrumentation:aws-sdk:test --tests "software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AwsSdkExperimentalAttributesInjectionTest"
173+
````
174+
175+
To run the `AdotAwsSdkClientAdviceTest`:
176+
````
177+
./gradlew :instrumentation:aws-sdk:test --tests "software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11.AdotAwsSdkClientAdviceTest"
178+
````
179+
180+
#### aws-sdk v2.2
181+
To run the `AwsSdkExperimentalAttributesInjectionTest`:
182+
````
183+
./gradlew :instrumentation:aws-sdk:test --tests "software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v2_2.AwsSdkExperimentalAttributesInjectionTest"

instrumentation/aws-sdk/build.gradle.kts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ dependencies {
2828
compileOnly("com.amazonaws:aws-java-sdk-core:1.11.0")
2929
compileOnly("software.amazon.awssdk:aws-core:2.2.0")
3030
compileOnly("software.amazon.awssdk:aws-json-protocol:2.2.0")
31-
3231
compileOnly("net.bytebuddy:byte-buddy")
33-
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
3432

3533
testImplementation("com.google.guava:guava")
36-
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common")
37-
38-
testImplementation("com.amazonaws:aws-java-sdk-core:1.11.0")
39-
testImplementation("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api")
4034
testImplementation("org.mockito:mockito-core:5.14.2")
41-
testImplementation("com.google.guava:guava")
4235
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common")
36+
testImplementation("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api")
37+
38+
testImplementation("software.amazon.awssdk:aws-core:2.2.0")
39+
testImplementation("com.amazonaws:aws-java-sdk-lambda:1.11.678")
40+
testImplementation("com.amazonaws:aws-java-sdk-kinesis:1.11.106")
41+
testImplementation("com.amazonaws:aws-java-sdk-sns:1.11.106")
42+
testImplementation("com.amazonaws:aws-java-sdk-stepfunctions:1.11.230")
43+
testImplementation("com.amazonaws:aws-java-sdk-secretsmanager:1.11.309")
4344
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
16+
package software.amazon.opentelemetry.javaagent.instrumentation.awssdk_v1_11;
17+
18+
import static org.mockito.ArgumentMatchers.eq;
19+
import static org.mockito.Mockito.*;
20+
21+
import com.amazonaws.Request;
22+
import com.amazonaws.Response;
23+
import com.amazonaws.auth.AWSCredentials;
24+
import com.amazonaws.handlers.HandlerContextKey;
25+
import com.amazonaws.services.kinesis.model.PutRecordRequest;
26+
import com.amazonaws.services.lambda.model.CreateFunctionRequest;
27+
import com.amazonaws.services.lambda.model.FunctionConfiguration;
28+
import com.amazonaws.services.lambda.model.GetFunctionResult;
29+
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
30+
import com.amazonaws.services.sns.model.PublishRequest;
31+
import com.amazonaws.services.stepfunctions.model.StartExecutionRequest;
32+
import io.opentelemetry.api.common.AttributesBuilder;
33+
import io.opentelemetry.context.Context;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
36+
37+
/*
38+
* NOTE: V1.11 attribute extraction is difficult to test in unit tests due to reflection-based
39+
* method access via MethodHandle. Many tests here only verify that the extractor correctly
40+
* identifies different AWS service types rather than actual attribute extraction. However, these
41+
* attributes are comprehensively tested in the contract tests which provide end-to-end validation
42+
* of the reflection-based extraction logic. The contract tests cover most V1.11 attributes
43+
* including all Bedrock Gen AI attributes.
44+
*/
45+
class AwsSdkExperimentalAttributesInjectionTest {
46+
47+
private AwsSdkExperimentalAttributesExtractor extractor;
48+
private AttributesBuilder attributes;
49+
private Request<?> mockRequest;
50+
private Response<?> mockResponse;
51+
private static final HandlerContextKey<AWSCredentials> AWS_CREDENTIALS =
52+
new HandlerContextKey<>("AWSCredentials");
53+
54+
@BeforeEach
55+
void setUp() {
56+
extractor = new AwsSdkExperimentalAttributesExtractor();
57+
attributes = mock(AttributesBuilder.class);
58+
mockRequest = mock(Request.class);
59+
mockResponse = mock(Response.class);
60+
}
61+
62+
@Test
63+
void testSnsExperimentalAttributes() {
64+
PublishRequest snsRequest = mock(PublishRequest.class);
65+
when(mockRequest.getServiceName()).thenReturn("AmazonSNS");
66+
when(mockRequest.getOriginalRequest()).thenReturn(snsRequest);
67+
when(snsRequest.getTopicArn()).thenReturn("arn:aws:sns:region:account:topic/test");
68+
69+
extractor.onStart(attributes, Context.current(), mockRequest);
70+
71+
verify(attributes)
72+
.put(
73+
eq(AwsExperimentalAttributes.AWS_SNS_TOPIC_ARN),
74+
eq("arn:aws:sns:region:account:topic/test"));
75+
}
76+
77+
@Test
78+
void testKinesisExperimentalAttributes() {
79+
PutRecordRequest kinesisRequest = mock(PutRecordRequest.class);
80+
when(mockRequest.getServiceName()).thenReturn("AmazonKinesis");
81+
when(mockRequest.getOriginalRequest()).thenReturn(kinesisRequest);
82+
when(kinesisRequest.getStreamARN()).thenReturn("arn:aws:kinesis:region:account:stream/test");
83+
84+
extractor.onStart(attributes, Context.current(), mockRequest);
85+
86+
verify(attributes)
87+
.put(
88+
eq(AwsExperimentalAttributes.AWS_STREAM_ARN),
89+
eq("arn:aws:kinesis:region:account:stream/test"));
90+
}
91+
92+
@Test
93+
void testStepFunctionsExperimentalAttributes() {
94+
StartExecutionRequest sfnRequest = mock(StartExecutionRequest.class);
95+
when(mockRequest.getServiceName()).thenReturn("AWSStepFunctions");
96+
when(mockRequest.getOriginalRequest()).thenReturn(sfnRequest);
97+
when(sfnRequest.getStateMachineArn())
98+
.thenReturn("arn:aws:states:region:account:stateMachine/test");
99+
100+
extractor.onStart(attributes, Context.current(), mockRequest);
101+
102+
verify(attributes)
103+
.put(
104+
eq(AwsExperimentalAttributes.AWS_STATE_MACHINE_ARN),
105+
eq("arn:aws:states:region:account:stateMachine/test"));
106+
}
107+
108+
@Test
109+
void testAuthAccessKeyAttributes() {
110+
AWSCredentials credentials = mock(AWSCredentials.class);
111+
when(mockRequest.getHandlerContext(AWS_CREDENTIALS)).thenReturn(credentials);
112+
when(credentials.getAWSAccessKeyId()).thenReturn("AKIAIOSFODNN7EXAMPLE");
113+
when(mockRequest.getOriginalRequest()).thenReturn(mock(PublishRequest.class));
114+
when(mockRequest.getServiceName()).thenReturn("AmazonSNS");
115+
116+
extractor.onStart(attributes, Context.current(), mockRequest);
117+
118+
verify(attributes)
119+
.put(eq(AwsExperimentalAttributes.AWS_AUTH_ACCESS_KEY), eq("AKIAIOSFODNN7EXAMPLE"));
120+
}
121+
122+
@Test
123+
void testSecretsManagerExperimentalAttributes() {
124+
GetSecretValueRequest secretRequest = mock(GetSecretValueRequest.class);
125+
when(mockRequest.getServiceName()).thenReturn("AWSSecretsManager");
126+
when(mockRequest.getOriginalRequest()).thenReturn(secretRequest);
127+
128+
extractor.onStart(attributes, Context.current(), mockRequest);
129+
// We're not verifying anything here since the actual attribute setting depends on reflection
130+
}
131+
132+
@Test
133+
void testLambdaNameExperimentalAttributes() {
134+
CreateFunctionRequest lambdaRequest = mock(CreateFunctionRequest.class);
135+
when(mockRequest.getServiceName()).thenReturn("AWSLambda");
136+
when(mockRequest.getOriginalRequest()).thenReturn(lambdaRequest);
137+
when(lambdaRequest.getFunctionName()).thenReturn("test-function");
138+
139+
extractor.onStart(attributes, Context.current(), mockRequest);
140+
141+
verify(attributes).put(eq(AwsExperimentalAttributes.AWS_LAMBDA_NAME), eq("test-function"));
142+
}
143+
144+
@Test
145+
void testLambdaArnExperimentalAttributes() {
146+
GetFunctionResult lambdaResult = mock(GetFunctionResult.class);
147+
FunctionConfiguration config = mock(FunctionConfiguration.class);
148+
when(mockResponse.getAwsResponse()).thenReturn(lambdaResult);
149+
when(lambdaResult.getConfiguration()).thenReturn(config);
150+
when(config.getFunctionArn()).thenReturn("arn:aws:lambda:region:account:function:test");
151+
when(mockRequest.getServiceName()).thenReturn("AWSLambda");
152+
153+
extractor.onEnd(attributes, Context.current(), mockRequest, mockResponse, null);
154+
155+
verify(attributes)
156+
.put(
157+
eq(AwsExperimentalAttributes.AWS_LAMBDA_ARN),
158+
eq("arn:aws:lambda:region:account:function:test"));
159+
}
160+
161+
@Test
162+
void testLambdaResourceIdExperimentalAttributes() {
163+
PublishRequest originalRequest = mock(PublishRequest.class);
164+
when(mockRequest.getServiceName()).thenReturn("AWSLambda");
165+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
166+
167+
extractor.onStart(attributes, Context.current(), mockRequest);
168+
// We can't verify the actual attribute setting since it depends on reflection
169+
}
170+
171+
@Test
172+
void testTableArnExperimentalAttributes() {
173+
PublishRequest originalRequest = mock(PublishRequest.class);
174+
when(mockRequest.getServiceName()).thenReturn("AmazonDynamoDBv2");
175+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
176+
177+
extractor.onStart(attributes, Context.current(), mockRequest);
178+
// We can't verify the actual attribute setting since it depends on reflection
179+
}
180+
181+
@Test
182+
void testBedrockRuntimeAttributes() {
183+
PublishRequest originalRequest = mock(PublishRequest.class);
184+
when(mockRequest.getServiceName()).thenReturn("AmazonBedrockRuntime");
185+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
186+
187+
extractor.onStart(attributes, Context.current(), mockRequest);
188+
// We can't verify the actual attribute setting since it depends on reflection and class name
189+
}
190+
191+
@Test
192+
void testBedrockAgentAttributes() {
193+
PublishRequest originalRequest = mock(PublishRequest.class);
194+
when(mockRequest.getServiceName()).thenReturn("AWSBedrockAgent");
195+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
196+
197+
extractor.onStart(attributes, Context.current(), mockRequest);
198+
// We can't verify the actual attribute setting since it depends on reflection
199+
}
200+
201+
@Test
202+
void testBedrockAgentRuntimeAttributes() {
203+
PublishRequest originalRequest = mock(PublishRequest.class);
204+
when(mockRequest.getServiceName()).thenReturn("AWSBedrockAgentRuntime");
205+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
206+
207+
extractor.onStart(attributes, Context.current(), mockRequest);
208+
// We can't verify the actual attribute setting since it depends on reflection
209+
}
210+
211+
@Test
212+
void testBedrockGuardrailAttributes() {
213+
PublishRequest originalRequest = mock(PublishRequest.class);
214+
when(mockRequest.getServiceName()).thenReturn("AmazonBedrock");
215+
when(mockRequest.getOriginalRequest()).thenReturn(originalRequest);
216+
217+
extractor.onStart(attributes, Context.current(), mockRequest);
218+
// We can't verify the actual attribute setting since it depends on reflection
219+
}
220+
}

0 commit comments

Comments
 (0)