Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
}

base.archivesName.set("opentelemetry-spring-boot-autoconfigure")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.spring.autoconfigure;

import static java.util.Objects.requireNonNull;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.trace.TracerProvider;
Expand Down Expand Up @@ -145,7 +147,7 @@ public InstrumentationConfig instrumentationConfig(ConfigProperties properties)
@Bean
public ConfigProperties otelProperties(
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
return AutoConfigureUtil.getConfig(autoConfiguredOpenTelemetrySdk);
return requireNonNull(AutoConfigureUtil.getConfig(autoConfiguredOpenTelemetrySdk));
}
}

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

package io.opentelemetry.instrumentation.spring.autoconfigure.internal;

import static java.util.Objects.requireNonNull;

import java.util.Map;
import java.util.Objects;
import org.springframework.context.annotation.Condition;
Expand All @@ -25,7 +27,7 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)

return EarlyConfig.isInstrumentationEnabled(
context.getEnvironment(),
attributes.get("module").toString(),
(boolean) attributes.get("enabledByDefault"));
requireNonNull(attributes.get("module")).toString(),
(boolean) requireNonNull(attributes.get("enabledByDefault")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.annotations;

import io.opentelemetry.api.OpenTelemetry;
import javax.annotation.Nullable;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand All @@ -24,6 +25,7 @@ class InstrumentationWithSpanAspect extends WithSpanAspect {
.InstrumentationAnnotationAttributeNameSupplier());
}

@Nullable
@Override
@Around("@annotation(io.opentelemetry.instrumentation.annotations.WithSpan)")
public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndSupport;
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import javax.annotation.Nullable;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.core.ParameterNameDiscoverer;

Expand Down Expand Up @@ -64,6 +65,7 @@ private static Context parentContext(
return request.inheritContext() ? parentContext : Context.root();
}

@Nullable
public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable {
JoinPointRequest request = requestFactory.create(pjp);
Context parentContext = Context.current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.sql.DataSource;
import org.springframework.aop.SpringProxy;
import org.springframework.aop.framework.AdvisedSupport;
Expand All @@ -27,7 +28,7 @@

final class DataSourcePostProcessor implements BeanPostProcessor, Ordered {

private static final Class<?> ROUTING_DATA_SOURCE_CLASS = getRoutingDataSourceClass();
@Nullable private static final Class<?> ROUTING_DATA_SOURCE_CLASS = getRoutingDataSourceClass();

private final ObjectProvider<OpenTelemetry> openTelemetryProvider;
private final ObjectProvider<InstrumentationConfig> configProvider;
Expand All @@ -39,6 +40,7 @@ final class DataSourcePostProcessor implements BeanPostProcessor, Ordered {
this.configProvider = configProvider;
}

@Nullable
private static Class<?> getRoutingDataSourceClass() {
try {
return Class.forName("org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.instrumentation.spring.kafka.v2_7.SpringKafkaTelemetry;
import java.lang.reflect.Field;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.kafka.config.AbstractKafkaListenerContainerFactory;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
Expand Down Expand Up @@ -47,6 +48,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
return listenerContainerFactory;
}

@Nullable
private static <T> T readField(Object container, String filedName, Class<T> fieldType) {
try {
Field field = AbstractKafkaListenerContainerFactory.class.getDeclaredField(filedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
import io.opentelemetry.instrumentation.runtimemetrics.java17.RuntimeMetrics;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RuntimeMetricsConfigUtil;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,6 +27,7 @@ public int minJavaVersion() {
return 17;
}

@Nullable
@Override
public AutoCloseable start(OpenTelemetry openTelemetry, InstrumentationConfig config) {
logger.debug("Use runtime metrics instrumentation for Java 17+");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
import io.opentelemetry.instrumentation.runtimemetrics.java8.RuntimeMetrics;
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.RuntimeMetricsConfigUtil;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,6 +27,7 @@ public int minJavaVersion() {
return 8;
}

@Nullable
@Override
public AutoCloseable start(OpenTelemetry openTelemetry, InstrumentationConfig config) {
logger.debug("Use runtime metrics instrumentation for Java 8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation;
import java.util.Comparator;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,7 +32,7 @@ public class RuntimeMetricsAutoConfiguration {
private static final Logger logger =
LoggerFactory.getLogger(RuntimeMetricsAutoConfiguration.class);

private AutoCloseable closeable;
@Nullable private AutoCloseable closeable;

@PreDestroy
public void stopMetrics() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public List<String> getList(String name) {
}

List<String> envValue = (List<String>) environment.getProperty(normalizedName, List.class);
return or(envValue, otelSdkProperties.getList(name));
return orNonNull(envValue, otelSdkProperties.getList(name));
}

@Nullable
Expand Down Expand Up @@ -281,4 +281,8 @@ private static Map<String, String> mergeWithOtel(
private static <T> T or(@Nullable T first, @Nullable T second) {
return first != null ? first : second;
}

private static <T> T orNonNull(@Nullable T first, T second) {
return first != null ? first : second;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.spring.autoconfigure.internal.resources;

import static java.util.Objects.requireNonNull;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
Expand All @@ -19,7 +21,9 @@
public class DistroVersionResourceProvider implements ResourceProvider {

public static final String VERSION =
EmbeddedInstrumentationProperties.findVersion("io.opentelemetry.spring-boot-autoconfigure");
requireNonNull(
EmbeddedInstrumentationProperties.findVersion(
"io.opentelemetry.spring-boot-autoconfigure"));

private static final AttributeKey<String> TELEMETRY_DISTRO_NAME =
AttributeKey.stringKey("telemetry.distro.name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.kafkaclients.common.v0_11.internal.KafkaProcessRequest;
import io.opentelemetry.instrumentation.kafkaclients.common.v0_11.internal.KafkaReceiveRequest;
import javax.annotation.Nullable;
import org.springframework.kafka.listener.AbstractMessageListenerContainer;
import org.springframework.kafka.listener.BatchInterceptor;
import org.springframework.kafka.listener.RecordInterceptor;
Expand Down Expand Up @@ -57,7 +58,7 @@ public <K, V> RecordInterceptor<K, V> createRecordInterceptor() {
* {@link AbstractMessageListenerContainer#setRecordInterceptor(RecordInterceptor)} method.
*/
public <K, V> RecordInterceptor<K, V> createRecordInterceptor(
RecordInterceptor<K, V> decoratedInterceptor) {
@Nullable RecordInterceptor<K, V> decoratedInterceptor) {
return new InstrumentedRecordInterceptor<>(processInstrumenter, decoratedInterceptor);
}

Expand All @@ -78,7 +79,7 @@ public <K, V> BatchInterceptor<K, V> createBatchInterceptor() {
* {@link AbstractMessageListenerContainer#setBatchInterceptor(BatchInterceptor)} method.
*/
public <K, V> BatchInterceptor<K, V> createBatchInterceptor(
BatchInterceptor<K, V> decoratedInterceptor) {
@Nullable BatchInterceptor<K, V> decoratedInterceptor) {
return new InstrumentedBatchInterceptor<>(batchProcessInstrumenter, decoratedInterceptor);
}
}
Loading