Skip to content

Commit

Permalink
remove unneeded vars, make s3 exception more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Nov 11, 2024
1 parent 70b4349 commit ba5e621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ private static Stream<Arguments> provideS3Arguments() {
@MethodSource("provideS3Arguments")
@SuppressWarnings("deprecation") // AmazonS3Client constructor is deprecated
void testRequestHandlerIsHookedUpWithConstructor(boolean addHandler, int size) throws Exception {
String accessKey = "asdf";
String secretKey = "qwerty";
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
BasicAWSCredentials credentials = new BasicAWSCredentials("asdf", "qwerty");
AmazonS3Client client = new AmazonS3Client(credentials);
if (addHandler) {
client.addRequestHandler(new RequestHandler2() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
import static io.opentelemetry.instrumentation.test.utils.PortUtils.UNUSABLE_PORT;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
Expand Down Expand Up @@ -159,42 +158,25 @@ void testTimeoutAndRetryErrorsNotCaptured() {
.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> {
span.hasName("S3.GetObject")
.hasKind(CLIENT)
.hasStatus(StatusData.error())
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(URL_FULL, server.httpUri().toString()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_PORT, server.httpPort()),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "Amazon S3"),
equalTo(RPC_METHOD, "GetObject"),
equalTo(stringKey("aws.endpoint"), server.httpUri().toString()),
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.bucket.name"), "someBucket"),
satisfies(
ERROR_TYPE,
val ->
val.satisfiesAnyOf(
v ->
assertThat(v)
.isEqualTo(SdkClientException.class.getName()),
v ->
assertThat(v)
.isEqualTo(
AmazonClientException.class.getName()))));

try {
span.hasException(
new AmazonClientException("Unable to execute HTTP request"));
} catch (AssertionError e) {
span.hasException(
new SdkClientException(
"Unable to execute HTTP request: Request did not complete before the request timeout configuration."));
}
}));
span ->
span.hasName("S3.GetObject")
.hasKind(CLIENT)
.hasStatus(StatusData.error())
.hasNoParent()
.hasException(
new SdkClientException(
"Unable to execute HTTP request: Request did not complete before the request timeout configuration."))
.hasAttributesSatisfyingExactly(
equalTo(URL_FULL, server.httpUri().toString()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_PORT, server.httpPort()),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(RPC_SYSTEM, "aws-api"),
equalTo(RPC_SERVICE, "Amazon S3"),
equalTo(RPC_METHOD, "GetObject"),
equalTo(stringKey("aws.endpoint"), server.httpUri().toString()),
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.bucket.name"), "someBucket"),
equalTo(ERROR_TYPE, SdkClientException.class.getName()))));
}
}

0 comments on commit ba5e621

Please sign in to comment.