Skip to content

Commit f6545a4

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

14 files changed

Lines changed: 74 additions & 81 deletions

File tree

instrumentation/spark-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sparkjava/RoutesInstrumentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1414
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
15+
import javax.annotation.Nullable;
1516
import net.bytebuddy.asm.Advice;
1617
import net.bytebuddy.description.type.TypeDescription;
1718
import net.bytebuddy.matcher.ElementMatcher;
@@ -37,7 +38,7 @@ public void transform(TypeTransformer transformer) {
3738
public static class FindAdvice {
3839

3940
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
40-
public static void routeMatchEnricher(@Advice.Return RouteMatch routeMatch) {
41+
public static void routeMatchEnricher(@Advice.Return @Nullable RouteMatch routeMatch) {
4142
SparkRouteUpdater.updateHttpRoute(routeMatch);
4243
}
4344
}

instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class SparkJavaBasedTest {
3737
@RegisterExtension
3838
private static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
3939

40-
static int port;
41-
static WebClient client;
40+
private static int port;
41+
private static WebClient client;
4242

4343
@BeforeAll
4444
static void setup() {

instrumentation/spring/spring-batch-3.0/metadata.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ description: >
66
library_link: https://spring.io/projects/spring-batch
77
configurations:
88
- name: otel.instrumentation.spring-batch.experimental-span-attributes
9+
declarative_name: java.spring_batch.experimental_span_attributes/development
910
type: boolean
1011
description: Adds the experimental attribute `job.system` to spans.
1112
default: false
1213
- name: otel.instrumentation.spring-batch.experimental.chunk.new-trace
14+
declarative_name: java.spring_batch.chunk/development.new_trace
1315
type: boolean
1416
description: When enabled, a new root span will be created for each chunk processing. Please note that this may lead to a high number of spans being created.
1517
default: false
1618
- name: otel.instrumentation.spring-batch.item.enabled
19+
declarative_name: java.spring_batch.item.enabled
1720
type: boolean
1821
description: When enabled, spans will be created for each item processed. Please note that this may lead to a high number of spans being created.
1922
default: false

instrumentation/spring/spring-boot-actuator-autoconfigure-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/actuator/v2_0/ActuatorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ void shouldInjectOtelMeterRegistry() {
6060
Set<MeterRegistry> registries = ((CompositeMeterRegistry) meterRegistry).getRegistries();
6161
ArrayList<MeterRegistry> list = new ArrayList<>(registries);
6262

63-
String last = list.get(list.size() - 1).getClass().getSimpleName();
64-
assertThat(last).isEqualTo("OpenTelemetryMeterRegistry");
63+
assertThat(list)
64+
.extracting(registry -> registry.getClass().getSimpleName())
65+
.endsWith("OpenTelemetryMeterRegistry");
6566
}
6667
}

instrumentation/spring/spring-boot-autoconfigure/testing/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/AbstractKafkaInstrumentationAutoConfigurationTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,39 @@ void instrumentationDisabled() {
2929
contextRunner
3030
.withPropertyValues("otel.instrumentation.kafka.enabled=false")
3131
.run(
32-
context -> {
33-
assertThat(context.containsBean("otelKafkaProducerFactoryCustomizer")).isFalse();
34-
assertThat(context.containsBean("otelKafkaListenerContainerFactoryBeanPostProcessor"))
35-
.isFalse();
36-
});
32+
context ->
33+
assertThat(context)
34+
.doesNotHaveBean("otelKafkaProducerFactoryCustomizer")
35+
.doesNotHaveBean("otelKafkaListenerContainerFactoryBeanPostProcessor"));
3736
}
3837

3938
@Test
4039
void listenerInterceptorCanBeDisabled() {
4140
contextRunner
4241
.withPropertyValues("otel.instrumentation.kafka.autoconfigure-interceptor=false")
4342
.run(
44-
context -> {
45-
assertThat(context.containsBean("otelKafkaProducerFactoryCustomizer")).isTrue();
46-
assertThat(context.containsBean("otelKafkaListenerContainerFactoryBeanPostProcessor"))
47-
.isFalse();
48-
});
43+
context ->
44+
assertThat(context)
45+
.hasBean("otelKafkaProducerFactoryCustomizer")
46+
.doesNotHaveBean("otelKafkaListenerContainerFactoryBeanPostProcessor"));
4947
}
5048

5149
@Test
5250
void defaultConfiguration() {
5351
contextRunner.run(
54-
context -> {
55-
assertThat(context.containsBean("otelKafkaProducerFactoryCustomizer")).isTrue();
56-
assertThat(context.containsBean("otelKafkaListenerContainerFactoryBeanPostProcessor"))
57-
.isTrue();
58-
});
52+
context ->
53+
assertThat(context)
54+
.hasBean("otelKafkaProducerFactoryCustomizer")
55+
.hasBean("otelKafkaListenerContainerFactoryBeanPostProcessor"));
5956
}
6057

6158
@Test
6259
void defaultConfigurationWithFactoryTesting() {
6360
contextRunner.run(
6461
context -> {
65-
assertThat(context.containsBean("otelKafkaProducerFactoryCustomizer")).isTrue();
66-
assertThat(context.containsBean("otelKafkaListenerContainerFactoryBeanPostProcessor"))
67-
.isTrue();
62+
assertThat(context)
63+
.hasBean("otelKafkaProducerFactoryCustomizer")
64+
.hasBean("otelKafkaListenerContainerFactoryBeanPostProcessor");
6865

6966
factoryTestAssertion(context);
7067
});

instrumentation/spring/spring-boot-autoconfigure/testing/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/AbstractMicrometerBridgeAutoConfigurationTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ void metricsEnabled() {
4444
void metricsDisabledByDefault() {
4545
contextRunner
4646
.withConfiguration(AutoConfigurations.of(getMetricsAutoConfigurationClass()))
47-
.run(context -> assertThat(context.containsBean("otelMeterRegistry")).isFalse());
47+
.run(context -> assertThat(context).doesNotHaveBean("otelMeterRegistry"));
4848
}
4949

5050
@Test
5151
void metricsDisabled() {
5252
contextRunner
5353
.withConfiguration(AutoConfigurations.of(getMetricsAutoConfigurationClass()))
5454
.withPropertyValues("otel.instrumentation.micrometer.enabled=false")
55-
.run(context -> assertThat(context.containsBean("otelMeterRegistry")).isFalse());
55+
.run(context -> assertThat(context).doesNotHaveBean("otelMeterRegistry"));
5656
}
5757

5858
@Test
5959
void noActuatorAutoConfiguration() {
6060
contextRunner
6161
.withPropertyValues("otel.instrumentation.micrometer.enabled=true")
62-
.run(context -> assertThat(context.containsBean("otelMeterRegistry")).isFalse());
62+
.run(context -> assertThat(context).doesNotHaveBean("otelMeterRegistry"));
6363
}
6464

6565
@Test
@@ -68,10 +68,6 @@ void doesNotActivateWhenMetricsAutoConfigurationIsMissing() {
6868
.withClassLoader(new FilteredClassLoader(getMetricsAutoConfigurationClass()))
6969
.withBean(Clock.class, () -> Clock.SYSTEM)
7070
.withPropertyValues("otel.instrumentation.micrometer.enabled=true")
71-
.run(
72-
context ->
73-
assertThat(context)
74-
.hasNotFailed()
75-
.satisfies(ctx -> assertThat(ctx.containsBean("otelMeterRegistry")).isFalse()));
71+
.run(context -> assertThat(context).hasNotFailed().doesNotHaveBean("otelMeterRegistry"));
7672
}
7773
}

instrumentation/spring/spring-boot-autoconfigure/testing/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/AbstractRestClientInstrumentationAutoConfigurationTest.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ void instrumentationEnabled() {
6666
void instrumentationDisabled() {
6767
contextRunner
6868
.withPropertyValues("otel.instrumentation.spring-web.enabled=false")
69-
.run(
70-
context ->
71-
assertThat(context.containsBean("otelRestClientBeanPostProcessor")).isFalse());
69+
.run(context -> assertThat(context).doesNotHaveBean("otelRestClientBeanPostProcessor"));
7270
}
7371

7472
@Test
@@ -105,17 +103,14 @@ void shouldNotCreateNewBeanWhenInterceptorAlreadyPresent() {
105103
processed
106104
.mutate()
107105
.requestInterceptors(
108-
interceptors -> {
109-
long count =
110-
interceptors.stream()
111-
.filter(
112-
rti ->
113-
rti.getClass()
114-
.getName()
115-
.startsWith("io.opentelemetry.instrumentation"))
116-
.count();
117-
assertThat(count).isEqualTo(1);
118-
});
106+
interceptors ->
107+
assertThat(interceptors)
108+
.filteredOn(
109+
rti ->
110+
rti.getClass()
111+
.getName()
112+
.startsWith("io.opentelemetry.instrumentation"))
113+
.hasSize(1));
119114
});
120115
}
121116
}

instrumentation/spring/spring-boot-autoconfigure/testing/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/AbstractSpringWebInstrumentationAutoConfigurationTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,22 @@ void instrumentationEnabled() {
5757
void instrumentationDisabled() {
5858
contextRunner
5959
.withPropertyValues("otel.instrumentation.spring-web.enabled=false")
60-
.run(
61-
context ->
62-
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
60+
.run(context -> assertThat(context).doesNotHaveBean("otelRestTemplateBeanPostProcessor"));
6361
}
6462

6563
@Test
6664
void instrumentationDisabledButAllEnabled() {
6765
contextRunner
6866
.withPropertyValues("otel.instrumentation.spring-web.enabled=false")
6967
.withPropertyValues("otel.instrumentation.common.default-enabled=true")
70-
.run(
71-
context ->
72-
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
68+
.run(context -> assertThat(context).doesNotHaveBean("otelRestTemplateBeanPostProcessor"));
7369
}
7470

7571
@Test
7672
void allInstrumentationDisabled() {
7773
contextRunner
7874
.withPropertyValues("otel.instrumentation.common.default-enabled=false")
79-
.run(
80-
context ->
81-
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
75+
.run(context -> assertThat(context).doesNotHaveBean("otelRestTemplateBeanPostProcessor"));
8276
}
8377

8478
@Test

instrumentation/spring/spring-boot-autoconfigure/testing/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/AbstractWebClientCustomizerAutoConfigurationTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static org.assertj.core.api.Assertions.assertThat;
99

1010
import io.opentelemetry.api.OpenTelemetry;
11-
import java.util.concurrent.atomic.AtomicLong;
1211
import org.junit.jupiter.api.BeforeEach;
1312
import org.junit.jupiter.api.Test;
1413
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -75,21 +74,19 @@ void shouldAddTracingFilterWhenCustomizerApplied() {
7574
WebClient.Builder builder = WebClient.builder();
7675
customizeWebClient(customizer, builder);
7776

78-
AtomicLong count = new AtomicLong(0);
7977
builder
8078
.build()
8179
.mutate()
8280
.filters(
8381
filters ->
84-
count.set(
85-
filters.stream()
86-
.filter(
87-
f ->
88-
f.getClass()
89-
.getName()
90-
.startsWith("io.opentelemetry.instrumentation"))
91-
.count()));
92-
assertThat(count.get()).isEqualTo(1);
82+
assertThat(filters)
83+
.filteredOn(
84+
filter ->
85+
filter
86+
.getClass()
87+
.getName()
88+
.startsWith("io.opentelemetry.instrumentation"))
89+
.hasSize(1));
9390
});
9491
}
9592

instrumentation/spring/spring-boot-resources/javaagent/src/main/java/io/opentelemetry/instrumentation/spring/resources/SpringBootServiceNameDetector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private String findByCurrentDirectoryApplicationProperties() {
158158
String result = null;
159159
try (InputStream in = system.openFile("application.properties")) {
160160
result = getAppNamePropertyFromStream(in);
161-
} catch (Exception e) {
161+
} catch (IOException | RuntimeException e) {
162162
// expected to fail sometimes
163163
}
164164
logger.log(FINER, "Checking application.properties in current dir: {0}", result);
@@ -209,7 +209,7 @@ private String findByCurrentDirectoryYamlFile(String fileName) {
209209
String result = null;
210210
try (InputStream in = system.openFile(fileName)) {
211211
result = parseNameFromYaml(in);
212-
} catch (Exception e) {
212+
} catch (IOException | RuntimeException e) {
213213
// expected to fail sometimes
214214
}
215215
if (logger.isLoggable(FINER)) {
@@ -258,7 +258,7 @@ private String attemptProcessHandleReflection() {
258258
try {
259259
String[] args = system.attemptGetCommandLineArgsViaReflection();
260260
return parseNameFromProcessArgs(args);
261-
} catch (Exception e) {
261+
} catch (ReflectiveOperationException e) {
262262
return null;
263263
}
264264
}
@@ -313,7 +313,7 @@ private static String getAppNamePropertyFromStream(InputStream in) {
313313
private String loadFromClasspath(String filename, Function<InputStream, String> parser) {
314314
try (InputStream in = system.openClasspathResource(filename)) {
315315
return in != null ? parser.apply(in) : null;
316-
} catch (Exception e) {
316+
} catch (IOException | RuntimeException e) {
317317
return null;
318318
}
319319
}

0 commit comments

Comments
 (0)