-
Notifications
You must be signed in to change notification settings - Fork 375
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
Add development environment detection #3036
Conversation
9b05ccd
to
bfaac40
Compare
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.
👍 LGTM
I suspect you're already aware (because you reused some code from it?) but just-in-case I'll point out that the EnvironmentLogger
does something similar so it would be a good target to be updated to use the new helper:
dd-trace-rb/lib/datadog/core/diagnostics/environment_logger.rb
Lines 39 to 53 in b1bec43
# Are we logging the environment data? | |
def log? | |
startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled | |
if startup_logs_enabled.nil? | |
!repl? # Suppress logs if we running in a REPL | |
else | |
startup_logs_enabled | |
end | |
end | |
REPL_PROGRAM_NAMES = %w[irb pry].freeze | |
def repl? | |
REPL_PROGRAM_NAMES.include?($PROGRAM_NAME) | |
end |
# RSpec is detected through the $PROGRAM_NAME. | ||
# Changing it will make RSpec detection to return false. | ||
# | ||
# We change the $PROGRAM_NAME instead of stubbing | ||
# `Datadog::Core::Environment::Execution.rspec?` because | ||
# otherwise we'll have no real test for non-RSpec cases. | ||
around do |example| | ||
begin | ||
original = $PROGRAM_NAME | ||
$PROGRAM_NAME = 'not-rspec' | ||
example.run | ||
ensure | ||
$PROGRAM_NAME = original | ||
end | ||
end |
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.
This made me think that one possible alternative implementation strategy is to maybe have a proc-per-thing we want to detect, e.g.
RSPEC_PROBE = proc { $PROGRAM_NAME.end_with?(RSPEC_PROGRAM_NAME) }
MINITEST_PROBE = proc { ... }
def test?(test_probes: [RSPEC_PROBE, MINITEST_PROBE])
test_probes.any?(&:call)
end
then we could override individual probes (or even dependency inject them).
This to say -- it came to mind; I think the current version is great as well so as usual with my random suggestions, feel free to ignore :)
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.
I agree that this suggested approach looks good!
I think the file is small now to keep it as it, but it's definitely a great alternative.
The |
Codecov Report
@@ Coverage Diff @@
## master #3036 +/- ##
==========================================
+ Coverage 98.08% 98.12% +0.03%
==========================================
Files 1317 1323 +6
Lines 74362 74649 +287
Branches 3402 3403 +1
==========================================
+ Hits 72941 73248 +307
+ Misses 1421 1401 -20
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
👍 LGTM
This PR adds a utility to detect if
ddtrace
is running in a development environment (an environment that is unlikely to need to send traces, profiles, perform appsec checking).This will enable us to selectively disable heavy features (background workers, network requests) performed by
ddtrace
when the environment does not need it. This is especially helpful when running tests withddtrace
installed.