[PROF-7440] Add workaround for incorrect invoke location when logging gem is in use #3183
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?
In #2950, we added a fallback for nameless threads: we use their "invoke location", as shown by Ruby in the default
Thread#to_s
. The invoke location is the file and line of the first method of the thread.This fallback has an issue: when thread creation is monkey patched. One common source of this is the
logging
gem. When thelogging
gem monkey patches thread creation, every thread will have the same invoke location, which will point to thelogging
gem.This made the fallback invoke location worse than not having anything.
To work around this, this PR changes the profiler so that when the invoke location belongs to the
logging
gem, it's not used, and a simpler(Unnamed thread)
placeholder is used instead.Motivation:
This issue came up when testing the timeline feature with some of the internal Ruby apps.
Additional Notes:
In the future we could probably explore a more generic fix (e.g. using
Thread.method(:new).source_location
or something like that to detect redefinition) but doing that from the profiler native code is a bit more work so I decided to go with a simpler approach.How to test the change?
Change includes test coverage. You can also see the thread name difference on an app by creating a simple thread before/after loading the
logging
gem and see the fallback name for the thread.For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.