Skip to content

Commit e64d78a

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 25260462600) (open-telemetry#18518)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent e84cdb9 commit e64d78a

14 files changed

Lines changed: 50 additions & 33 deletions

File tree

.github/agents/knowledge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1515
| `gradle-conventions.md` | `build.gradle.kts` or `settings.gradle.kts` changes, custom test task registration or wiring |
1616
| `javaagent-advice-patterns.md` | ByteBuddy `@Advice` class or advice-method changes |
1717
| `javaagent-module-patterns.md` | `InstrumentationModule`, `TypeInstrumentation`, `VirtualField`, `CallDepth` |
18-
| `javaagent-singletons-patterns.md` | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields |
18+
| `javaagent-singletons-patterns.md` | `*Singletons`, `*SpanNaming`, and similar holder classes; singleton accessors; callers of singleton accessors/fields |
1919
| `library-patterns.md` | Library instrumentation telemetry, builder, getter, or setter pattern changes |
2020
| `module-naming.md` | New or renamed modules or packages; settings includes |
2121
| `testing-general-patterns.md` | Test files in scope — assertion style, test method signatures and throws clauses, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |

.github/agents/knowledge/general-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
2121
| Naming | Module/package naming | New or renamed modules/packages | `module-naming.md` |
2222
| Javaagent | Advice patterns | `@Advice` classes | `javaagent-advice-patterns.md` |
2323
| Javaagent | Module structure patterns | `InstrumentationModule`, `TypeInstrumentation` | `javaagent-module-patterns.md` |
24-
| Javaagent | Singletons patterns | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields | `javaagent-singletons-patterns.md` |
24+
| Javaagent | Singletons patterns | `*Singletons`, `*SpanNaming`, and similar holder classes; singleton accessors; callers of singleton accessors/fields | `javaagent-singletons-patterns.md` |
2525
| Javaagent | Incorrect `classLoaderMatcher()` | `classLoaderMatcher()` override that is redundant (muzzle already handles it) or missing when needed (muzzle cannot distinguish version range) | `javaagent-module-patterns.md` |
2626
| Semconv | Library vs javaagent semconv constant usage | Semconv constants/assertions ||
2727
| Semconv | Dual semconv testing | `SemconvStability`, `maybeStable`, semconv Gradle tasks | `testing-semconv-stability.md` |

.github/agents/knowledge/javaagent-singletons-patterns.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
## Quick Reference
44

5-
- Use when: reviewing `*Singletons` holder classes and their callers
5+
- Use when: reviewing `*Singletons`, `*SpanNaming`, and similar holder classes and their callers
66
- Review focus: field/accessor naming, eager initialization, singleton accessor call sites
77

88
Javaagent modules keep shared `Instrumenter` instances and related collaborators in a dedicated
9-
`Singletons` holder class such as `MyLibrarySingletons`.
9+
`Singletons` holder class such as `MyLibrarySingletons`. Some modules also use focused helper
10+
holders such as `*ServerSpanNaming` for shared span-name or route-name collaborators; apply the
11+
same accessor and call-site rules when these classes expose stored singleton fields.
1012

1113
## Rules
1214

@@ -18,8 +20,10 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
1820
- For exported collaborators, keep the field `private`, use a lower camel case field name, and
1921
give the accessor method the exact same name as the field. Do not prefix these accessors with
2022
`get`. This rule applies only to zero-arg methods that directly return a stored singleton
21-
field; methods that take arguments or compute a value are not singleton accessors and keep
22-
their normal names (including `get*` when appropriate).
23+
field. It applies regardless of whether the holder class is named `*Singletons`,
24+
`*ServerSpanNaming`, or another focused holder name. Methods that take arguments or compute a
25+
value are not singleton accessors and keep their normal names (including `get*` when
26+
appropriate).
2327
- `instrumenter` -> `instrumenter()`
2428
- `helper` -> `helper()`
2529
- `setter` -> `setter()`
@@ -32,7 +36,9 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
3236
- `RESPONSE_STATUS` stays `RESPONSE_STATUS`
3337
- Callers should static import only exported singleton accessors and uppercase constant-like
3438
fields, and use those members unqualified: accessors for lower camel collaborators, fields for
35-
uppercase constant-like members.
39+
uppercase constant-like members. This includes route/span naming accessors such as
40+
`serverSpanName()` when they simply return a stored `HttpServerRouteGetter` or similar
41+
collaborator.
3642
- Keep verb-named helper methods as verbs when they perform work instead of returning a stored
3743
field. These methods are not singleton accessors and should not be static imported under this
3844
rule.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@
9797
`equalTo(AttributeKey<Long>, int)` overload, so `equalTo(longKey("iteration"), iteration)` is
9898
preferred over `equalTo(longKey("iteration"), (long) iteration)`.
9999

100+
## Metric Assertions
101+
102+
- Prefer `InstrumentationExtension.waitAndAssertMetrics(...)` for metric assertions. It waits
103+
until the supplied assertion passes, so fixed sleeps such as `Thread.sleep(100)`
104+
usually unnecessary and make tests slower and more fragile.
105+
- `DbConnectionPoolMetricsAssertions.assertConnectionPoolEmitsMetrics()` already uses
106+
`waitAndAssertMetrics(...)` for each expected pool metric. Keep the pool state being asserted
107+
valid until this method returns; for example, if the assertion expects a `used` connection point,
108+
keep the borrowed connection open until after the assertion.
109+
- After removing a metric-producing source or unregistering an observable callback, call
110+
`testing().clearData()` and then use `waitAndAssertMetrics(..., AbstractIterableAssert::isEmpty)`
111+
for absence checks. Do not add an exporter-interval sleep before or after `clearData()` solely to
112+
wait for metrics; the test runners force-flush metrics when reading them.
113+
100114
## Attribute Assertion `satisfies()` Lambda Parameters
101115

102116
**Attribute-assertion `satisfies()` lambda parameters are `AbstractAssert` instances, not raw

instrumentation/clickhouse/clickhouse-client-common-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/client/common/v0_5/ClickHouseAttributesGetter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import java.util.function.Function;
1616
import javax.annotation.Nullable;
1717

18-
final class ClickHouseAttributesGetter
19-
implements SqlClientAttributesGetter<ClickHouseDbRequest, Void> {
18+
class ClickHouseAttributesGetter implements SqlClientAttributesGetter<ClickHouseDbRequest, Void> {
2019

2120
private final Function<Throwable, String> errorCodeExtractor;
2221

instrumentation/play/play-ws/play-ws-common-1.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/common/v1_0/PlayWsClientBaseTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ abstract class PlayWsClientBaseTest<REQUEST> extends AbstractHttpClientTest<REQU
4444
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
4545

4646
private static ActorSystem system;
47-
protected static AsyncHttpClient asyncHttpClient;
48-
protected static AsyncHttpClient asyncHttpClientWithReadTimeout;
49-
protected static ActorMaterializer materializer;
47+
static AsyncHttpClient asyncHttpClient;
48+
static AsyncHttpClient asyncHttpClientWithReadTimeout;
49+
static ActorMaterializer materializer;
5050

5151
@BeforeAll
5252
static void setupHttpClient() {

instrumentation/vibur-dbcp-11.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/viburdbcp/v11_0/ViburDbcpInstrumentationModule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public ViburDbcpInstrumentationModule() {
2424
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
2525
// in 11.0, the ViburDBCPDataSource#getPool() method signature was changed - this is detected by
2626
// muzzle
27-
return hasClassesNamed(
28-
// added in 10.0
29-
"org.vibur.dbcp.ViburConfig");
27+
// added in 10.0
28+
return hasClassesNamed("org.vibur.dbcp.ViburConfig");
3029
}
3130

3231
@Override

instrumentation/vibur-dbcp-11.0/testing/src/main/java/io/opentelemetry/instrumentation/viburdbcp/AbstractViburInstrumentationTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.instrumentation.viburdbcp;
77

88
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
9-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
109
import static org.mockito.Mockito.when;
1110

1211
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
@@ -35,7 +34,7 @@ public abstract class AbstractViburInstrumentationTest {
3534
protected abstract void shutdown(ViburDBCPDataSource viburDataSource);
3635

3736
@Test
38-
void shouldReportMetrics() throws SQLException, InterruptedException {
37+
void shouldReportMetrics() throws SQLException {
3938
// given
4039
when(dataSourceMock.getConnection()).thenReturn(connectionMock);
4140

@@ -47,8 +46,6 @@ void shouldReportMetrics() throws SQLException, InterruptedException {
4746

4847
// when
4948
Connection viburConnection = viburDataSource.getConnection();
50-
MILLISECONDS.sleep(100);
51-
viburConnection.close();
5249

5350
// then
5451
DbConnectionPoolMetricsAssertions.create(testing(), INSTRUMENTATION_NAME, "testPool")
@@ -62,15 +59,14 @@ void shouldReportMetrics() throws SQLException, InterruptedException {
6259
.assertConnectionPoolEmitsMetrics();
6360

6461
// when
62+
viburConnection.close();
63+
6564
// this one too shouldn't cause any problems when called more than once
6665
viburDataSource.close();
6766
viburDataSource.close();
6867
shutdown(viburDataSource);
6968

70-
// sleep exporter interval
71-
Thread.sleep(100);
7269
testing().clearData();
73-
Thread.sleep(100);
7470

7571
// then
7672
String countMetricName =

instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/v8_0/RequestHandlerExecutorInstrumentation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package io.opentelemetry.javaagent.instrumentation.wicket.v8_0;
77

88
import static io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource.CONTROLLER;
9+
import static io.opentelemetry.javaagent.instrumentation.wicket.v8_0.WicketServerSpanNaming.serverSpanName;
10+
import static io.opentelemetry.javaagent.instrumentation.wicket.v8_0.WicketServerSpanNaming.serverSpanNameResource;
911
import static net.bytebuddy.matcher.ElementMatchers.named;
1012
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1113

@@ -43,14 +45,14 @@ public static void onEnter(@Advice.Argument(0) IRequestHandler handler) {
4345
HttpServerRoute.update(
4446
Java8BytecodeBridge.currentContext(),
4547
CONTROLLER,
46-
WicketServerSpanNaming.getServerSpanName(),
48+
serverSpanName(),
4749
(IPageClassRequestHandler) handler);
4850
}
4951
if (handler instanceof ResourceReferenceRequestHandler) {
5052
HttpServerRoute.update(
5153
Java8BytecodeBridge.currentContext(),
5254
CONTROLLER,
53-
WicketServerSpanNaming.getServerSpanNameResource(),
55+
serverSpanNameResource(),
5456
(ResourceReferenceRequestHandler) handler);
5557
}
5658
}

instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/v8_0/WicketServerSpanNaming.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public class WicketServerSpanNaming {
3434
return ServletContextPath.prepend(context, filterPath + "/" + resourceName);
3535
};
3636

37-
public static HttpServerRouteGetter<IPageClassRequestHandler> getServerSpanName() {
37+
public static HttpServerRouteGetter<IPageClassRequestHandler> serverSpanName() {
3838
return serverSpanName;
3939
}
4040

41-
public static HttpServerRouteGetter<ResourceReferenceRequestHandler> getServerSpanNameResource() {
41+
public static HttpServerRouteGetter<ResourceReferenceRequestHandler> serverSpanNameResource() {
4242
return serverSpanNameResource;
4343
}
4444

0 commit comments

Comments
 (0)