Skip to content
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

[PROF-3514] Skip CPU time instrumentation if logging gem is detected #1557

Merged

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jun 17, 2021

...instead, customers will get a log message as follows:

    INFO -- ddtrace: [ddtrace] (/app/lib/ddtrace/profiling/tasks/setup.rb
    :44:in `activate_cpu_extensions') CPU time profiling skipped because
    native CPU time is not supported: The `logging` gem is installed and
    its thread inherit context feature is enabled. Please add
    LOGGING_INHERIT_CONTEXT=false to your application's environment
    variables to disable the conflicting `logging` gem feature. See
    https://github.com/TwP/logging/pull/230 for details. Profiles
    containing Wall time will still be reported.

This is a repeat of #1362 -- the logging gem also monkey patches Thread initialization using alias_method, which is incompatible with our instrumentation that uses preload.

For details, see TwP/logging#230 where we submitted a fix to the upstream gem.

Right now the only way to avoid this issue and still enable proflier is to either remove the logging gem or to disable the feature using the LOGGING_INHERIT_CONTEXT environment variable.

If/when the gem creators accept our proposed change and release it, we'll need to revise this to take that into consideration, as we do for rollbar.

NOTE: I'm not entirely happy with the complexity that is accumulating for the tests, but I've decided to not refactor it yet. If we need to add more gems, we should definitely refactor the tests. My hope is that soon we can get rid of our Thread monkey patches, and thus get rid of all of this instead.

@ivoanjo ivoanjo requested a review from a team June 17, 2021 12:03
Instead, customers will get the following log message:

```
INFO -- ddtrace: [ddtrace] (/app/lib/ddtrace/profiling/tasks/setup.rb
:44:in `activate_cpu_extensions') CPU time profiling skipped because
native CPU time is not supported: The `logging` gem is installed and
its thread inherit context feature is enabled. Please add
LOGGING_INHERIT_CONTEXT=false to your application's environment
variables to disable the conflicting `logging` gem feature. See
TwP/logging#230 for details. Profiles
containing Wall time will still be reported.
```

This is a repeat of #1362 -- the logging gem also monkey patches
`Thread` initialization using `alias_method`, which is incompatible
with our instrumentation that uses `preload`.

For details, see TwP/logging#230 where we
submitted a fix to the upstream gem.

Right now the only way to avoid this issue and still enable proflier is
to either remove the logging gem or to disable the feature using the
`LOGGING_INHERIT_CONTEXT` environment variable.

If/when the gem creators accept our proposed change and release it,
we'll need to revise this to take that into consideration, as we do
for rollbar.

NOTE: I'm not entirely happy with the complexity that is accumulating
for the tests, but I've decided to not refactor it yet. If we need
to add more gems, we should definitely refactor the tests. My hope is
that soon we can get rid of our `Thread` monkey patches, and thus get
rid of all of this instead.
@ivoanjo ivoanjo force-pushed the fix/skip-cpu-time-instrumentation-if-logging-is-around branch from add4289 to cef8067 Compare June 17, 2021 12:04
@codecov-commenter
Copy link

Codecov Report

Merging #1557 (cef8067) into master (e702645) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1557   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files         878      878           
  Lines       42429    42452   +23     
=======================================
+ Hits        41683    41706   +23     
  Misses        746      746           
Impacted Files Coverage Δ
lib/ddtrace/profiling/ext/cpu.rb 100.00% <100.00%> (ø)
spec/ddtrace/profiling/ext/cpu_spec.rb 100.00% <100.00%> (ø)
spec/ddtrace/profiling/integration_spec.rb 94.63% <0.00%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e702645...cef8067. Read the comment docs.

@ivoanjo ivoanjo merged commit 80ead5a into master Jun 18, 2021
@ivoanjo ivoanjo deleted the fix/skip-cpu-time-instrumentation-if-logging-is-around branch June 18, 2021 08:14
@github-actions github-actions bot added this to the 0.51.0 milestone Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants