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 @@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
Expand All @@ -36,14 +38,19 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

public class OpenTelemetryHandlerMappingFilter implements Filter, Ordered {
private static final Logger logger =
Logger.getLogger(OpenTelemetryHandlerMappingFilter.class.getName());

private static final MethodHandle usesPathPatternsMh = getUsesPathPatternsMh();
private static final MethodHandle parseAndCacheMh = parseAndCacheMh();

private final HttpServerRouteGetter<HttpServletRequest> serverSpanName =
(context, request) -> {
if (this.parseRequestPath) {
// sets new value for PATH_ATTRIBUTE of request
parseAndCache(request);
if (!parseAndCache(request)) {
return null;
}
}
if (findMapping(request)) {
// Name the parent span based on the matching pattern
Expand Down Expand Up @@ -191,14 +198,16 @@ private static MethodHandle parseAndCacheMh() {
}
}

private static void parseAndCache(HttpServletRequest request) {
private static boolean parseAndCache(HttpServletRequest request) {
if (parseAndCacheMh == null) {
return;
return false;
}
try {
parseAndCacheMh.invoke(request);
return true;
} catch (Throwable throwable) {
throw new IllegalStateException(throwable);
logger.log(Level.FINE, "Failed calling parseAndCache", throwable);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerExecutionChain;
Expand All @@ -34,12 +36,19 @@
import org.springframework.web.util.ServletRequestPathUtils;

public class OpenTelemetryHandlerMappingFilter implements Filter, Ordered {
private static final Logger logger =
Logger.getLogger(OpenTelemetryHandlerMappingFilter.class.getName());

private final HttpServerRouteGetter<HttpServletRequest> serverSpanName =
(context, request) -> {
if (this.parseRequestPath) {
// sets new value for PATH_ATTRIBUTE of request
ServletRequestPathUtils.parseAndCache(request);
try {
ServletRequestPathUtils.parseAndCache(request);
} catch (RuntimeException exception) {
logger.log(Level.FINE, "Failed calling parseAndCache", exception);
return null;
}
}
if (findMapping(request)) {
// Name the parent span based on the matching pattern
Expand Down
Loading