Fix service name caching based on context path#1326
Merged
eyalkoren merged 2 commits intoelastic:masterfrom Aug 6, 2020
Merged
Fix service name caching based on context path#1326eyalkoren merged 2 commits intoelastic:masterfrom
eyalkoren merged 2 commits intoelastic:masterfrom
Conversation
felixbarny
approved these changes
Aug 5, 2020
Member
felixbarny
left a comment
There was a problem hiding this comment.
Please describe the error scenario in a comment. Either in code or in the PR description. This makes it much easier to understand the context of a change compared to linking to a long thread.
Brilliant investigation BTW and sorry for introducing the bug 😬
| public class ServletGlobalState { | ||
|
|
||
| public static final Set<String> nameInitialized = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); | ||
| public static final WeakConcurrentMap<ClassLoader, Boolean> nameInitialized = WeakMapSupplier.createMap(); |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes service name caching.
Context
A bug reported in https://discuss.elastic.co/t/apm-agent-not-working-after-updating-war-in-tomcat/239750 - after un-deploying and re-deploying a web app on a Servlet container, the web-app-specific service name (based on auto-discovery) is not used anymore. Instead, events are reported with the generic process service name.
The problem is with two inconsistent caches of the service name - it is cached in
ServletTransactionHelperbased on the context path and then inElasticApmTracerbased on the instrumented class's initiating class loader. When redeploying an app, the same context app is used with a different class loader and this causes the problem.NOTE: I am not sure the first caching even worth it, only a few String comparisons. Maybe it's enough to leave only the second (class-loader-based) caching in
ElasticApmTracer).Checklist