Skip to content

Commit 07786ec

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 24966697425) (#18323)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 95f1757 commit 07786ec

7 files changed

Lines changed: 29 additions & 19 deletions

File tree

.github/agents/knowledge/gradle-conventions.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ Flag `build.gradle.kts` dependencies that appear unused or redundant:
157157
- A dependency that duplicates something already provided transitively.
158158
- A `testImplementation` dependency for a library not used in tests.
159159

160+
### Never declare `javaagent-bootstrap` explicitly in javaagent modules
161+
162+
The `otel.javaagent-instrumentation` convention plugin already provides
163+
`javaagent-bootstrap` on the `compileOnly` classpath transitively. Do not add
164+
`compileOnly(project(":javaagent-bootstrap"))` to a javaagent module's
165+
`build.gradle.kts`, and remove it if present.
166+
160167
## Custom Test Tasks
161168

162169
Every custom `Test` task registered with `val foo by registering(Test::class)` **must** include
@@ -215,15 +222,16 @@ block, not repeated on each individual task.
215222
If a property or JVM arg is moved into `withType<Test>().configureEach`, remove any now-redundant
216223
copies from individual tasks unless a task intentionally overrides the shared value.
217224

218-
When the module's `build.gradle.kts` does not explicitly register additional `Test` tasks,
219-
`tasks.test { ... }` is fine — **do not** convert it to `withType<Test>().configureEach` and
220-
do not flag it.
225+
**When the module has only a single test task, prefer the simple `tasks.test { ... }` form.**
226+
Do **not** convert `tasks.test { ... }` to `withType<Test>().configureEach` in single-test-task
227+
modules, and do **not** flag the simple form as a problem. The `withType<Test>().configureEach`
228+
form is only justified when the same `build.gradle.kts` actually registers additional `Test` tasks.
221229

222230
**`latestDepTest` does not count as a second test task for this rule.** It is registered
223231
implicitly by the convention plugin when `testLatestDeps` is set, and it inherits the
224232
configuration of `tasks.test`. A module with only a `tasks.test { ... }` block and no
225233
`by registering(Test::class)` declarations is a single-test-task module — leave it alone
226-
even if `testLatestDeps = true`.
234+
(use the simple form) even if `testLatestDeps = true`.
227235

228236
Only consider converting to `withType<Test>().configureEach` when the **same
229237
`build.gradle.kts`** explicitly registers one or more additional `Test` tasks via
@@ -261,9 +269,10 @@ review**. Only verify correctness when they are already present.
261269

262270
When already present, verify:
263271

264-
- `collectMetadata` is in `withType<Test>().configureEach` (or `tasks.test` if the module
265-
does not explicitly register additional `Test` tasks — `latestDepTest` does not count) —
266-
never on individual tasks.
272+
- `collectMetadata` is in `tasks.test` for single-test-task modules (preferred), or in
273+
`withType<Test>().configureEach` for modules that explicitly register additional `Test`
274+
tasks via `by registering(Test::class)` (`latestDepTest` does not count) — never on
275+
individual tasks.
267276
- `metadataConfig` is on each non-default task. It may also appear on the default `test`
268277
task when that task itself runs with non-default `jvmArgs` (e.g., an experimental flag
269278
enabled module-wide via `withType<Test>().configureEach { jvmArgs(...) }`); in that case

instrumentation/internal/internal-lambda/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/LambdaTransformerHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
/** Helper class for transforming lambda class bytes. */
1313
public class LambdaTransformerHelper {
1414

15-
private LambdaTransformerHelper() {}
16-
1715
/**
1816
* Called from {@code java.lang.invoke.InnerClassLambdaMetafactory} to transform lambda class
1917
* bytes.
@@ -40,4 +38,6 @@ public static byte[] transform(byte[] classBytes, String slashClassName, Class<?
4038
}
4139
return classBytes;
4240
}
41+
42+
private LambdaTransformerHelper() {}
4343
}

instrumentation/internal/internal-reflection/javaagent-integration-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ReflectionTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ void testOurFieldsAndMethodsAreNotVisibleWithReflection() {
3434

3535
// although marker interfaces are removed from getInterfaces() result class is still assignable
3636
// to them
37-
assertThat(VirtualFieldInstalledMarker.class.isAssignableFrom(TestClass.class)).isTrue();
38-
assertThat(VirtualFieldAccessorMarker.class.isAssignableFrom(TestClass.class)).isTrue();
39-
assertThat(TestClass.class.getInterfaces())
40-
.containsExactlyInAnyOrder(Runnable.class, Serializable.class);
37+
assertThat(TestClass.class).isAssignableTo(VirtualFieldInstalledMarker.class);
38+
assertThat(TestClass.class).isAssignableTo(VirtualFieldAccessorMarker.class);
39+
assertThat(TestClass.class.getInterfaces()).containsExactly(Runnable.class, Serializable.class);
4140
}
4241

4342
@Test

instrumentation/internal/internal-url-class-loader/javaagent-integration-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/urlclassloader/AddUrlTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
class AddUrlTest {
2020

21-
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
21+
@RegisterExtension
22+
private static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
2223

2324
@Test
2425
void testShouldInstrumentClassAfterItIsLoadedViaAddUrl() throws Exception {

instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/javahttpclient/HttpClientInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public static AsyncAdviceScope start(HttpRequest request) {
144144
}
145145
Context parentContext = currentContext();
146146
if (!instrumenter().shouldStart(parentContext, request)) {
147+
callDepth.decrementAndGet();
147148
return null;
148149
}
149150
Context context = instrumenter().start(parentContext, request);

instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/javahttpclient/JavaHttpClientTelemetryBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
/** Builder for {@link JavaHttpClientTelemetry}. */
2323
public final class JavaHttpClientTelemetryBuilder {
2424

25-
private final DefaultHttpClientInstrumenterBuilder<HttpRequest, HttpResponse<?>> builder;
26-
private final OpenTelemetry openTelemetry;
27-
2825
static {
2926
Experimental.internalSetEmitExperimentalTelemetry(
3027
(builder, emit) -> builder.builder.setEmitExperimentalHttpClientTelemetry(emit));
3128
}
3229

30+
private final DefaultHttpClientInstrumenterBuilder<HttpRequest, HttpResponse<?>> builder;
31+
private final OpenTelemetry openTelemetry;
32+
3333
JavaHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) {
3434
builder = JavaHttpClientInstrumenterBuilderFactory.create(openTelemetry);
3535
this.openTelemetry = openTelemetry;

instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/javahttpclient/internal/JavaHttpClientInstrumenterBuilderFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
* any time.
1616
*/
1717
public class JavaHttpClientInstrumenterBuilderFactory {
18-
private JavaHttpClientInstrumenterBuilderFactory() {}
19-
2018
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.java-http-client";
2119

2220
public static DefaultHttpClientInstrumenterBuilder<HttpRequest, HttpResponse<?>> create(
2321
OpenTelemetry openTelemetry) {
2422
return DefaultHttpClientInstrumenterBuilder.create(
2523
INSTRUMENTATION_NAME, openTelemetry, new JavaHttpClientAttributesGetter());
2624
}
25+
26+
private JavaHttpClientInstrumenterBuilderFactory() {}
2727
}

0 commit comments

Comments
 (0)