-
Notifications
You must be signed in to change notification settings - Fork 373
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 "circular require considered harmful" warnings in profiling and tracing integrations #1998
Merged
Conversation
This file contains 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
…tions A bunch of integrations had a structure where the `integration.rb` file required `patcher.rb` and then `patcher.rb` did the same thing. When running Ruby with warnings enabled, this generated a lot of similar-looking warnings: ``` $ bundle exec ruby -W2 -S -e 'require "ddtrace"' .../lib/datadog/tracing/contrib/action_view/patcher.rb:7: warning: loading in progress, circular require considered harmful - .../lib/datadog/tracing/contrib/action_view/integration.rb from -e:1:in `<main>' from -e:1:in `require' from .../lib/ddtrace.rb:5:in `<top (required)>' from .../lib/ddtrace.rb:5:in `require' from .../lib/datadog/tracing/contrib.rb:36:in `<top (required)>' from .../lib/datadog/tracing/contrib.rb:36:in `require' from .../lib/datadog/tracing/contrib/action_view/integration.rb:4:in `<top (required)>' from .../lib/datadog/tracing/contrib/action_view/integration.rb:4:in `require' from .../lib/datadog/tracing/contrib/action_view/patcher.rb:7:in `<top (required)>' from .../lib/datadog/tracing/contrib/action_view/patcher.rb:7:in `require' ``` I checked all integrations and these were the ones where the patcher still required the `integration.rb` file. On all others this was already correct.
The `datadog/profiling/tasks/setup` file is only directly required by `datadog/profiling` and so it does not need to itself require `datadog/profiling` back. This eliminates yet another warning: ``` .../lib/datadog/profiling/tasks/setup.rb:4: warning: loading in progress, circular require considered harmful - .../lib/datadog/profiling.rb from -e:1:in `<main>' from -e:1:in `require' from .../lib/ddtrace.rb:11:in `<top (required)>' from .../lib/ddtrace.rb:11:in `require' from .../lib/datadog/profiling.rb:7:in `<top (required)>' from .../lib/datadog/profiling.rb:9:in `<module:Datadog>' from .../lib/datadog/profiling.rb:166:in `<module:Profiling>' from .../lib/datadog/profiling.rb:155:in `load_profiling' from .../lib/datadog/profiling.rb:155:in `require' from .../lib/datadog/profiling/tasks/setup.rb:4:in `<top (required)>' from .../lib/datadog/profiling/tasks/setup.rb:4:in `require' ```
…ions The `tracing/contrib` file already requires `tracing/contrib/extensions` so the latter should not require the former again. This eliminates this warning: ``` .../lib/datadog/tracing/contrib/extensions.rb:7: warning: loading in progress, circular require considered harmful - .../lib/datadog/tracing/contrib.rb from -e:1:in `<main>' from -e:1:in `require' from .../lib/ddtrace.rb:5:in `<top (required)>' from .../lib/ddtrace.rb:5:in `require' from .../lib/datadog/tracing/contrib.rb:5:in `<top (required)>' from .../lib/datadog/tracing/contrib.rb:5:in `require' from .../lib/datadog/tracing/contrib/extensions.rb:7:in `<top (required)>' from .../lib/datadog/tracing/contrib/extensions.rb:7:in `require' ```
The `datadog/profiling` file already requires the core, so `datadog/profiling/encoding/profile` shouldn't require it as well. Furthermore, `ddtrace.rb` and `datadog/profiling` already require the core, so `core/configuration/components` should not require `datadog/profiling` back. Fixes the following warnings: ``` .../lib/datadog/profiling.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb from -e:1:in `<main>' from -e:1:in `require' from .../lib/ddtrace.rb:4:in `<top (required)>' from .../lib/ddtrace.rb:4:in `require' from .../lib/datadog/tracing.rb:3:in `<top (required)>' from .../lib/datadog/tracing.rb:3:in `require' from .../lib/datadog/core.rb:57:in `<top (required)>' from .../lib/datadog/core.rb:57:in `require' from .../lib/datadog/core/extensions.rb:3:in `<top (required)>' from .../lib/datadog/core/extensions.rb:3:in `require' from .../lib/datadog/core/configuration.rb:4:in `<top (required)>' from .../lib/datadog/core/configuration.rb:4:in `require' from .../lib/datadog/core/configuration/components.rb:14:in `<top (required)>' from .../lib/datadog/core/configuration/components.rb:14:in `require' from .../lib/datadog/profiling.rb:3:in `<top (required)>' from .../lib/datadog/profiling.rb:3:in `require' .../lib/datadog/profiling/encoding/profile.rb:6: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb from -e:1:in `<main>' from -e:1:in `require' from .../lib/ddtrace.rb:4:in `<top (required)>' from .../lib/ddtrace.rb:4:in `require' from .../lib/datadog/tracing.rb:3:in `<top (required)>' from .../lib/datadog/tracing.rb:3:in `require' from .../lib/datadog/core.rb:57:in `<top (required)>' from .../lib/datadog/core.rb:57:in `require' from .../lib/datadog/core/extensions.rb:3:in `<top (required)>' from .../lib/datadog/core/extensions.rb:3:in `require' from .../lib/datadog/core/configuration.rb:4:in `<top (required)>' from .../lib/datadog/core/configuration.rb:4:in `require' from .../lib/datadog/core/configuration/components.rb:14:in `<top (required)>' from .../lib/datadog/core/configuration/components.rb:14:in `require' from .../lib/datadog/profiling.rb:7:in `<top (required)>' from .../lib/datadog/profiling.rb:9:in `<module:Datadog>' from .../lib/datadog/profiling.rb:166:in `<module:Profiling>' from .../lib/datadog/profiling.rb:156:in `load_profiling' from .../lib/datadog/profiling.rb:156:in `require' from .../lib/datadog/profiling/transport/io.rb:4:in `<top (required)>' from .../lib/datadog/profiling/transport/io.rb:4:in `require' from .../lib/datadog/profiling/encoding/profile.rb:6:in `<top (required)>' from .../lib/datadog/profiling/encoding/profile.rb:6:in `require' ```
marcotc
approved these changes
May 5, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹
ivoanjo
added a commit
that referenced
this pull request
May 9, 2022
…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.
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.
The warnings can be spotted by running Ruby with warnings enabled, e.g.
See individual commits for details.