Skip to content

Commit 429ecfc

Browse files
authored
Update error prone (#6646)
(note that change from BDDMockito is due to google/error-prone#3396)
1 parent 557c6d1 commit 429ecfc

File tree

79 files changed

+382
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+382
-51
lines changed

conventions/src/main/kotlin/otel.java-conventions.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ dependencies {
124124
components.all<NettyAlignmentRule>()
125125

126126
compileOnly("com.google.code.findbugs:jsr305")
127+
compileOnly("com.google.errorprone:error_prone_annotations")
127128

128129
codenarc("org.codenarc:CodeNarc:2.2.0")
129130
codenarc(platform("org.codehaus.groovy:groovy-bom:3.0.9"))

dependencyManagement/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ val CORE_DEPENDENCIES = listOf(
4545
"com.google.auto.service:auto-service-annotations:1.0.1",
4646
"com.google.auto.value:auto-value:1.9",
4747
"com.google.auto.value:auto-value-annotations:1.9",
48-
"com.google.errorprone:error_prone_annotations:2.14.0",
49-
"com.google.errorprone:error_prone_core:2.14.0",
50-
"com.google.errorprone:error_prone_test_helpers:2.14.0",
48+
"com.google.errorprone:error_prone_annotations:2.15.0",
49+
"com.google.errorprone:error_prone_core:2.15.0",
50+
"com.google.errorprone:error_prone_test_helpers:2.15.0",
5151
// When updating, also update conventions/build.gradle.kts
5252
"net.bytebuddy:byte-buddy:1.12.17",
5353
"net.bytebuddy:byte-buddy-dep:1.12.17",

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlClientAttributesExtractorBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Objects.requireNonNull;
99

10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1011
import io.opentelemetry.api.common.AttributeKey;
1112
import io.opentelemetry.instrumentation.api.db.SqlStatementSanitizer;
1213
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
@@ -30,6 +31,7 @@ public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
3031
* @param dbTableAttribute The {@link AttributeKey} under which the table extracted by the {@link
3132
* SqlClientAttributesExtractor} will be stored.
3233
*/
34+
@CanIgnoreReturnValue
3335
public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setTableAttribute(
3436
AttributeKey<String> dbTableAttribute) {
3537
this.dbTableAttribute = requireNonNull(dbTableAttribute);
@@ -41,6 +43,7 @@ public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setTableAttribute(
4143
* SqlClientAttributesExtractor} should be sanitized. If set to {@code true}, all parameters that
4244
* can potentially contain sensitive information will be masked. Enabled by default.
4345
*/
46+
@CanIgnoreReturnValue
4447
public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setStatementSanitizationEnabled(
4548
boolean statementSanitizationEnabled) {
4649
this.statementSanitizationEnabled = statementSanitizationEnabled;

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Collections.emptyList;
99

10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1011
import java.util.List;
1112

1213
/** A builder of {@link HttpClientAttributesExtractor}. */
@@ -31,6 +32,7 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
3132
*
3233
* @param requestHeaders A list of HTTP header names.
3334
*/
35+
@CanIgnoreReturnValue
3436
public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
3537
List<String> requestHeaders) {
3638
this.capturedRequestHeaders = requestHeaders;
@@ -49,6 +51,7 @@ public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedReques
4951
*
5052
* @param responseHeaders A list of HTTP header names.
5153
*/
54+
@CanIgnoreReturnValue
5255
public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
5356
List<String> responseHeaders) {
5457
this.capturedResponseHeaders = responseHeaders;

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Collections.emptyList;
99

10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1011
import java.util.List;
1112

1213
/** A builder of {@link HttpServerAttributesExtractor}. */
@@ -31,6 +32,7 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
3132
*
3233
* @param requestHeaders A list of HTTP header names.
3334
*/
35+
@CanIgnoreReturnValue
3436
public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
3537
List<String> requestHeaders) {
3638
this.capturedRequestHeaders = requestHeaders;
@@ -49,6 +51,7 @@ public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedReques
4951
*
5052
* @param responseHeaders A list of HTTP header names.
5153
*/
54+
@CanIgnoreReturnValue
5255
public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
5356
List<String> responseHeaders) {
5457
this.capturedResponseHeaders = responseHeaders;

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorBuilder.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Collections.emptyList;
99

10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1011
import java.util.List;
1112

1213
/** A builder of {@link MessagingAttributesExtractor}. */
@@ -31,6 +32,7 @@ public final class MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> {
3132
*
3233
* @param capturedHeaders A list of messaging header names.
3334
*/
35+
@CanIgnoreReturnValue
3436
public MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedHeaders(
3537
List<String> capturedHeaders) {
3638
this.capturedHeaders = capturedHeaders;

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractorTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.opentelemetry.instrumentation.api.instrumenter.code;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.mockito.BDDMockito.willReturn;
9+
import static org.mockito.Mockito.doReturn;
1010

1111
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
1212
import org.junit.jupiter.api.Test;
@@ -23,8 +23,8 @@ void shouldExtractFullSpanName() {
2323
// given
2424
Object request = new Object();
2525

26-
willReturn(TestClass.class).given(getter).codeClass(request);
27-
willReturn("doSomething").given(getter).methodName(request);
26+
doReturn(TestClass.class).when(getter).codeClass(request);
27+
doReturn("doSomething").when(getter).methodName(request);
2828

2929
SpanNameExtractor<Object> underTest = CodeSpanNameExtractor.create(getter);
3030

@@ -41,8 +41,8 @@ void shouldExtractFullSpanNameForAnonymousClass() {
4141
AnonymousBaseClass anon = new AnonymousBaseClass() {};
4242
Object request = new Object();
4343

44-
willReturn(anon.getClass()).given(getter).codeClass(request);
45-
willReturn("doSomething").given(getter).methodName(request);
44+
doReturn(anon.getClass()).when(getter).codeClass(request);
45+
doReturn("doSomething").when(getter).methodName(request);
4646

4747
SpanNameExtractor<Object> underTest = CodeSpanNameExtractor.create(getter);
4848

@@ -59,8 +59,8 @@ void shouldExtractFullSpanNameForLambda() {
5959
Runnable lambda = () -> {};
6060
Object request = new Object();
6161

62-
willReturn(lambda.getClass()).given(getter).codeClass(request);
63-
willReturn("doSomething").given(getter).methodName(request);
62+
doReturn(lambda.getClass()).when(getter).codeClass(request);
63+
doReturn("doSomething").when(getter).methodName(request);
6464

6565
SpanNameExtractor<Object> underTest = CodeSpanNameExtractor.create(getter);
6666

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbClientSpanNameExtractorTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.opentelemetry.instrumentation.api.instrumenter.db;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.mockito.BDDMockito.given;
9+
import static org.mockito.Mockito.when;
1010

1111
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
1212
import org.junit.jupiter.api.Test;
@@ -24,8 +24,8 @@ void shouldExtractFullSpanName() {
2424
// given
2525
DbRequest dbRequest = new DbRequest();
2626

27-
given(sqlAttributesGetter.rawStatement(dbRequest)).willReturn("SELECT * from table");
28-
given(sqlAttributesGetter.name(dbRequest)).willReturn("database");
27+
when(sqlAttributesGetter.rawStatement(dbRequest)).thenReturn("SELECT * from table");
28+
when(sqlAttributesGetter.name(dbRequest)).thenReturn("database");
2929

3030
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter);
3131

@@ -41,8 +41,8 @@ void shouldSkipDbNameIfTableAlreadyHasDbNamePrefix() {
4141
// given
4242
DbRequest dbRequest = new DbRequest();
4343

44-
given(sqlAttributesGetter.rawStatement(dbRequest)).willReturn("SELECT * from another.table");
45-
given(sqlAttributesGetter.name(dbRequest)).willReturn("database");
44+
when(sqlAttributesGetter.rawStatement(dbRequest)).thenReturn("SELECT * from another.table");
45+
when(sqlAttributesGetter.name(dbRequest)).thenReturn("database");
4646

4747
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter);
4848

@@ -58,7 +58,7 @@ void shouldExtractOperationAndTable() {
5858
// given
5959
DbRequest dbRequest = new DbRequest();
6060

61-
given(sqlAttributesGetter.rawStatement(dbRequest)).willReturn("SELECT * from table");
61+
when(sqlAttributesGetter.rawStatement(dbRequest)).thenReturn("SELECT * from table");
6262

6363
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(sqlAttributesGetter);
6464

@@ -74,8 +74,8 @@ void shouldExtractOperationAndName() {
7474
// given
7575
DbRequest dbRequest = new DbRequest();
7676

77-
given(dbAttributesGetter.operation(dbRequest)).willReturn("SELECT");
78-
given(dbAttributesGetter.name(dbRequest)).willReturn("database");
77+
when(dbAttributesGetter.operation(dbRequest)).thenReturn("SELECT");
78+
when(dbAttributesGetter.name(dbRequest)).thenReturn("database");
7979

8080
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(dbAttributesGetter);
8181

@@ -91,7 +91,7 @@ void shouldExtractOperation() {
9191
// given
9292
DbRequest dbRequest = new DbRequest();
9393

94-
given(dbAttributesGetter.operation(dbRequest)).willReturn("SELECT");
94+
when(dbAttributesGetter.operation(dbRequest)).thenReturn("SELECT");
9595

9696
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(dbAttributesGetter);
9797

@@ -107,7 +107,7 @@ void shouldExtractDbName() {
107107
// given
108108
DbRequest dbRequest = new DbRequest();
109109

110-
given(dbAttributesGetter.name(dbRequest)).willReturn("database");
110+
when(dbAttributesGetter.name(dbRequest)).thenReturn("database");
111111

112112
SpanNameExtractor<DbRequest> underTest = DbClientSpanNameExtractor.create(dbAttributesGetter);
113113

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingSpanNameExtractorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.opentelemetry.instrumentation.api.instrumenter.messaging;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.mockito.BDDMockito.given;
9+
import static org.mockito.Mockito.when;
1010

1111
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
1212
import java.util.stream.Stream;
@@ -33,9 +33,9 @@ void shouldExtractSpanName(
3333
Message message = new Message();
3434

3535
if (isTemporaryQueue) {
36-
given(getter.temporaryDestination(message)).willReturn(true);
36+
when(getter.temporaryDestination(message)).thenReturn(true);
3737
} else {
38-
given(getter.destination(message)).willReturn(destinationName);
38+
when(getter.destination(message)).thenReturn(destinationName);
3939
}
4040

4141
SpanNameExtractor<Message> underTest = MessagingSpanNameExtractor.create(getter, operation);

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static org.assertj.core.api.Assertions.entry;
1111
import static org.junit.jupiter.api.Assertions.assertTrue;
1212
import static org.mockito.ArgumentMatchers.any;
13-
import static org.mockito.BDDMockito.given;
13+
import static org.mockito.Mockito.when;
1414

1515
import io.opentelemetry.api.common.Attributes;
1616
import io.opentelemetry.api.common.AttributesBuilder;
@@ -54,7 +54,7 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() {
5454
PeerServiceAttributesExtractor<String, String> underTest =
5555
new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping);
5656

57-
given(netAttributesExtractor.peerName(any(), any())).willReturn("example2.com");
57+
when(netAttributesExtractor.peerName(any(), any())).thenReturn("example2.com");
5858

5959
Context context = Context.root();
6060

@@ -79,7 +79,7 @@ void shouldSetPeerNameIfItMatches() {
7979
PeerServiceAttributesExtractor<String, String> underTest =
8080
new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping);
8181

82-
given(netAttributesExtractor.peerName(any(), any())).willReturn("example.com");
82+
when(netAttributesExtractor.peerName(any(), any())).thenReturn("example.com");
8383

8484
Context context = Context.root();
8585

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Objects.requireNonNull;
99

10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1011
import io.opentelemetry.api.OpenTelemetry;
1112
import io.opentelemetry.api.metrics.Meter;
1213
import io.opentelemetry.api.metrics.MeterBuilder;
@@ -78,6 +79,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
7879
* @param instrumentationVersion is the version of the instrumentation library, not the version of
7980
* the instrument<b>ed</b> library.
8081
*/
82+
@CanIgnoreReturnValue
8183
public InstrumenterBuilder<REQUEST, RESPONSE> setInstrumentationVersion(
8284
String instrumentationVersion) {
8385
this.instrumentationVersion = requireNonNull(instrumentationVersion, "instrumentationVersion");
@@ -88,6 +90,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setInstrumentationVersion(
8890
* Sets the OpenTelemetry schema URL that will be associated with all telemetry produced by this
8991
* {@link Instrumenter}.
9092
*/
93+
@CanIgnoreReturnValue
9194
public InstrumenterBuilder<REQUEST, RESPONSE> setSchemaUrl(String schemaUrl) {
9295
this.schemaUrl = requireNonNull(schemaUrl, "schemaUrl");
9396
return this;
@@ -96,6 +99,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setSchemaUrl(String schemaUrl) {
9699
/**
97100
* Sets the {@link SpanStatusExtractor} that will determine the {@link StatusCode} for a response.
98101
*/
102+
@CanIgnoreReturnValue
99103
public InstrumenterBuilder<REQUEST, RESPONSE> setSpanStatusExtractor(
100104
SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor) {
101105
this.spanStatusExtractor = requireNonNull(spanStatusExtractor, "spanStatusExtractor");
@@ -105,13 +109,15 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setSpanStatusExtractor(
105109
/**
106110
* Adds a {@link AttributesExtractor} that will extract attributes from requests and responses.
107111
*/
112+
@CanIgnoreReturnValue
108113
public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractor(
109114
AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) {
110115
this.attributesExtractors.add(requireNonNull(attributesExtractor, "attributesExtractor"));
111116
return this;
112117
}
113118

114119
/** Adds {@link AttributesExtractor}s that will extract attributes from requests and responses. */
120+
@CanIgnoreReturnValue
115121
public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractors(
116122
Iterable<? extends AttributesExtractor<? super REQUEST, ? super RESPONSE>>
117123
attributesExtractors) {
@@ -120,6 +126,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractors(
120126
}
121127

122128
/** Adds a {@link SpanLinksExtractor} that will extract span links from requests. */
129+
@CanIgnoreReturnValue
123130
public InstrumenterBuilder<REQUEST, RESPONSE> addSpanLinksExtractor(
124131
SpanLinksExtractor<REQUEST> spanLinksExtractor) {
125132
spanLinksExtractors.add(requireNonNull(spanLinksExtractor, "spanLinksExtractor"));
@@ -130,6 +137,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addSpanLinksExtractor(
130137
* Adds a {@link ContextCustomizer} that will customize the context during {@link
131138
* Instrumenter#start(Context, Object)}.
132139
*/
140+
@CanIgnoreReturnValue
133141
public InstrumenterBuilder<REQUEST, RESPONSE> addContextCustomizer(
134142
ContextCustomizer<? super REQUEST> contextCustomizer) {
135143
contextCustomizers.add(requireNonNull(contextCustomizer, "contextCustomizer"));
@@ -140,6 +148,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addContextCustomizer(
140148
* Adds a {@link OperationListener} that will be called when an instrumented operation starts and
141149
* ends.
142150
*/
151+
@CanIgnoreReturnValue
143152
public InstrumenterBuilder<REQUEST, RESPONSE> addOperationListener(OperationListener listener) {
144153
operationListeners.add(requireNonNull(listener, "operationListener"));
145154
return this;
@@ -149,6 +158,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addOperationListener(OperationList
149158
* Adds a {@link OperationMetrics} that will produce a {@link OperationListener} capturing the
150159
* requests processing metrics.
151160
*/
161+
@CanIgnoreReturnValue
152162
public InstrumenterBuilder<REQUEST, RESPONSE> addOperationMetrics(OperationMetrics factory) {
153163
operationMetrics.add(requireNonNull(factory, "operationMetrics"));
154164
return this;
@@ -158,6 +168,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addOperationMetrics(OperationMetri
158168
* Sets the {@link ErrorCauseExtractor} that will extract the root cause of an error thrown during
159169
* request processing.
160170
*/
171+
@CanIgnoreReturnValue
161172
public InstrumenterBuilder<REQUEST, RESPONSE> setErrorCauseExtractor(
162173
ErrorCauseExtractor errorCauseExtractor) {
163174
this.errorCauseExtractor = requireNonNull(errorCauseExtractor, "errorCauseExtractor");
@@ -168,6 +179,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setErrorCauseExtractor(
168179
* Allows enabling/disabling the {@link Instrumenter} based on the {@code enabled} value passed as
169180
* parameter. All instrumenters are enabled by default.
170181
*/
182+
@CanIgnoreReturnValue
171183
public InstrumenterBuilder<REQUEST, RESPONSE> setEnabled(boolean enabled) {
172184
this.enabled = enabled;
173185
return this;

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanLinksBuilderImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.api.instrumenter;
77

8+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
89
import io.opentelemetry.api.common.Attributes;
910
import io.opentelemetry.api.trace.SpanBuilder;
1011
import io.opentelemetry.api.trace.SpanContext;
@@ -17,12 +18,14 @@ final class SpanLinksBuilderImpl implements SpanLinksBuilder {
1718
}
1819

1920
@Override
21+
@CanIgnoreReturnValue
2022
public SpanLinksBuilder addLink(SpanContext spanContext) {
2123
spanBuilder.addLink(spanContext);
2224
return this;
2325
}
2426

2527
@Override
28+
@CanIgnoreReturnValue
2629
public SpanLinksBuilder addLink(SpanContext spanContext, Attributes attributes) {
2730
spanBuilder.addLink(spanContext, attributes);
2831
return this;

0 commit comments

Comments
 (0)