-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server span naming for servlet filters (#2887)
* Server span naming for servlet filters * wildfly default servlet has empty mappings * jetty11 requires java11 * try a differnt way to disable jetty11 tests on java8 * Update instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5FilterMappingTest.groovy Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * review fix * rework to use InstrumentationContext * remove debugging code * move MappingResolver to avoid ClassCastException on wildfly * Update instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3FilterMappingTest.groovy Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com> * review fixes Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
- Loading branch information
1 parent
c9a3793
commit 357140c
Showing
37 changed files
with
1,078 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ava/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3FilterInitAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver; | ||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterConfig; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
public class Servlet3FilterInitAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void filterInit( | ||
@Advice.This Filter filter, @Advice.Argument(0) FilterConfig filterConfig) { | ||
if (filterConfig == null) { | ||
return; | ||
} | ||
InstrumentationContext.get(Filter.class, MappingResolver.class) | ||
.putIfAbsent(filter, new Servlet3FilterMappingResolverFactory(filterConfig)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...elemetry/javaagent/instrumentation/servlet/v3_0/Servlet3FilterMappingResolverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver; | ||
import io.opentelemetry.instrumentation.servlet.naming.ServletFilterMappingResolverFactory; | ||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore; | ||
import java.util.Collection; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.FilterRegistration; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletRegistration; | ||
|
||
public class Servlet3FilterMappingResolverFactory | ||
extends ServletFilterMappingResolverFactory<FilterRegistration> | ||
implements ContextStore.Factory<MappingResolver> { | ||
private final FilterConfig filterConfig; | ||
|
||
public Servlet3FilterMappingResolverFactory(FilterConfig filterConfig) { | ||
this.filterConfig = filterConfig; | ||
} | ||
|
||
@Override | ||
protected FilterRegistration getFilterRegistration() { | ||
String filterName = filterConfig.getFilterName(); | ||
ServletContext servletContext = filterConfig.getServletContext(); | ||
if (filterName == null || servletContext == null) { | ||
return null; | ||
} | ||
return servletContext.getFilterRegistration(filterName); | ||
} | ||
|
||
@Override | ||
protected Collection<String> getUrlPatternMappings(FilterRegistration filterRegistration) { | ||
return filterRegistration.getUrlPatternMappings(); | ||
} | ||
|
||
@Override | ||
protected Collection<String> getServletNameMappings(FilterRegistration filterRegistration) { | ||
return filterRegistration.getServletNameMappings(); | ||
} | ||
|
||
@Override | ||
protected Collection<String> getServletMappings(String servletName) { | ||
ServletRegistration servletRegistration = | ||
filterConfig.getServletContext().getServletRegistration(servletName); | ||
if (servletRegistration == null) { | ||
return null; | ||
} | ||
return servletRegistration.getMappings(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3InitAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver; | ||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import javax.servlet.Servlet; | ||
import javax.servlet.ServletConfig; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
public class Servlet3InitAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void servletInit( | ||
@Advice.This Servlet servlet, @Advice.Argument(0) ServletConfig servletConfig) { | ||
if (servletConfig == null) { | ||
return; | ||
} | ||
InstrumentationContext.get(Servlet.class, MappingResolver.class) | ||
.putIfAbsent(servlet, new Servlet3MappingResolverFactory(servletConfig)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3MappingResolverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver; | ||
import io.opentelemetry.instrumentation.servlet.naming.ServletMappingResolverFactory; | ||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore; | ||
import java.util.Collection; | ||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletRegistration; | ||
|
||
public class Servlet3MappingResolverFactory extends ServletMappingResolverFactory | ||
implements ContextStore.Factory<MappingResolver> { | ||
private final ServletConfig servletConfig; | ||
|
||
public Servlet3MappingResolverFactory(ServletConfig servletConfig) { | ||
this.servletConfig = servletConfig; | ||
} | ||
|
||
public Collection<String> getMappings() { | ||
String servletName = servletConfig.getServletName(); | ||
ServletContext servletContext = servletConfig.getServletContext(); | ||
if (servletName == null || servletContext == null) { | ||
return null; | ||
} | ||
|
||
ServletRegistration servletRegistration = servletContext.getServletRegistration(servletName); | ||
if (servletRegistration == null) { | ||
return null; | ||
} | ||
return servletRegistration.getMappings(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.