Prevent public API related spans from being recycled#1859
Prevent public API related spans from being recycled#1859eyalkoren merged 10 commits intoelastic:masterfrom
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
...-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentationTest.java
Show resolved
Hide resolved
...ugin/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java
Outdated
Show resolved
Hide resolved
SylvainJuge
left a comment
There was a problem hiding this comment.
LGTM, I'm fine with having webflux test app rely on internal API for now, we can revisit this later if required to. 99.99% of the time this app will only be used for unit testing.
...-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentationTest.java
Show resolved
Hide resolved
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) | ||
| public static void incrementReferences(@Advice.Argument(0) Object span) { | ||
| ((AbstractSpan<?>) span).incrementReferences(); |
There was a problem hiding this comment.
Have you considered instrumenting AbstractSpanImpl directly and incrementing the reference there? The advantage is that would also work with older versions of the API.
There was a problem hiding this comment.
If you mean the constructor, then - yes, I considered but preferred this.
As far as I see it - there is no problem to any current API user (besides the one that reported this issue) and all future users will use the newer API version.
|
Thanks for the honest feedback. We've seen enough misuse that caused a lot of grief to our community, which made us decide that the performance gains of recycling do not worth the pain, only in the narrow context of public API spans/transactions. This PR only makes sure that spans/transactions "touched" by the public API pass away in the natural Java way, which is garbage collection, instead of being recycled. So if your recycling validation would have passed, that would be a bug in this PR that requires fixing 🙂 .
Yes, for the time being. |

What does this PR do?
In order to work around misuse of the public activation API, related spans will not be recycled.
This way we can ensure there is no improper usage of recycled-and-still-referenced span objects at the cost of creating some garbage.
Checklist
I have made corresponding changes to the documentationI decided not to add anything to the documentation about that, as I think it would only cause confusion.