io.opentelemetry.javaagent.instrumentation.servlet.v2_2.Servlet2InstrumentationModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-servlet-2.2 Show documentation
Show all versions of opentelemetry-javaagent-servlet-2.2 Show documentation
Instrumentation of Java libraries using OpenTelemetry.
The newest version!
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.servlet.v2_2;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.not;
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.instrumentation.servlet.common.response.HttpServletResponseInstrumentation;
import io.opentelemetry.javaagent.instrumentation.servlet.common.service.ServletAndFilterInstrumentation;
import java.util.Arrays;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;
@AutoService(InstrumentationModule.class)
public class Servlet2InstrumentationModule extends InstrumentationModule {
private static final String BASE_PACKAGE = "javax.servlet";
public Servlet2InstrumentationModule() {
super("servlet", "servlet-2.2");
}
// this is required to make sure servlet 2 instrumentation won't apply to servlet 3
@Override
public ElementMatcher.Junction classLoaderMatcher() {
return not(hasClassesNamed("javax.servlet.AsyncEvent", "javax.servlet.AsyncListener"));
}
@Override
public List typeInstrumentations() {
return Arrays.asList(
new Servlet2HttpServletResponseInstrumentation(),
new ServletAndFilterInstrumentation(BASE_PACKAGE, adviceClassName(".Servlet2Advice")),
new HttpServletResponseInstrumentation(
BASE_PACKAGE, adviceClassName(".Servlet2ResponseSendAdvice")));
}
private static String adviceClassName(String suffix) {
return Servlet2InstrumentationModule.class.getPackage().getName() + suffix;
}
}