Skip to content

Commit e90a788

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 25130600248) (#18414)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 9e623a0 commit e90a788

11 files changed

Lines changed: 50 additions & 45 deletions

File tree

.github/agents/knowledge/testing-general-patterns.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
- In JUnit tests, when an `AutoCloseable` is intended to remain live for most or all of the test
4949
and only needs cleanup at test end, prefer `AutoCleanupExtension` with `deferCleanup(...)`
5050
over wrapping most of the test body in try-with-resources.
51-
- Use `AutoCleanupExtension.deferAfterAll(...)` only for cleanup actions registered
52-
dynamically (from inside test methods or other runtime-conditional setup). For a
53-
fixed set of class-scoped fields known at class-init time, use a plain `@AfterAll`
54-
that closes each field directly.
51+
- For class-scoped cleanup, prefer `AutoCleanupExtension.deferAfterAll(...)`
52+
registered next to the resource's construction in `@BeforeAll`. The same
53+
applies to per-test cleanup with `deferCleanup(...)` registered in
54+
`@BeforeEach` or in the test body. This keeps creation and cleanup together
55+
and avoids a separate `@AfterAll` / `@AfterEach` that re-references and
56+
null-checks the field. Prefer a plain `@AfterAll` / `@AfterEach` when
57+
null-checking the field is not needed for correct cleanup.
5558
- Reuse an existing `cleanup` extension when one is already in scope.
5659
Otherwise, add a `@RegisterExtension` field when the deferred-cleanup pattern improves
5760
clarity or avoids wrapping most of the test body.

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractBaseAwsClientTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141

4242
@SuppressWarnings("deprecation") // using deprecated semconv
4343
public abstract class AbstractBaseAwsClientTest {
44+
protected static final AWSStaticCredentialsProvider credentialsProvider =
45+
new AWSStaticCredentialsProvider(new AnonymousAWSCredentials());
46+
protected static final MockWebServerExtension server = new MockWebServerExtension();
47+
protected static AwsClientBuilder.EndpointConfiguration endpoint;
48+
4449
protected abstract InstrumentationExtension testing();
4550

4651
protected abstract boolean hasRequestId();
4752

48-
protected static MockWebServerExtension server = new MockWebServerExtension();
49-
protected static AwsClientBuilder.EndpointConfiguration endpoint;
50-
protected static final AWSStaticCredentialsProvider credentialsProvider =
51-
new AWSStaticCredentialsProvider(new AnonymousAWSCredentials());
52-
5353
@BeforeAll
5454
static void setUp() {
5555
System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY, "my-access-key");

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractLambdaClientTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,28 @@ protected boolean hasRequestId() {
120120
return false;
121121
}
122122

123+
@ParameterizedTest
124+
@MethodSource("provideArguments")
125+
void testSendRequestWithMockedResponse(
126+
String operation,
127+
String method,
128+
String responseBody,
129+
List<AttributeAssertion> additionalAttributes,
130+
Function<AWSLambda, Object> call)
131+
throws ReflectiveOperationException {
132+
AWSLambdaClientBuilder clientBuilder = AWSLambdaClientBuilder.standard();
133+
AWSLambda client =
134+
configureClient(clientBuilder)
135+
.withEndpointConfiguration(endpoint)
136+
.withCredentials(credentialsProvider)
137+
.build();
138+
139+
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, responseBody));
140+
Object response = call.apply(client);
141+
assertRequestWithMockedResponse(
142+
response, client, "AWSLambda", operation, method, additionalAttributes);
143+
}
144+
123145
private static Stream<Arguments> provideArguments() {
124146
return Stream.of(
125147
Arguments.of(
@@ -163,26 +185,4 @@ private static Stream<Arguments> provideArguments() {
163185
c.getFunction(
164186
new GetFunctionRequest().withFunctionName("lambda-function-name-foo"))));
165187
}
166-
167-
@ParameterizedTest
168-
@MethodSource("provideArguments")
169-
void testSendRequestWithMockedResponse(
170-
String operation,
171-
String method,
172-
String responseBody,
173-
List<AttributeAssertion> additionalAttributes,
174-
Function<AWSLambda, Object> call)
175-
throws ReflectiveOperationException {
176-
AWSLambdaClientBuilder clientBuilder = AWSLambdaClientBuilder.standard();
177-
AWSLambda client =
178-
configureClient(clientBuilder)
179-
.withEndpointConfiguration(endpoint)
180-
.withCredentials(credentialsProvider)
181-
.build();
182-
183-
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, responseBody));
184-
Object response = call.apply(client);
185-
assertRequestWithMockedResponse(
186-
response, client, "AWSLambda", operation, method, additionalAttributes);
187-
}
188188
}

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractS3ClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
@SuppressWarnings("deprecation") // using deprecated semconv
4848
public abstract class AbstractS3ClientTest extends AbstractBaseAwsClientTest {
4949

50-
public abstract AmazonS3ClientBuilder configureClient(AmazonS3ClientBuilder client);
51-
5250
private final AmazonS3ClientBuilder clientBuilder =
5351
AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true);
5452

53+
public abstract AmazonS3ClientBuilder configureClient(AmazonS3ClientBuilder client);
54+
5555
@Override
5656
protected boolean hasRequestId() {
5757
return false;

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
@SuppressWarnings("deprecation") // using deprecated semconv
4848
public abstract class AbstractSqsSuppressReceiveSpansTest {
4949

50+
private static int sqsPort;
51+
private static SQSRestServer sqsRestServer;
52+
private static AmazonSQSAsync sqsClient;
53+
5054
protected abstract InstrumentationExtension testing();
5155

5256
protected abstract AmazonSQSAsyncClientBuilder configureClient(
5357
AmazonSQSAsyncClientBuilder client);
5458

55-
private static int sqsPort;
56-
private static SQSRestServer sqsRestServer;
57-
private static AmazonSQSAsync sqsClient;
58-
5959
@BeforeEach
6060
void setUp() {
6161
sqsPort = PortUtils.findOpenPort();

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@
6161
@SuppressWarnings("deprecation") // using deprecated semconv
6262
public abstract class AbstractSqsTracingTest {
6363

64+
private static int sqsPort;
65+
private static SQSRestServer sqsRestServer;
66+
private static AmazonSQSAsync sqsClient;
67+
6468
protected abstract InstrumentationExtension testing();
6569

6670
protected abstract AmazonSQSAsyncClientBuilder configureClient(
6771
AmazonSQSAsyncClientBuilder client);
6872

69-
private static int sqsPort;
70-
private static SQSRestServer sqsRestServer;
71-
private static AmazonSQSAsync sqsClient;
72-
7373
@BeforeEach
7474
void setUp() {
7575
sqsPort = PortUtils.findOpenPort();

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ muzzle {
99
group.set("software.amazon.awssdk")
1010
module.set("aws-core")
1111
versions.set("[2.2.0,)")
12+
assertInverse.set(true)
1213
// Used by all SDK services, the only case it isn't is an SDK extension such as a custom HTTP
1314
// client, which is not target of instrumentation anyways.
1415
extraDependency("software.amazon.awssdk:protocol-core")
@@ -36,6 +37,7 @@ muzzle {
3637
group.set("software.amazon.awssdk")
3738
module.set("sqs")
3839
versions.set("[2.2.0,)")
40+
assertInverse.set(true)
3941
// Used by all SDK services, the only case it isn't is an SDK extension such as a custom HTTP
4042
// client, which is not target of instrumentation anyways.
4143
extraDependency("software.amazon.awssdk:protocol-core")

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/BedrockRuntimeInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void doTransform(TypeTransformer transformer) {
4646

4747
@SuppressWarnings("unused")
4848
public static class RegisterAdvice {
49-
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
49+
@Advice.OnMethodExit(inline = false)
5050
public static void onExit() {
5151
// (indirectly) using BedrockRuntimeImpl class here to make sure it is available from
5252
// BedrockRuntimeAccess (injected into app classloader) and checked by Muzzle

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/LambdaInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void doTransform(TypeTransformer transformer) {
3939

4040
@SuppressWarnings("unused")
4141
public static class RegisterAdvice {
42-
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
42+
@Advice.OnMethodExit(inline = false)
4343
public static void onExit() {
4444
// (indirectly) using LambdaImpl class here to make sure it is available from LambdaAccess
4545
// (injected into app classloader) and checked by Muzzle

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v2_2/SnsInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void doTransform(TypeTransformer transformer) {
3636

3737
@SuppressWarnings("unused")
3838
public static class RegisterAdvice {
39-
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
39+
@Advice.OnMethodExit(inline = false)
4040
public static void onExit() {
4141
// (indirectly) using SnsImpl class here to make sure it is available from SnsAccess
4242
// (injected into app classloader) and checked by Muzzle

0 commit comments

Comments
 (0)