-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add Scala concurrent plugin #1048
Conversation
💚 CLA has been signed |
@SylvainJuge As I just started exploring the APM, I wanted to start with a test that just checks if it is matching one of the methods I wrote a |
...concurrent-plugin/src/main/scala/co/elastic/apm/agent/concurrent/FutureInstrumentation.scala
Outdated
Show resolved
Hide resolved
...urrent-plugin/src/test/scala/co/elastic/apm/agent/concurrent/FutureInstrumentationSpec.scala
Outdated
Show resolved
Hide resolved
...concurrent-plugin/src/main/scala/co/elastic/apm/agent/concurrent/FutureInstrumentation.scala
Outdated
Show resolved
Hide resolved
...-plugin/src/test/scala/co/elastic/apm/agent/scala/concurrent/FutureInstrumentationSpec.scala
Outdated
Show resolved
Hide resolved
...-plugin/src/test/scala/co/elastic/apm/agent/scala/concurrent/FutureInstrumentationSpec.scala
Outdated
Show resolved
Hide resolved
...urrent-plugin/src/main/java/co/elastic/apm/agent/scala/concurrent/FutureInstrumentation.java
Outdated
Show resolved
Hide resolved
The tests I created are passing now. But it is hard for me to judge to what extent these tests are a good representation of reality and testing edge-cases. The project I created to test a lot of tooling together would also be a good test run: https://github.com/milanvdm/scala-elastic-apm |
Here are some instructions around that: https://github.com/elastic/apm-agent-java#build-form-source |
Thanks! I managed to release it locally and use it in my test project as well. Without the specific scala-concurrent instrumentation, it was not able to trace all the different parts of the program. From some talks with the maintainer of Kamon, this seems to be related to how the scala execution-context handles an internal queue for scheduling. With the newly added scala-concurrent instrumentation, it was able to trace all 20 http-calls and 20 database requests, all done in an async way: https://github.com/milanvdm/scala-elastic-apm/blob/master/src/main/scala/me/milan/MainF.scala Not sure what the next steps would be to get this PR merged :) |
To summarize my current thinking: Ideally, we'd capture context when it's scheduled for execution and restore the context on execution. It seems like with the current instrumentation that works well most of the time. Unless there's something that breaks context propagation like something related to In an ideal world, we should fix the loss of context. Pragmatically, it's probably not a bad idea to just combine the two approaches. I expect nothing bad will happen if both the Promise instrumentation (which captures the context when the promise is created and restores when it executes) and the executor instrumentation capture and restore the same context. I'm willing to give this a shot. In the |
@felixbarny Thanks for the write up :) I fully agree with your arguments. Once this is merged, I'll continue with adding some extra libraries for Scala. Some leftover comments (which may need to be solved in a different PR):
I can create some issues for that if you want to track it. |
Shall I also create an issue pointing to my test-branch that shows an example on where the AsyncHttpClient seems to lose context? |
Codecov Report
@@ Coverage Diff @@
## master #1048 +/- ##
=========================================
Coverage 59.31% 59.31%
Complexity 90 90
=========================================
Files 354 354
Lines 16249 16249
Branches 2268 2268
=========================================
Hits 9638 9638
Misses 5958 5958
Partials 653 653 Continue to review full report at Codecov.
|
Yes, that'd be great |
As a last attempt, could you try out the artifact from #1230? I've added some fixes around |
@felixbarny Will have a look :) Do you build artifacts for branches or do I need to build it locally? |
Yes, there’s a link to the artifacts in the comment added by the CI |
@felixbarny Same issue when using the artifact from that branch |
Tests are failing with NPEs on CI. Could you have a look? |
@felixbarny For some reason, |
Ah, yes. You need to start the agent after building it and before starting transactions |
What does this PR do?
This PR is a draft to add specific Scala support to the ElasticAPM agent.
The goal is to add basic support for Scala Futures.
Known issues
Checklist
Related issues
Part of #818