Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move helper class to spring package so that loadClass can find it #3718

Merged
merged 6 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -24,6 +24,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.OpenTelemetryHandlerMappingFilter;

public class DispatcherServletInstrumentation implements TypeInstrumentation {

Expand Down Expand Up @@ -62,8 +63,8 @@ public static void afterRefresh(
@Advice.Argument(0) ApplicationContext springCtx,
@Advice.FieldValue("handlerMappings") List<HandlerMapping> handlerMappings) {
if (springCtx.containsBean("otelAutoDispatcherFilter")) {
HandlerMappingResourceNameFilter filter =
(HandlerMappingResourceNameFilter) springCtx.getBean("otelAutoDispatcherFilter");
OpenTelemetryHandlerMappingFilter filter =
(OpenTelemetryHandlerMappingFilter) springCtx.getBean("otelAutoDispatcherFilter");
if (handlerMappings != null && filter != null) {
filter.setHandlerMappings(handlerMappings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public SpringWebMvcInstrumentationModule() {
super("spring-webmvc", "spring-webmvc-3.1");
}

@Override
public boolean isHelperClass(String className) {
return className.startsWith(
"org.springframework.web.servlet.OpenTelemetryHandlerMappingFilter");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.bytebuddy.matcher.ElementMatcher;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.web.servlet.OpenTelemetryHandlerMappingFilter;

/**
* This instrumentation adds the HandlerMappingResourceNameFilter definition to the spring context
Expand Down Expand Up @@ -62,7 +63,7 @@ public static void onEnter(@Advice.Argument(0) ConfigurableListableBeanFactory b

((BeanDefinitionRegistry) beanFactory)
.registerBeanDefinition(
"otelAutoDispatcherFilter", new HandlerMappingResourceNameFilter.BeanDefinition());
"otelAutoDispatcherFilter", new OpenTelemetryHandlerMappingFilter.BeanDefinition());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.springwebmvc;
package org.springframework.web.servlet;

import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER;

import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming;
import io.opentelemetry.javaagent.instrumentation.springwebmvc.SpringWebMvcServerSpanNaming;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,11 +23,9 @@
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

public class HandlerMappingResourceNameFilter implements Filter, Ordered {
public class OpenTelemetryHandlerMappingFilter implements Filter, Ordered {
private volatile List<HandlerMapping> handlerMappings;

@Override
Expand Down Expand Up @@ -126,8 +125,8 @@ public int getOrder() {
public static class BeanDefinition extends GenericBeanDefinition {
public BeanDefinition() {
setScope(SCOPE_SINGLETON);
setBeanClass(HandlerMappingResourceNameFilter.class);
setBeanClassName(HandlerMappingResourceNameFilter.class.getName());
setBeanClass(OpenTelemetryHandlerMappingFilter.class);
setBeanClassName(OpenTelemetryHandlerMappingFilter.class.getName());
}
}
}