-
Notifications
You must be signed in to change notification settings - Fork 879
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
laurit
merged 11 commits into
open-telemetry:main
from
laurit:servlet-filter-span-naming
May 6, 2021
+1,078
−213
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0d460b5
Server span naming for servlet filters
laurit 2f1f7b6
wildfly default servlet has empty mappings
laurit a8fe86e
jetty11 requires java11
laurit 7c4785a
try a differnt way to disable jetty11 tests on java8
laurit dd4633e
Update instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/…
laurit d148afd
review fix
laurit a7ad07f
rework to use InstrumentationContext
laurit ee666a8
remove debugging code
laurit 8871bd2
move MappingResolver to avoid ClassCastException on wildfly
laurit d0295d0
Update instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/…
laurit 1b7dc66
review fixes
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!