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

Fix NoMethodError when running Datadog.configure after only requiring core #2008

Merged
merged 1 commit into from
May 10, 2022

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented May 9, 2022

The fix in #1998, specifically in 2e5d1ee broke using datadog/core directly without require 'ddtrace'.

For instance:

bundle exec ruby -e "require 'datadog/core'; Datadog.configure { }"
Traceback (most recent call last):
  9: from -e:1:in `<main>'
  8: from .../lib/datadog/core/configuration.rb:89:in `configure'
  7: from .../lib/datadog/core/configuration.rb:223:in `safely_synchronize'
  6: from .../lib/datadog/core/configuration.rb:223:in `synchronize'
  5: from .../lib/datadog/core/configuration.rb:225:in `block in safely_synchronize'
  4: from .../lib/datadog/core/configuration.rb:94:in `block in configure'
  3: from .../lib/datadog/core/configuration.rb:243:in `build_components'
  2: from .../lib/datadog/core/configuration.rb:243:in `new'
  1: from .../lib/datadog/core/configuration/components.rb:345:in `initialize'
.../lib/datadog/core/configuration/components.rb:202:in `build_profiler': undefined method `supported?' for Datadog::Profiling:Module (NoMethodError)

As a workaround, I've added a require 'datadog/profiling' in build_profiler: this avoids re-adding the circular dependency issue, but fixes this use-case.

Additionally, I've made is such that profiling is only loaded if it is enabled, which means that customers not using it will not need to load it, which is a nice bonus vs what we did prior to #1998.

…ng core

The fix in #1998, specifically in
2e5d1ee
broke using `datadog/core` directly without `require 'ddtrace'`.

For instance:

```
bundle exec ruby -e "require 'datadog/core'; Datadog.configure { }"
Traceback (most recent call last):
  9: from -e:1:in `<main>'
  8: from .../lib/datadog/core/configuration.rb:89:in `configure'
  7: from .../lib/datadog/core/configuration.rb:223:in `safely_synchronize'
  6: from .../lib/datadog/core/configuration.rb:223:in `synchronize'
  5: from .../lib/datadog/core/configuration.rb:225:in `block in safely_synchronize'
  4: from .../lib/datadog/core/configuration.rb:94:in `block in configure'
  3: from .../lib/datadog/core/configuration.rb:243:in `build_components'
  2: from .../lib/datadog/core/configuration.rb:243:in `new'
  1: from .../lib/datadog/core/configuration/components.rb:345:in `initialize'
.../lib/datadog/core/configuration/components.rb:202:in `build_profiler': undefined method `supported?' for Datadog::Profiling:Module (NoMethodError)
```

As a workaround, I've added a `require 'datadog/profiling'` in
`build_profiler`: this avoids re-adding the circular dependency issue,
but fixes this use-case.

Additionally, I've made is such that profiling is only loaded if it
is enabled, which means that customers not using it will not need to
load it, which is a nice bonus vs what we did prior to #1998.
@ivoanjo ivoanjo requested a review from a team May 9, 2022 11:32
@codecov-commenter
Copy link

Codecov Report

Merging #2008 (d1d7af7) into master (cf27d41) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2008   +/-   ##
=======================================
  Coverage   97.81%   97.81%           
=======================================
  Files        1008     1008           
  Lines       51143    51145    +2     
=======================================
+ Hits        50023    50025    +2     
  Misses       1120     1120           
Impacted Files Coverage Δ
lib/datadog/core/configuration/components.rb 98.78% <100.00%> (+0.01%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@ivoanjo ivoanjo merged commit 3661038 into master May 10, 2022
@ivoanjo ivoanjo deleted the ivoanjo/fix-breakage-when-profiler-is-not-loaded branch May 10, 2022 07:22
@github-actions github-actions bot added this to the 1.1.0 milestone May 10, 2022
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.

3 participants