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
Expand Up @@ -57,7 +57,8 @@ private HttpServerRoute() {}
* strictly lower priority than the provided {@link HttpServerRouteSource}, and the passed value
* is non-null.
*/
public static void update(Context context, HttpServerRouteSource source, String httpRoute) {
public static void update(
Context context, HttpServerRouteSource source, @Nullable String httpRoute) {
update(context, source, ConstantAdapter.INSTANCE, httpRoute);
}

Expand All @@ -75,7 +76,7 @@ public static <T> void update(
Context context,
HttpServerRouteSource source,
HttpServerRouteGetter<T> httpRouteGetter,
T arg1) {
@Nullable T arg1) {
update(context, source, OneArgAdapter::get, arg1, httpRouteGetter);
}

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

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void transform(TypeTransformer transformer) {
public static class UrlTemplateAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
@Nullable
public static Scope onEnter(@Advice.Argument(1) String uriTemplate) {
if (uriTemplate != null) {
String path = UrlParser.getPath(uriTemplate);
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 @@ -50,7 +50,7 @@ public static <T> Mono<T> wrapMono(Mono<T> mono, Context context) {

@FunctionalInterface
interface OnSpanEnd {
void end(Throwable throwable);
void end(@Nullable Throwable throwable);
}

private static class ContextMono<T> extends Mono<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void accept(HandlerFunction<?> handler) {
HttpServerRoute.update(Context.current(), HttpServerRouteSource.CONTROLLER, route);
}

@Nullable
private static String parsePredicateString(RouterFunction<?> routerFunction) {
String routerFunctionString = routerFunction.toString();
// Router functions containing lambda predicates should not end up in span tags since they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static Instrumenter<Object, Void> instrumenter() {

public static HttpServerRouteGetter<ServerWebExchange> httpRouteGetter() {
return (context, exchange) -> {
if (exchange == null) {
return null;
}
Object bestPatternObj = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (bestPatternObj == null) {
return 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
Expand Up @@ -14,6 +14,9 @@ public class SpringWebMvcServerSpanNaming {

public static final HttpServerRouteGetter<HttpServletRequest> SERVER_SPAN_NAME =
(context, request) -> {
if (request == null) {
return null;
}
Object bestMatchingPattern =
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (bestMatchingPattern != null) {
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")
}

val springBootVersion = "2.6.15"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ private void setHandlerMappings(List<HandlerMapping> mappings) {
}

@Nullable
String getHttpRoute(Context context, HttpServletRequest request) {
String getHttpRoute(Context context, @Nullable HttpServletRequest request) {
if (request == null) {
return null;
}
boolean parsePath = this.parseRequestPath;
Object previousValue = null;
if (parsePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.instrumentation.api.internal.EnumerationUtil;
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

enum JavaxHttpServletRequestGetter implements TextMapGetter<HttpServletRequest> {
Expand All @@ -20,12 +21,19 @@ public Iterable<String> keys(HttpServletRequest carrier) {
}

@Override
public String get(HttpServletRequest carrier, String key) {
@Nullable
public String get(@Nullable HttpServletRequest carrier, String key) {
if (carrier == null) {
return null;
}
return carrier.getHeader(key);
}

@Override
public Iterator<String> getAll(HttpServletRequest carrier, String key) {
public Iterator<String> getAll(@Nullable HttpServletRequest carrier, String key) {
if (carrier == null) {
return Collections.emptyIterator();
}
return EnumerationUtil.asIterator(carrier.getHeaders(key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal;

import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder;
import io.opentelemetry.instrumentation.api.internal.Initializer;
import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetryBuilder;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -31,6 +32,7 @@ private SpringMvcBuilderUtil() {}
return builderExtractor;
}

@Initializer
public static void setBuilderExtractor(
Function<
SpringWebMvcTelemetryBuilder,
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 @@ -14,6 +14,9 @@ public class SpringWebMvcServerSpanNaming {

public static final HttpServerRouteGetter<HttpServletRequest> SERVER_SPAN_NAME =
(context, request) -> {
if (request == null) {
return null;
}
Object bestMatchingPattern =
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (bestMatchingPattern != null) {
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 @@ -96,7 +96,10 @@ private void setHandlerMappings(List<HandlerMapping> mappings) {
}

@Nullable
String getHttpRoute(Context context, HttpServletRequest request) {
String getHttpRoute(Context context, @Nullable HttpServletRequest request) {
if (request == null) {
return null;
}
boolean parsePath = this.parseRequestPath;
Object previousValue = null;
if (parsePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.Nullable;

enum JakartaHttpServletRequestGetter implements TextMapGetter<HttpServletRequest> {
INSTANCE;
Expand All @@ -20,12 +21,19 @@ public Iterable<String> keys(HttpServletRequest carrier) {
}

@Override
public String get(HttpServletRequest carrier, String key) {
@Nullable
public String get(@Nullable HttpServletRequest carrier, String key) {
if (carrier == null) {
return null;
}
return carrier.getHeader(key);
}

@Override
public Iterator<String> getAll(HttpServletRequest carrier, String key) {
public Iterator<String> getAll(@Nullable HttpServletRequest carrier, String key) {
if (carrier == null) {
return Collections.emptyIterator();
}
return EnumerationUtil.asIterator(carrier.getHeaders(key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal;

import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder;
import io.opentelemetry.instrumentation.api.internal.Initializer;
import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetryBuilder;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -31,6 +32,7 @@ private SpringMvcBuilderUtil() {}
return builderExtractor;
}

@Initializer
public static void setBuilderExtractor(
Function<
SpringWebMvcTelemetryBuilder,
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")
}

dependencies {
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 @@ -7,6 +7,7 @@

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static io.opentelemetry.javaagent.instrumentation.spring.ws.v2_0.SpringWsSingletons.instrumenter;
import static java.util.Objects.requireNonNull;
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
Expand Down Expand Up @@ -53,12 +54,15 @@ public static class AnnotatedMethodAdvice {

public static class AdviceScope {
private final CallDepth callDepth;
private final SpringWsRequest request;
private final Context context;
private final Scope scope;
@Nullable private final SpringWsRequest request;
@Nullable private final Context context;
@Nullable private final Scope scope;

private AdviceScope(
CallDepth callDepth, SpringWsRequest request, Context context, Scope scope) {
CallDepth callDepth,
@Nullable SpringWsRequest request,
@Nullable Context context,
@Nullable Scope scope) {
this.callDepth = callDepth;
this.request = request;
this.context = context;
Expand Down Expand Up @@ -88,7 +92,8 @@ public void exit(@Nullable Throwable throwable) {
return;
}
scope.close();
instrumenter().end(context, request, null, throwable);
// scope non-null implies context and request are both non-null (see enter method above)
instrumenter().end(requireNonNull(context), requireNonNull(request), null, throwable);
}
}

Expand Down
Loading