Skip to content
Open
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.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

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

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.internal.Initializer;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.ContextAndScope;
import javax.annotation.Nullable;
Expand All @@ -28,6 +29,7 @@ public TracingChunkExecutionListener(Class<?> builderClass) {
}

@Override
@Initializer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget what this does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that true in this case? I'm guessing this listener is created, and then beforeChunk is called multiple times?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chunkContextAndBuilder is needed by afterChunk, and beforeChunk is setting it, it's initializing the variable

	/**
	 * Callback before the chunk is executed, but inside the transaction.
	 *
	 * @param context The current {@link ChunkContext}
	 */
	void beforeChunk(ChunkContext context);

	/**
	 * Callback after the chunk is executed, outside the transaction.
	 *
	 * @param context The current {@link ChunkContext}
	 */
	void afterChunk(ChunkContext context);

public void beforeChunk(ChunkContext chunkContext) {
Context parentContext = shouldCreateRootSpanForChunk() ? Context.root() : Context.current();
chunkContextAndBuilder = new ChunkContextAndBuilder(chunkContext, builderClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import javax.annotation.Nullable;
import org.springframework.batch.core.scope.context.ChunkContext;

public class ItemSingletons {
Expand Down Expand Up @@ -47,6 +48,7 @@ public static Context startChunk(Context currentContext, ChunkContext chunkConte
return currentContext.with(CHUNK_CONTEXT_KEY, chunkContext);
}

@Nullable
public static ChunkContext getChunkContext(Context currentContext) {
return currentContext.get(CHUNK_CONTEXT_KEY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void beforeStep(StepExecution stepExecution) {
}

@Override
@Nullable
public ExitStatus afterStep(StepExecution stepExecution) {
ContextAndScope contextAndScope = CONTEXT_AND_SCOPE.get(stepExecution);
if (contextAndScope == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.sdk-extension")
id("otel.nullaway-conventions")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ private String findByClasspathBootstrapYaml() {
return findByClasspathYamlFile("bootstrap.yaml");
}

@Nullable
private String findByClasspathYamlFile(String fileName) {
String result = loadFromClasspath(fileName, SpringBootServiceNameDetector::parseNameFromYaml);
if (logger.isLoggable(FINER)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.Collection;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -32,6 +33,7 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class ExecuteAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
@Nullable
public static Scope methodEnter(@Advice.Argument(0) Collection<Message<?>> messages) {
return SpringAwsUtil.handleBatch(messages);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -33,6 +34,7 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class OnMessageAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
@Nullable
public static SpringAwsUtil.MessageScope methodEnter(@Advice.Argument(0) Message<?> message) {
return SpringAwsUtil.handleMessage(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.instrumentation.awssdk.v2_2.internal.TracingExecutionInterceptor;
import io.opentelemetry.instrumentation.awssdk.v2_2.internal.TracingList;
import java.util.Collection;
import javax.annotation.Nullable;
import org.springframework.messaging.Message;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;

Expand Down Expand Up @@ -61,6 +62,7 @@ public static void copyTracingState(Message<?> original, Message<?> transformed)
tracingContextField.set(transformed, tracingContextField.get(original));
}

@Nullable
public static MessageScope handleMessage(Message<?> message) {
TracingContext tracingContext = tracingContextField.get(message);
if (tracingContext == null) {
Expand All @@ -71,6 +73,7 @@ public static MessageScope handleMessage(Message<?> message) {
}

// restore context from the first message of the batch
@Nullable
public static Scope handleBatch(Collection<Message<?>> messages) {
if (messages == null || messages.isEmpty()) {
return null;
Expand Down Expand Up @@ -131,6 +134,7 @@ private static class TracingContext {
this.sqsMessage = sqsMessage;
}

@Nullable
MessageScope trace() {
SqsMessage wrappedMessage = SqsMessageImpl.wrap(sqsMessage);
Context parentContext = receiveContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.web.server.ServerWebExchange;

Expand Down Expand Up @@ -68,7 +69,11 @@ public static void extractAttributes(ServerWebExchange exchange, Context context
}
}

public static String extractServerRoute(ServerWebExchange exchange) {
@Nullable
public static String extractServerRoute(@Nullable ServerWebExchange exchange) {
if (exchange == null) {
return null;
}
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
if (route != null) {
return convergeRouteId(route);
Expand All @@ -83,6 +88,7 @@ public static String extractServerRoute(ServerWebExchange exchange) {
* @see <a
* href="https://github.com/spring-cloud/spring-cloud-gateway/commit/5002fe2e0a2825ef47dd667cade37b844c276cf6"/>
*/
@Nullable
private static String convergeRouteId(Route route) {
String routeId = route.getId();
if (routeId == null || routeId.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.java-conventions")
id("otel.nullaway-conventions")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.testing.internal.armeria.client.WebClient;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -47,7 +48,7 @@ void beforeEach() {
}

protected List<AttributeAssertion> buildAttributeAssertions(
String routeId, String uri, int order, int filterSize) {
@Nullable String routeId, String uri, int order, int filterSize) {
List<AttributeAssertion> assertions = new ArrayList<>();
if (!StringUtils.isEmpty(routeId)) {
assertions.add(equalTo(AttributeKey.stringKey("spring-cloud-gateway.route.id"), routeId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -44,6 +45,7 @@ public void transform(TypeTransformer transformer) {
public static class ExecuteAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
@Nullable
public static PropagatedContext enterJobSubmit(@Advice.Argument(0) Runnable task) {
Context context = Java8BytecodeBridge.currentContext();
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.lang.reflect.Method;
import java.util.List;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -89,13 +90,14 @@ public void postProcess(ProxyFactory factory, RepositoryInformation repositoryIn
}

static final class RepositoryInterceptor implements MethodInterceptor {
private static final Class<?> MONO_CLASS = loadClass("reactor.core.publisher.Mono");
@Nullable private static final Class<?> MONO_CLASS = loadClass("reactor.core.publisher.Mono");
private final Class<?> repositoryInterface;

RepositoryInterceptor(Class<?> repositoryInterface) {
this.repositoryInterface = repositoryInterface;
}

@Nullable
private static Class<?> loadClass(String name) {
try {
return Class.forName(name);
Expand All @@ -105,6 +107,7 @@ private static Class<?> loadClass(String name) {
}

@Override
@Nullable
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Context parentContext = currentContext();
Method method = methodInvocation.getMethod();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

// context "leak" here is intentional: spring-integration instrumentation will always override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void close() {
getScope().close();
}

static ContextAndScope create(Context context, Scope scope) {
static ContextAndScope create(@Nullable Context context, Scope scope) {
return new AutoValue_ContextAndScope(context, scope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public Iterable<String> keys(MessageWithChannel carrier) {
}

@Override
public String get(MessageWithChannel carrier, String key) {
@Nullable
public String get(@Nullable MessageWithChannel carrier, String key) {
if (carrier == null) {
return null;
}
MessageHeaders headers = carrier.getMessage().getHeaders();
String nativeHeaderValue = getNativeHeader(headers, key);
if (nativeHeaderValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.messaging.support.NativeMessageHeaderAccessor;

Expand All @@ -21,7 +22,10 @@ enum MessageHeadersSetter implements TextMapSetter<MessageHeaderAccessor> {
INSTANCE;

@Override
public void set(MessageHeaderAccessor carrier, String key, String value) {
public void set(@Nullable MessageHeaderAccessor carrier, String key, String value) {
if (carrier == null) {
return;
}
carrier.setHeader(key, value);
setNativeHeader(carrier, key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.messaging.Message;
Expand Down Expand Up @@ -202,11 +203,15 @@ private static Message<?> createMessageWithHeaders(
.build();
}

@Nullable
private static final Class<?> directWithAttributesChannelClass =
getDirectWithAttributesChannelClass();

@Nullable
private static final MethodHandle channelGetAttributeMh =
getChannelAttributeMh(directWithAttributesChannelClass);

@Nullable
private static Class<?> getDirectWithAttributesChannelClass() {
try {
return Class.forName(
Expand All @@ -216,7 +221,9 @@ private static Class<?> getDirectWithAttributesChannelClass() {
}
}

private static MethodHandle getChannelAttributeMh(Class<?> directWithAttributesChannelClass) {
@Nullable
private static MethodHandle getChannelAttributeMh(
@Nullable Class<?> directWithAttributesChannelClass) {
if (directWithAttributesChannelClass == null) {
return null;
}
Expand Down Expand Up @@ -244,6 +251,10 @@ private boolean createProducerSpan(MessageChannel messageChannel) {
return false;
}

if (channelGetAttributeMh == null) {
return false;
}

try {
return "output".equals(channelGetAttributeMh.invoke(messageChannel, "type"));
} catch (Throwable throwable) {
Expand Down
Loading