Skip to content

Instrument javax.servlet.Filter the same way as javax.servlet.FilterChain (#1857)#1858

Merged
SylvainJuge merged 16 commits intoelastic:masterfrom
tobiasstadler:fix-1857
Jul 1, 2021
Merged

Instrument javax.servlet.Filter the same way as javax.servlet.FilterChain (#1857)#1858
SylvainJuge merged 16 commits intoelastic:masterfrom
tobiasstadler:fix-1857

Conversation

@tobiasstadler
Copy link
Contributor

@tobiasstadler tobiasstadler commented Jun 14, 2021

What does this PR do?

Fixes #1857

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation
@ghost
Copy link

ghost commented Jun 14, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Branch indexing

  • Start Time: 2021-07-01T10:39:17.133+0000

  • Duration: 54 min 8 sec

  • Commit: 5e67104

Test stats 🧪

Test Results
Failed 0
Passed 2286
Skipped 19
Total 2305

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 2286
Skipped 19
Total 2305

@tobiasstadler
Copy link
Contributor Author

Can somebody please do a review?

@SylvainJuge SylvainJuge enabled auto-merge (squash) June 24, 2021 15:12
auto-merge was automatically disabled June 24, 2021 16:43

Head branch was pushed to by a user without write access

@tobiasstadler
Copy link
Contributor Author

@SylvainJuge I merged the master branch (which disabled the auto-merge), would you mind merging it?

@eyalkoren
Copy link
Contributor

@SylvainJuge this may considerably increase the number of times ServletApiAdvice can be invoked. Do you think we should add a quick abort when not required? For example - if there is an active transaction when ServletApiAdvice#onEnterServletService() starts - abort early; also make sure ServletApiAdvice#onExitServletService() aborts early when not required (e.g. when onEnterServletService aborted).

@tobiasstadler
Copy link
Contributor Author

@eyalkoren Something like

ElasticApmTracer tracer = GlobalTracer.getTracerImpl();
if(tracer == null || tracer.currentTransaction() != null) {
    return null;
}
@SylvainJuge
Copy link
Member

I did run a few wall-clock benchmarks with & without this change and did not found significant impact.

I did test with Tomcat though, which means that the ApplicationFilterChain is a parent of any call to Filter.doFilter configured within the application, hence making the Advice exit early as the transaction scope is defined by ApplicationFilterChain which extends FilterChain (but that might be an implementation detail only for Tomcat`.

Alternatively, for the specific case of Spark, the usage of Servlet API is quite non-standard, and maybe adding a proper support for Jetty handler to handle the transaction would also work (albeit it's definitely a bit more work).

@tobiasstadler
Copy link
Contributor Author

@SylvainJuge It is the same for Undertow (But ApplicationFilterChain is called FilterChainImpl)

@tobiasstadler
Copy link
Contributor Author

So how should we proceed?

@SylvainJuge SylvainJuge merged commit ec7781c into elastic:master Jul 1, 2021
@tobiasstadler
Copy link
Contributor Author

Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants