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

Server span naming for servlet filters #2887

Merged
merged 11 commits into from
May 6, 2021

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Apr 29, 2021

Set server span name when request passes through a servlet filter. Names given based on servlet filters have a lower precedence than names from servlets and controllers. If request reaches a servlet or controller then the name given from filter will be replaced.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice new tests 👍

Comment on lines 13 to 15
public final class JakartaServletFilterConfigHolder {
private static final Cache<Filter, FilterConfig> filterConfigs =
Cache.newBuilder().setWeakKeys().build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use InstrumentationContext instead? or if not can you add comment here to explain why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote it to use InstrumentationContext

Comment on lines 13 to 15
public final class Servlet3FilterConfigHolder {
private static final Cache<Filter, FilterConfig> filterConfigs =
Cache.newBuilder().setWeakKeys().build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment on lines 73 to 81
protected MappingProvider<ServletContext> getMappingProvider(Object servletOrFilter) {
if (servletOrFilter instanceof Servlet) {
return getServletMappingProvider((Servlet) servletOrFilter);
} else if (servletOrFilter instanceof Filter) {
return getServletFilterMappingProvider((Filter) servletOrFilter);
}

return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this instantiates a new MappingProvider on each call, can we cache the MappingProvider for each servlet/filter?

or maybe cache MappingResolver in the servlet/filter, and then only need to instantiate MappingProvider the first time when MappingResolver is not available and need to instantiate it? and maybe then MappingProvider can be MappingResolverFactory or MappingResolverProvider? I think that would help reduce the number of concepts (even if not the number of classes)

I also may not be making sense, let me know

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now MappingResolver is bound to InstrumentationContext via MappingResolverFactory

import spock.lang.IgnoreIf

@IgnoreIf({ !jvm.java11Compatible })
class JettyServlet5MappingTest extends AbstractServlet5MappingTest<Object, Object> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

Suggested change
class JettyServlet5MappingTest extends AbstractServlet5MappingTest<Object, Object> {
class JettyServlet5MappingTest extends AbstractServlet5MappingTest<Server, ServletContextHandler > {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jetty 11 classes are compiled with java 11 so need to disable test on java 8. As class is poked with reflection before IgnoreIf applies can't use java 11 classes in method signatures because of UnsupportedClassVersionError.

laurit and others added 2 commits May 4, 2021 14:19
…TomcatServlet3FilterMappingTest.groovy

Co-authored-by: Mateusz Rzeszutek <[email protected]>
@iNikem iNikem requested a review from trask May 5, 2021 07:34
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

import javax.servlet.ServletRegistration;

public class Servlet3MappingResolverFactory extends ServletMappingResolverFactory
implements ContextStore.Factory<MappingResolver> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I hadn't noticed ContextStore.Factory before!

@laurit laurit merged commit 357140c into open-telemetry:main May 6, 2021
@laurit laurit deleted the servlet-filter-span-naming branch May 6, 2021 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants