Skip to content

Commit

Permalink
Intellij cleanup (Java and Groovy) (#3285)
Browse files Browse the repository at this point in the history
* Intellij cleanup

* Update instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeAttributesExtractorTest.java

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>

* Update instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>

* Update instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>

* Update instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>

* Update instrumentation/spring/spring-web-3.1/library/src/test/java/io/opentelemetry/instrumentation/spring/httpclients/RestTemplateInterceptorTest.java

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>

* Use glassfish version that supports lambdas

Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
  • Loading branch information
trask and anuraaga authored Jun 14, 2021
1 parent fbb1a35 commit 62f1f49
Show file tree
Hide file tree
Showing 57 changed files with 241 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ public void configure() {
.collect(Collectors.toList());

TaskProvider<?> byteBuddyTask =
project
.getTasks()
.register(
taskName,
task -> {
task.dependsOn(languageTasks);
});
project.getTasks().register(taskName, task -> task.dependsOn(languageTasks));

project
.getTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ private Span internalStartSpan(
spanBuilder.setStartTimestamp(startTimeNanos, TimeUnit.NANOSECONDS);
}
onRequest(spanBuilder, request);
Span span = spanBuilder.startSpan();
return span;
return spanBuilder.startSpan();
}

protected void onRequest(SpanBuilder spanBuilder, REQUEST request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void unbounded() {
}

@Test
void bounded() throws Exception {
void bounded() {
Cache<String, String> cache = Cache.newBuilder().setWeakKeys().setMaximumSize(1).build();

assertThat(cache.computeIfAbsent("bear", unused -> "roar")).isEqualTo("roar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class CodeAttributesExtractorTest {

CodeAttributesExtractor<Map<String, String>, Void> underTest =
static final CodeAttributesExtractor<Map<String, String>, Void> underTest =
new CodeAttributesExtractor<Map<String, String>, Void>() {
@Override
protected Class<?> codeClass(Map<String, String> request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.jupiter.api.Test;

class DbAttributesExtractorTest {
DbAttributesExtractor<Map<String, String>, Void> underTest =
static final DbAttributesExtractor<Map<String, String>, Void> underTest =
new DbAttributesExtractor<Map<String, String>, Void>() {
@Override
protected String system(Map<String, String> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class SqlAttributesExtractorTest {
AttributeKey<String> dbTableAttribute;
SqlAttributesExtractor<Map<String, String>, Void> underTest =
final SqlAttributesExtractor<Map<String, String>, Void> underTest =
new SqlAttributesExtractor<Map<String, String>, Void>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.junit.jupiter.params.provider.MethodSource;

class MessagingAttributesExtractorTest {
MessagingAttributesExtractor<Map<String, String>, String> underTest =
static final MessagingAttributesExtractor<Map<String, String>, String> underTest =
new MessagingAttributesExtractor<Map<String, String>, String>() {
@Override
protected String system(Map<String, String> request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public Iterable<String> keys(HttpRequest httpRequest) {
@Override
public String get(HttpRequest carrier, String key) {
Optional<HttpHeader> header = carrier.getHeader(key);
if (header.isPresent()) {
return header.get().value();
} else {
return null;
}
return header.map(HttpHeader::value).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

public enum CamelDirection {
INBOUND,
OUTBOUND;
OUTBOUND
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,18 @@ private static void onExchangeSending(ExchangeSendingEvent ese) {

/** Camel finished sending (outbound). Finish span and remove it from CAMEL holder. */
private static void onExchangeSent(ExchangeSentEvent event) {
ExchangeSentEvent ese = event;
SpanDecorator sd = CamelTracer.TRACER.getSpanDecorator(ese.getEndpoint());
SpanDecorator sd = CamelTracer.TRACER.getSpanDecorator(event.getEndpoint());
if (!sd.shouldStartNewSpan()) {
return;
}

Span span = ActiveSpanManager.getSpan(ese.getExchange());
Span span = ActiveSpanManager.getSpan(event.getExchange());
if (span != null) {
LOG.debug("[Exchange sent] Initiator span finished: {}", span);
sd.post(span, ese.getExchange(), ese.getEndpoint());
ActiveSpanManager.deactivate(ese.getExchange());
sd.post(span, event.getExchange(), event.getEndpoint());
ActiveSpanManager.deactivate(event.getExchange());
} else {
LOG.warn("Could not find managed span for exchange: {}", ese.getExchange());
LOG.warn("Could not find managed span for exchange: {}", event.getExchange());
}
}

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

package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
Expand All @@ -20,6 +20,6 @@ public ApacheHttpAsyncClientInstrumentationModule() {

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(new ApacheHttpAsyncClientInstrumentation());
return singletonList(new ApacheHttpAsyncClientInstrumentation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Ex
if (span.isRecording()) {
ctx.log()
.whenComplete()
.thenAccept(
log -> {
instrumenter.end(context, ctx, log, log.responseCause());
});
.thenAccept(log -> instrumenter.end(context, ctx, log, log.responseCause()));
}

try (Scope ignored = context.makeCurrent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private WrapperConfiguration() {}
"OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT";
public static final Duration OTEL_LAMBDA_FLUSH_TIMEOUT_DEFAULT = Duration.ofSeconds(10);

public static final Duration flushTimeout() {
public static Duration flushTimeout() {
String lambdaFlushTimeout = System.getenv(OTEL_LAMBDA_FLUSH_TIMEOUT_ENV_KEY);
if (lambdaFlushTimeout != null && !lambdaFlushTimeout.isEmpty()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,12 @@ public void onResponse(Span span, Response<?> response) {

private String qualifiedOperation(String service, Class<?> operation) {
ConcurrentHashMap<String, String> cache = namesCache.get(operation);
String qualified = cache.get(service);
if (qualified == null) {
qualified =
service.replace("Amazon", "").trim()
+ '.'
+ operation.getSimpleName().replace("Request", "");
cache.put(service, qualified);
}
return qualified;
return cache.computeIfAbsent(
service,
s ->
s.replace("Amazon", "").trim()
+ '.'
+ operation.getSimpleName().replace("Request", ""));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FieldMapping {

enum Type {
REQUEST,
RESPONSE;
RESPONSE
}

private final Type type;
Expand Down Expand Up @@ -49,7 +49,7 @@ Type getType() {
return type;
}

static final Map<Type, List<FieldMapping>> groupByType(FieldMapping[] fieldMappings) {
static Map<Type, List<FieldMapping>> groupByType(FieldMapping[] fieldMappings) {

EnumMap<Type, List<FieldMapping>> fields = new EnumMap<>(Type.class);
for (FieldMapping.Type type : FieldMapping.Type.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void shouldSerializeCollection() {
@Test
public void shouldSerializeEmptyCollectionAsNull() {
// given
List<String> collection = Arrays.asList();
List<String> collection = Collections.emptyList();
// when
String serialized = new Serializer().serialize(collection);
// then
Expand All @@ -62,7 +63,7 @@ public void shouldSerializeEmptyCollectionAsNull() {
public void shouldSerializeMapAsKeyCollection() {
// given
Map<String, Object> map = new HashMap<>();
map.put("uno", Long.valueOf(1));
map.put("uno", 1L);
map.put("dos", new LinkedHashMap<>());
map.put("tres", "cuatro");
// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ public CompletionStage<AsyncResultSet> executeAsync(Statement<?> statement) {
try (Scope ignored = context.makeCurrent()) {
CompletionStage<AsyncResultSet> stage = session.executeAsync(statement);
return stage.whenComplete(
(asyncResultSet, throwable) -> {
instrumenter()
.end(context, request, getExecutionInfo(asyncResultSet, throwable), throwable);
});
(asyncResultSet, throwable) ->
instrumenter()
.end(context, request, getExecutionInfo(asyncResultSet, throwable), throwable));
}
}

Expand All @@ -206,10 +205,9 @@ public CompletionStage<AsyncResultSet> executeAsync(String query) {
try (Scope ignored = context.makeCurrent()) {
CompletionStage<AsyncResultSet> stage = session.executeAsync(query);
return stage.whenComplete(
(asyncResultSet, throwable) -> {
instrumenter()
.end(context, request, getExecutionInfo(asyncResultSet, throwable), throwable);
});
(asyncResultSet, throwable) ->
instrumenter()
.end(context, request, getExecutionInfo(asyncResultSet, throwable), throwable));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
name "GetAction"
kind CLIENT
status ERROR
errorEvent IndexNotFoundException, ~/no such index( \[invalid-index\])?/
errorEvent IndexNotFoundException, ~/no such index( \[invalid-index])?/
attributes {
"${SemanticAttributes.DB_SYSTEM.key}" "elasticsearch"
"${SemanticAttributes.DB_OPERATION.key}" "GetAction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public GrpcTracing build() {
.addAttributesExtractors(
new GrpcNetAttributesExtractor(),
new GrpcRpcAttributesExtractor(),
new GrpcAttributesExtractor());
new GrpcAttributesExtractor())
.addAttributesExtractors(additionalExtractors);
return new GrpcTracing(
instrumenterBuilder.newServerInstrumenter(GrpcExtractAdapter.GETTER),
// gRPC client interceptors require two phases, one to set up request and one to execute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import java.io.IOException;
import test.gwt.shared.MessageService;
import test.gwt.shared.MessageServiceAsync;

Expand Down Expand Up @@ -50,25 +49,21 @@ private void sendMessageToServer() {
messageLabel.setText("");
messageLabel.setStyleName("");

try {
messageServiceAsync.sendMessage(
message,
new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
messageLabel.setText("Error");
messageLabel.addStyleName("error.received");
}
messageServiceAsync.sendMessage(
message,
new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
messageLabel.setText("Error");
messageLabel.addStyleName("error.received");
}

@Override
public void onSuccess(String result) {
messageLabel.setText(result);
messageLabel.addStyleName("message.received");
}
});
} catch (IOException e) {
throw new IllegalStateException(e);
}
@Override
public void onSuccess(String result) {
messageLabel.setText(result);
messageLabel.addStyleName("message.received");
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
package test.gwt.shared;

import com.google.gwt.user.client.rpc.AsyncCallback;
import java.io.IOException;

/** The async counterpart of <code>MessageService</code>. */
public interface MessageServiceAsync {
void sendMessage(String input, AsyncCallback<String> callback) throws IOException;
void sendMessage(String input, AsyncCallback<String> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName(.*)from Customer(.*)/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName(.*)from Customer(.*)/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down Expand Up @@ -109,7 +109,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)where ([^.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)(where ([^\.]+)\.lastName( ?)=( ?)\?|)/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)(where ([^.]+)\.lastName( ?)=( ?)\?|)/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand All @@ -172,7 +172,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)where ([^.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName(.*)from Customer(.*)/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName(.*)from Customer(.*)/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down Expand Up @@ -109,7 +109,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)where ([^.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)(where ([^\.]+)\.lastName( ?)=( ?)\?|)/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)(where ([^.]+)\.lastName( ?)=( ?)\?|)/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand All @@ -172,7 +172,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^.]+)\.id([^,]*), ([^.]+)\.firstName([^,]*), ([^.]+)\.lastName (.*)from Customer (.*)where ([^.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_OPERATION.key}" "SELECT"
"${SemanticAttributes.DB_SQL_TABLE.key}" "Customer"
}
Expand Down
Loading

0 comments on commit 62f1f49

Please sign in to comment.