Skip to content

Commit 1e35fa5

Browse files
committed
Merge remote-tracking branch 'upstream/main' into split-armeria
2 parents a4463f6 + 4cc4e1c commit 1e35fa5

File tree

26 files changed

+217
-54
lines changed

26 files changed

+217
-54
lines changed

custom-checks/src/main/java/io/opentelemetry/javaagent/customchecks/OtelInternalJavadoc.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
@AutoService(BugChecker.class)
2424
@BugPattern(
2525
summary =
26-
"This public internal class doesn't end with the javadoc disclaimer: \""
27-
+ OtelInternalJavadoc.EXPECTED_INTERNAL_COMMENT
26+
"This public internal class doesn't end with any of the applicable javadoc disclaimers: \""
27+
+ OtelInternalJavadoc.EXPECTED_INTERNAL_COMMENT_V1
28+
+ "\", or \""
29+
+ OtelInternalJavadoc.EXPECTED_INTERNAL_COMMENT_V2
2830
+ "\"",
2931
severity = WARNING)
3032
public class OtelInternalJavadoc extends BugChecker implements BugChecker.ClassTreeMatcher {
@@ -36,17 +38,24 @@ public class OtelInternalJavadoc extends BugChecker implements BugChecker.ClassT
3638
private static final Pattern EXCLUDE_PACKAGE_PATTERN =
3739
Pattern.compile("^io\\.opentelemetry\\.javaagent\\.instrumentation\\.internal\\.");
3840

39-
static final String EXPECTED_INTERNAL_COMMENT =
41+
static final String EXPECTED_INTERNAL_COMMENT_V1 =
4042
"This class is internal and is hence not for public use."
4143
+ " Its APIs are unstable and can change at any time.";
4244

45+
static final String EXPECTED_INTERNAL_COMMENT_V2 =
46+
"This class is internal and experimental. Its APIs are unstable and can change at any time."
47+
+ " Its APIs (or a version of them) may be promoted to the public stable API in the"
48+
+ " future, but no guarantees are made.";
49+
4350
@Override
4451
public Description matchClass(ClassTree tree, VisitorState state) {
4552
if (!isPublic(tree) || !isInternal(state) || tree.getSimpleName().toString().endsWith("Test")) {
4653
return Description.NO_MATCH;
4754
}
4855
String javadoc = getJavadoc(state);
49-
if (javadoc != null && javadoc.endsWith(EXPECTED_INTERNAL_COMMENT)) {
56+
if (javadoc != null
57+
&& (javadoc.contains(EXPECTED_INTERNAL_COMMENT_V1)
58+
|| javadoc.contains(EXPECTED_INTERNAL_COMMENT_V2))) {
5059
return Description.NO_MATCH;
5160
}
5261
return describeMatch(tree);

custom-checks/src/test/resources/io/opentelemetry/javaagent/customchecks/internal/InternalJavadocPositiveCases.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
package io.opentelemetry.javaagent.customchecks.internal;
77

8-
// BUG: Diagnostic contains: doesn't end with the javadoc disclaimer
8+
// BUG: Diagnostic contains: doesn't end with any of the applicable javadoc disclaimers
99
public class InternalJavadocPositiveCases {
1010

11-
// BUG: Diagnostic contains: doesn't end with the javadoc disclaimer
11+
// BUG: Diagnostic contains: doesn't end with any of the applicable javadoc disclaimers
1212
public static class One {}
1313

1414
/** Doesn't have the disclaimer. */
15-
// BUG: Diagnostic contains: doesn't end with the javadoc disclaimer
15+
// BUG: Diagnostic contains: doesn't end with any of the applicable javadoc disclaimers
1616
public static class Two {}
1717
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static <REQUEST, RESPONSE> DefaultHttpClientInstrumenterBuilder<REQUEST,
103103
* items. The {@link AttributesExtractor} will be executed after all default extractors.
104104
*/
105105
@CanIgnoreReturnValue
106-
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> addAttributeExtractor(
106+
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractor(
107107
AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) {
108108
additionalExtractors.add(attributesExtractor);
109109
return this;
@@ -190,15 +190,15 @@ public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setSpanNameExtrac
190190
@CanIgnoreReturnValue
191191
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setPeerServiceResolver(
192192
PeerServiceResolver peerServiceResolver) {
193-
return addAttributeExtractor(
193+
return addAttributesExtractor(
194194
HttpClientPeerServiceAttributesExtractor.create(attributesGetter, peerServiceResolver));
195195
}
196196

197197
/** Sets the {@code peer.service} attribute for http client spans. */
198198
@CanIgnoreReturnValue
199199
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setPeerService(
200200
String peerService) {
201-
return addAttributeExtractor(AttributesExtractor.constant(PEER_SERVICE, peerService));
201+
return addAttributesExtractor(AttributesExtractor.constant(PEER_SERVICE, peerService));
202202
}
203203

204204
@CanIgnoreReturnValue

instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,27 @@ public final class ApacheHttpClientTelemetryBuilder {
3333
/**
3434
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
3535
* items. The {@link AttributesExtractor} will be executed after all default extractors.
36+
*
37+
* @deprecated Use {@link #addAttributesExtractor(AttributesExtractor)} instead.
3638
*/
39+
@Deprecated
3740
@CanIgnoreReturnValue
3841
public ApacheHttpClientTelemetryBuilder addAttributeExtractor(
3942
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
4043
attributesExtractor) {
41-
builder.addAttributeExtractor(attributesExtractor);
44+
builder.addAttributesExtractor(attributesExtractor);
45+
return this;
46+
}
47+
48+
/**
49+
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
50+
* items. The {@link AttributesExtractor} will be executed after all default extractors.
51+
*/
52+
@CanIgnoreReturnValue
53+
public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
54+
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
55+
attributesExtractor) {
56+
builder.addAttributesExtractor(attributesExtractor);
4257
return this;
4358
}
4459

instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class ApacheHttpClient5TelemetryBuilder {
3939
public ApacheHttpClient5TelemetryBuilder addAttributeExtractor(
4040
AttributesExtractor<? super ApacheHttpClient5Request, ? super HttpResponse>
4141
attributesExtractor) {
42-
builder.addAttributeExtractor(attributesExtractor);
42+
builder.addAttributesExtractor(attributesExtractor);
4343
return this;
4444
}
4545

instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ArmeriaTelemetryBuilder setServerStatusExtractor(
104104
@CanIgnoreReturnValue
105105
public ArmeriaTelemetryBuilder addAttributeExtractor(
106106
AttributesExtractor<? super RequestContext, ? super RequestLog> attributesExtractor) {
107-
clientBuilder.addAttributeExtractor(attributesExtractor);
107+
clientBuilder.addAttributesExtractor(attributesExtractor);
108108
serverBuilder.addAttributesExtractor(attributesExtractor);
109109
return this;
110110
}
@@ -121,7 +121,7 @@ public ArmeriaTelemetryBuilder addAttributeExtractor(
121121
@CanIgnoreReturnValue
122122
public ArmeriaTelemetryBuilder addClientAttributeExtractor(
123123
AttributesExtractor<? super ClientRequestContext, ? super RequestLog> attributesExtractor) {
124-
clientBuilder.addAttributeExtractor(attributesExtractor);
124+
clientBuilder.addAttributesExtractor(attributesExtractor);
125125
return this;
126126
}
127127

instrumentation/couchbase/couchbase-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/v3_1/CouchbaseClient31Test.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ class CouchbaseClient31Test {
4444

4545
@BeforeAll
4646
static void setup() {
47+
// wait and retry in the hope that it will help against test flakiness
48+
await()
49+
.atMost(Duration.ofMinutes(5))
50+
.ignoreException(UnambiguousTimeoutException.class)
51+
.until(
52+
() -> {
53+
startCouchbase();
54+
return true;
55+
});
56+
}
57+
58+
private static void startCouchbase() {
4759
couchbase =
4860
new CouchbaseContainer("couchbase/server:7.6.0")
4961
.withExposedPorts(8091)
@@ -65,18 +77,11 @@ static void setup() {
6577
ClusterOptions.clusterOptions(couchbase.getUsername(), couchbase.getPassword())
6678
.environment(environment));
6779

68-
// wait and retry in the hope that it will help against test flakiness
69-
await()
70-
.atMost(Duration.ofMinutes(2))
71-
.ignoreException(UnambiguousTimeoutException.class)
72-
.until(
73-
() -> {
74-
Bucket bucket = cluster.bucket("test");
75-
collection = bucket.defaultCollection();
80+
Bucket bucket = cluster.bucket("test");
81+
collection = bucket.defaultCollection();
7682

77-
bucket.waitUntilReady(Duration.ofSeconds(30));
78-
return true;
79-
});
83+
// Wait 1 minute due to slow startup contributing to flakiness
84+
bucket.waitUntilReady(Duration.ofMinutes(1));
8085
}
8186

8287
@AfterAll

instrumentation/couchbase/couchbase-common/testing/src/main/java/io/opentelemetry/instrumentation/couchbase/AbstractCouchbaseAsyncClientTest.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.concurrent.TimeUnit;
3232
import java.util.concurrent.TimeoutException;
3333
import java.util.stream.Stream;
34+
import org.junit.jupiter.api.AfterAll;
35+
import org.junit.jupiter.api.BeforeAll;
3436
import org.junit.jupiter.api.Test;
3537
import org.junit.jupiter.api.extension.RegisterExtension;
3638
import org.junit.jupiter.params.ParameterizedTest;
@@ -47,28 +49,51 @@ public abstract class AbstractCouchbaseAsyncClientTest extends AbstractCouchbase
4749

4850
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
4951

52+
private CouchbaseEnvironment environmentCouchbase;
53+
private CouchbaseEnvironment environmentMemcache;
54+
private CouchbaseAsyncCluster clusterCouchbase;
55+
private CouchbaseAsyncCluster clusterMemcache;
56+
5057
private static Stream<Arguments> bucketSettings() {
5158
return Stream.of(
5259
Arguments.of(named(bucketCouchbase.type().name(), bucketCouchbase)),
5360
Arguments.of(named(bucketMemcache.type().name(), bucketMemcache)));
5461
}
5562

56-
private CouchbaseAsyncCluster prepareCluster(BucketSettings bucketSettings) {
57-
CouchbaseEnvironment environment = envBuilder(bucketSettings).build();
58-
CouchbaseAsyncCluster cluster =
59-
CouchbaseAsyncCluster.create(environment, Collections.singletonList("127.0.0.1"));
60-
cleanup.deferCleanup(
61-
() -> cluster.disconnect().timeout(10, TimeUnit.SECONDS).toBlocking().single());
62-
cleanup.deferCleanup(environment::shutdown);
63+
@BeforeAll
64+
void setUpClusters() {
65+
environmentCouchbase = envBuilder(bucketCouchbase).build();
66+
clusterCouchbase =
67+
CouchbaseAsyncCluster.create(environmentCouchbase, Collections.singletonList("127.0.0.1"));
68+
69+
environmentMemcache = envBuilder(bucketMemcache).build();
70+
clusterMemcache =
71+
CouchbaseAsyncCluster.create(environmentMemcache, Collections.singletonList("127.0.0.1"));
72+
}
73+
74+
@AfterAll
75+
void cleanUpClusters() {
76+
clusterCouchbase.disconnect().timeout(10, TimeUnit.SECONDS).toBlocking().single();
77+
environmentCouchbase.shutdown();
78+
79+
clusterMemcache.disconnect().timeout(10, TimeUnit.SECONDS).toBlocking().single();
80+
environmentMemcache.shutdown();
81+
}
6382

64-
return cluster;
83+
private CouchbaseAsyncCluster getCluster(BucketSettings bucketSettings) {
84+
if (bucketSettings == bucketCouchbase) {
85+
return clusterCouchbase;
86+
} else if (bucketSettings == bucketMemcache) {
87+
return clusterMemcache;
88+
}
89+
throw new IllegalArgumentException("unknown setting " + bucketSettings.name());
6590
}
6691

6792
@ParameterizedTest
6893
@MethodSource("bucketSettings")
6994
void hasBucket(BucketSettings bucketSettings)
7095
throws ExecutionException, InterruptedException, TimeoutException {
71-
CouchbaseAsyncCluster cluster = prepareCluster(bucketSettings);
96+
CouchbaseAsyncCluster cluster = getCluster(bucketSettings);
7297
AsyncClusterManager manager = cluster.clusterManager(USERNAME, PASSWORD).toBlocking().single();
7398

7499
testing.waitForTraces(1);
@@ -103,7 +128,7 @@ void hasBucket(BucketSettings bucketSettings)
103128
@MethodSource("bucketSettings")
104129
void upsert(BucketSettings bucketSettings)
105130
throws ExecutionException, InterruptedException, TimeoutException {
106-
CouchbaseAsyncCluster cluster = prepareCluster(bucketSettings);
131+
CouchbaseAsyncCluster cluster = getCluster(bucketSettings);
107132

108133
JsonObject content = JsonObject.create().put("hello", "world");
109134
CompletableFuture<JsonDocument> inserted = new CompletableFuture<>();
@@ -144,7 +169,7 @@ void upsert(BucketSettings bucketSettings)
144169
@MethodSource("bucketSettings")
145170
void upsertAndGet(BucketSettings bucketSettings)
146171
throws ExecutionException, InterruptedException, TimeoutException {
147-
CouchbaseAsyncCluster cluster = prepareCluster(bucketSettings);
172+
CouchbaseAsyncCluster cluster = getCluster(bucketSettings);
148173

149174
JsonObject content = JsonObject.create().put("hello", "world");
150175
CompletableFuture<JsonDocument> inserted = new CompletableFuture<>();
@@ -194,7 +219,7 @@ void upsertAndGet(BucketSettings bucketSettings)
194219
@Test
195220
void query() throws ExecutionException, InterruptedException, TimeoutException {
196221
// Only couchbase buckets support queries.
197-
CouchbaseAsyncCluster cluster = prepareCluster(bucketCouchbase);
222+
CouchbaseAsyncCluster cluster = getCluster(bucketCouchbase);
198223

199224
CompletableFuture<JsonObject> queryResult = new CompletableFuture<>();
200225
// Mock expects this specific query.

instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTelemetryBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,28 @@ public final class GrpcTelemetryBuilder {
5959
/**
6060
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
6161
* items. The {@link AttributesExtractor} will be executed after all default extractors.
62+
*
63+
* @deprecated Use {@link #addAttributesExtractor(AttributesExtractor)} instead.
6264
*/
65+
@Deprecated
6366
@CanIgnoreReturnValue
6467
public GrpcTelemetryBuilder addAttributeExtractor(
6568
AttributesExtractor<? super GrpcRequest, ? super Status> attributesExtractor) {
6669
additionalExtractors.add(attributesExtractor);
6770
return this;
6871
}
6972

73+
/**
74+
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
75+
* items. The {@link AttributesExtractor} will be executed after all default extractors.
76+
*/
77+
@CanIgnoreReturnValue
78+
public GrpcTelemetryBuilder addAttributesExtractor(
79+
AttributesExtractor<? super GrpcRequest, ? super Status> attributesExtractor) {
80+
additionalExtractors.add(attributesExtractor);
81+
return this;
82+
}
83+
7084
/**
7185
* Adds an extra client-only {@link AttributesExtractor} to invoke to set attributes to
7286
* instrumented items. The {@link AttributesExtractor} will be executed after all default

instrumentation/grpc-1.6/library/src/test/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void sayHello(
9191
.addService(greeter)
9292
.intercept(
9393
GrpcTelemetry.builder(testing.getOpenTelemetry())
94-
.addAttributeExtractor(new CustomAttributesExtractor())
94+
.addAttributesExtractor(new CustomAttributesExtractor())
9595
.addServerAttributeExtractor(new CustomAttributesExtractorV2("serverSideValue"))
9696
.build()
9797
.newServerInterceptor())
@@ -103,7 +103,7 @@ public void sayHello(
103103
ManagedChannelBuilder.forAddress("localhost", server.getPort())
104104
.intercept(
105105
GrpcTelemetry.builder(testing.getOpenTelemetry())
106-
.addAttributeExtractor(new CustomAttributesExtractor())
106+
.addAttributesExtractor(new CustomAttributesExtractor())
107107
.addClientAttributeExtractor(
108108
new CustomAttributesExtractorV2("clientSideValue"))
109109
.build()

0 commit comments

Comments
 (0)