Module: Datadog::Core::Environment::Execution

Defined in:
lib/datadog/core/environment/execution.rb

Overview

Provides information about the execution environment on the current process.

Class Method Summary collapse

Class Method Details

.development?Boolean

Is this process running in a development environment? This can be used to make decisions about when to enable background systems like worker threads or telemetry.

Returns:

  • (Boolean)


14
15
16
# File 'lib/datadog/core/environment/execution.rb', line 14

def development?
  !!(webmock_enabled? || repl? || test? || rails_development?)
end

.webmock_enabled?Boolean

WebMock stores the reference to ‘Net::HTTP` with constant `OriginalNetHTTP`, and when WebMock enables, the adapter swaps `Net::HTTP` reference to its mock object, @webMockNetHTTP.

Hence, we can detect by

1. Checking if `Net::HTTP` is referring to mock object
=> ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))

2. Checking if `Net::HTTP` is referring to the original one
=> ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP)

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/datadog/core/environment/execution.rb', line 27

def webmock_enabled?
  defined?(::WebMock::HttpLibAdapters::NetHttpAdapter) &&
    defined?(::Net::HTTP) &&
    ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
end