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

Servlet 5 API, reorganize servlet modules #2609

Merged
merged 11 commits into from
Mar 23, 2021

Conversation

agoallikmaa
Copy link
Contributor

The following changes are made in this PR:

  • servlet-common is split up into servlet-common and servlet-javax-common where the former does not directly use servlet classes, but defines an interface ServletAccessor<REQUEST, RESPONSE> which is used to access request and response objects, and the latter applies instrumentations previously found in servlet-common.
  • :instrumentation-core:servlet-2.2 is migrated to :instrumentation:servlet:servlet-common:library
  • Both servlet-2.2:javaagent and servlet-3.0:javaagent are split into javaagent and library modules where the tracer moves to library.
  • Shared TypeInstrumentation classes moved to servlet-common:javaagent and they take base package (either javax.servlet or jakarta.servlet) and advice class name as constructor parameters
  • New module servlet-jakarta which applies instrumentations to jakarta.servlet classes (the ones which are done by servlet-javax-common and servlet-3.0 for javax.servlet packages)
  • Matrix project gets a subproject called servlet-jakarta which is Servlet API 5.0 equivalent of the test war project. Added Jetty 11 test images which use the new war file. Manually tested that Jetty tests that do not require the jetty-8.0 module pass with those images.

To get a general overview of the structure of instrumentation/servlet directory, read the updated readme in there.

Most of the changes to existing servlet modules were made to reduce code duplication, but some code is still duplicated for the following cases:

  • Advice classes of servlet-3.0 and servlet-jakarta. As they modify local variables injected into instrumented methods, extracting common methods would require some additional allocations and complexity.
  • Span name detection in Servlet3HttpServerTracer and JakartaServletHttpServerTracer, as it uses too many different Servlet API classes to reasonably cover with generics.

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.

a lot of good stuff, thx for tackling it!

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.

btw, thx for the detailed PR summary, and the updated servlet/README.md, made reviewing much easier ❤️

Copy link
Contributor

@iNikem iNikem left a comment

Choose a reason for hiding this comment

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

Great work, thank you!

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Just small comments, thanks!

private String getSpanName(
Object servletOrFilter, HttpServletRequest request, boolean allowNull) {
String spanName = getSpanName(servletOrFilter, request);
if (spanName == null && !allowNull) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I only see this called twice, one with allowNull and one without. Can we move the logic for !allowNull to the caller to reduce conditionals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's good to have as a separate method since return keyword is convenient here and the method name still fits. However, made the caller of true call the inner method instead to still get rid of this extra parameter, and renamed the inner method to getSpanNameFromPath.

pass {
group = "jakarta.servlet"
module = 'jakarta.servlet-api'
versions = "[5.0.0,)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assertInverse? Since package name changed assuming it's safe so good to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@iNikem iNikem merged commit 69c2644 into open-telemetry:main Mar 23, 2021
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.

4 participants