Skip to content

Commit

Permalink
Update error prone (#6646)
Browse files Browse the repository at this point in the history
(note that change from BDDMockito is due to
google/error-prone#3396)
  • Loading branch information
trask committed Sep 23, 2022
1 parent 557c6d1 commit 429ecfc
Show file tree
Hide file tree
Showing 79 changed files with 382 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ dependencies {
components.all<NettyAlignmentRule>()

compileOnly("com.google.code.findbugs:jsr305")
compileOnly("com.google.errorprone:error_prone_annotations")

codenarc("org.codenarc:CodeNarc:2.2.0")
codenarc(platform("org.codehaus.groovy:groovy-bom:3.0.9"))
Expand Down
6 changes: 3 additions & 3 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ val CORE_DEPENDENCIES = listOf(
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.value:auto-value:1.9",
"com.google.auto.value:auto-value-annotations:1.9",
"com.google.errorprone:error_prone_annotations:2.14.0",
"com.google.errorprone:error_prone_core:2.14.0",
"com.google.errorprone:error_prone_test_helpers:2.14.0",
"com.google.errorprone:error_prone_annotations:2.15.0",
"com.google.errorprone:error_prone_core:2.15.0",
"com.google.errorprone:error_prone_test_helpers:2.15.0",
// When updating, also update conventions/build.gradle.kts
"net.bytebuddy:byte-buddy:1.12.17",
"net.bytebuddy:byte-buddy-dep:1.12.17",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Objects.requireNonNull;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.db.SqlStatementSanitizer;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand All @@ -30,6 +31,7 @@ public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
* @param dbTableAttribute The {@link AttributeKey} under which the table extracted by the {@link
* SqlClientAttributesExtractor} will be stored.
*/
@CanIgnoreReturnValue
public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setTableAttribute(
AttributeKey<String> dbTableAttribute) {
this.dbTableAttribute = requireNonNull(dbTableAttribute);
Expand All @@ -41,6 +43,7 @@ public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setTableAttribute(
* SqlClientAttributesExtractor} should be sanitized. If set to {@code true}, all parameters that
* can potentially contain sensitive information will be masked. Enabled by default.
*/
@CanIgnoreReturnValue
public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setStatementSanitizationEnabled(
boolean statementSanitizationEnabled) {
this.statementSanitizationEnabled = statementSanitizationEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Collections.emptyList;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;

/** A builder of {@link HttpClientAttributesExtractor}. */
Expand All @@ -31,6 +32,7 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
*
* @param requestHeaders A list of HTTP header names.
*/
@CanIgnoreReturnValue
public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
List<String> requestHeaders) {
this.capturedRequestHeaders = requestHeaders;
Expand All @@ -49,6 +51,7 @@ public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedReques
*
* @param responseHeaders A list of HTTP header names.
*/
@CanIgnoreReturnValue
public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
List<String> responseHeaders) {
this.capturedResponseHeaders = responseHeaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Collections.emptyList;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;

/** A builder of {@link HttpServerAttributesExtractor}. */
Expand All @@ -31,6 +32,7 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
*
* @param requestHeaders A list of HTTP header names.
*/
@CanIgnoreReturnValue
public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
List<String> requestHeaders) {
this.capturedRequestHeaders = requestHeaders;
Expand All @@ -49,6 +51,7 @@ public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedReques
*
* @param responseHeaders A list of HTTP header names.
*/
@CanIgnoreReturnValue
public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
List<String> responseHeaders) {
this.capturedResponseHeaders = responseHeaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Collections.emptyList;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;

/** A builder of {@link MessagingAttributesExtractor}. */
Expand All @@ -31,6 +32,7 @@ public final class MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> {
*
* @param capturedHeaders A list of messaging header names.
*/
@CanIgnoreReturnValue
public MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedHeaders(
List<String> capturedHeaders) {
this.capturedHeaders = capturedHeaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.instrumentation.api.instrumenter.code;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.doReturn;

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

willReturn(TestClass.class).given(getter).codeClass(request);
willReturn("doSomething").given(getter).methodName(request);
doReturn(TestClass.class).when(getter).codeClass(request);
doReturn("doSomething").when(getter).methodName(request);

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

Expand All @@ -41,8 +41,8 @@ void shouldExtractFullSpanNameForAnonymousClass() {
AnonymousBaseClass anon = new AnonymousBaseClass() {};
Object request = new Object();

willReturn(anon.getClass()).given(getter).codeClass(request);
willReturn("doSomething").given(getter).methodName(request);
doReturn(anon.getClass()).when(getter).codeClass(request);
doReturn("doSomething").when(getter).methodName(request);

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

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

willReturn(lambda.getClass()).given(getter).codeClass(request);
willReturn("doSomething").given(getter).methodName(request);
doReturn(lambda.getClass()).when(getter).codeClass(request);
doReturn("doSomething").when(getter).methodName(request);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.instrumentation.api.instrumenter.db;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;

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

given(sqlAttributesGetter.rawStatement(dbRequest)).willReturn("SELECT * from table");
given(sqlAttributesGetter.name(dbRequest)).willReturn("database");
when(sqlAttributesGetter.rawStatement(dbRequest)).thenReturn("SELECT * from table");
when(sqlAttributesGetter.name(dbRequest)).thenReturn("database");

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

Expand All @@ -41,8 +41,8 @@ void shouldSkipDbNameIfTableAlreadyHasDbNamePrefix() {
// given
DbRequest dbRequest = new DbRequest();

given(sqlAttributesGetter.rawStatement(dbRequest)).willReturn("SELECT * from another.table");
given(sqlAttributesGetter.name(dbRequest)).willReturn("database");
when(sqlAttributesGetter.rawStatement(dbRequest)).thenReturn("SELECT * from another.table");
when(sqlAttributesGetter.name(dbRequest)).thenReturn("database");

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

Expand All @@ -58,7 +58,7 @@ void shouldExtractOperationAndTable() {
// given
DbRequest dbRequest = new DbRequest();

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

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

Expand All @@ -74,8 +74,8 @@ void shouldExtractOperationAndName() {
// given
DbRequest dbRequest = new DbRequest();

given(dbAttributesGetter.operation(dbRequest)).willReturn("SELECT");
given(dbAttributesGetter.name(dbRequest)).willReturn("database");
when(dbAttributesGetter.operation(dbRequest)).thenReturn("SELECT");
when(dbAttributesGetter.name(dbRequest)).thenReturn("database");

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

Expand All @@ -91,7 +91,7 @@ void shouldExtractOperation() {
// given
DbRequest dbRequest = new DbRequest();

given(dbAttributesGetter.operation(dbRequest)).willReturn("SELECT");
when(dbAttributesGetter.operation(dbRequest)).thenReturn("SELECT");

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

Expand All @@ -107,7 +107,7 @@ void shouldExtractDbName() {
// given
DbRequest dbRequest = new DbRequest();

given(dbAttributesGetter.name(dbRequest)).willReturn("database");
when(dbAttributesGetter.name(dbRequest)).thenReturn("database");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.instrumentation.api.instrumenter.messaging;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;

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

if (isTemporaryQueue) {
given(getter.temporaryDestination(message)).willReturn(true);
when(getter.temporaryDestination(message)).thenReturn(true);
} else {
given(getter.destination(message)).willReturn(destinationName);
when(getter.destination(message)).thenReturn(destinationName);
}

SpanNameExtractor<Message> underTest = MessagingSpanNameExtractor.create(getter, operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
Expand Down Expand Up @@ -54,7 +54,7 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() {
PeerServiceAttributesExtractor<String, String> underTest =
new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping);

given(netAttributesExtractor.peerName(any(), any())).willReturn("example2.com");
when(netAttributesExtractor.peerName(any(), any())).thenReturn("example2.com");

Context context = Context.root();

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

given(netAttributesExtractor.peerName(any(), any())).willReturn("example.com");
when(netAttributesExtractor.peerName(any(), any())).thenReturn("example.com");

Context context = Context.root();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Objects.requireNonNull;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.MeterBuilder;
Expand Down Expand Up @@ -78,6 +79,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
* @param instrumentationVersion is the version of the instrumentation library, not the version of
* the instrument<b>ed</b> library.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> setInstrumentationVersion(
String instrumentationVersion) {
this.instrumentationVersion = requireNonNull(instrumentationVersion, "instrumentationVersion");
Expand All @@ -88,6 +90,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setInstrumentationVersion(
* Sets the OpenTelemetry schema URL that will be associated with all telemetry produced by this
* {@link Instrumenter}.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> setSchemaUrl(String schemaUrl) {
this.schemaUrl = requireNonNull(schemaUrl, "schemaUrl");
return this;
Expand All @@ -96,6 +99,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setSchemaUrl(String schemaUrl) {
/**
* Sets the {@link SpanStatusExtractor} that will determine the {@link StatusCode} for a response.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> setSpanStatusExtractor(
SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor) {
this.spanStatusExtractor = requireNonNull(spanStatusExtractor, "spanStatusExtractor");
Expand All @@ -105,13 +109,15 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setSpanStatusExtractor(
/**
* Adds a {@link AttributesExtractor} that will extract attributes from requests and responses.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractor(
AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) {
this.attributesExtractors.add(requireNonNull(attributesExtractor, "attributesExtractor"));
return this;
}

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

/** Adds a {@link SpanLinksExtractor} that will extract span links from requests. */
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> addSpanLinksExtractor(
SpanLinksExtractor<REQUEST> spanLinksExtractor) {
spanLinksExtractors.add(requireNonNull(spanLinksExtractor, "spanLinksExtractor"));
Expand All @@ -130,6 +137,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addSpanLinksExtractor(
* Adds a {@link ContextCustomizer} that will customize the context during {@link
* Instrumenter#start(Context, Object)}.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> addContextCustomizer(
ContextCustomizer<? super REQUEST> contextCustomizer) {
contextCustomizers.add(requireNonNull(contextCustomizer, "contextCustomizer"));
Expand All @@ -140,6 +148,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addContextCustomizer(
* Adds a {@link OperationListener} that will be called when an instrumented operation starts and
* ends.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> addOperationListener(OperationListener listener) {
operationListeners.add(requireNonNull(listener, "operationListener"));
return this;
Expand All @@ -149,6 +158,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addOperationListener(OperationList
* Adds a {@link OperationMetrics} that will produce a {@link OperationListener} capturing the
* requests processing metrics.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> addOperationMetrics(OperationMetrics factory) {
operationMetrics.add(requireNonNull(factory, "operationMetrics"));
return this;
Expand All @@ -158,6 +168,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addOperationMetrics(OperationMetri
* Sets the {@link ErrorCauseExtractor} that will extract the root cause of an error thrown during
* request processing.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> setErrorCauseExtractor(
ErrorCauseExtractor errorCauseExtractor) {
this.errorCauseExtractor = requireNonNull(errorCauseExtractor, "errorCauseExtractor");
Expand All @@ -168,6 +179,7 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setErrorCauseExtractor(
* Allows enabling/disabling the {@link Instrumenter} based on the {@code enabled} value passed as
* parameter. All instrumenters are enabled by default.
*/
@CanIgnoreReturnValue
public InstrumenterBuilder<REQUEST, RESPONSE> setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.api.instrumenter;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanContext;
Expand All @@ -17,12 +18,14 @@ final class SpanLinksBuilderImpl implements SpanLinksBuilder {
}

@Override
@CanIgnoreReturnValue
public SpanLinksBuilder addLink(SpanContext spanContext) {
spanBuilder.addLink(spanContext);
return this;
}

@Override
@CanIgnoreReturnValue
public SpanLinksBuilder addLink(SpanContext spanContext, Attributes attributes) {
spanBuilder.addLink(spanContext, attributes);
return this;
Expand Down
Loading

0 comments on commit 429ecfc

Please sign in to comment.