Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
# Load other products (must follow tracing)
require_relative 'datadog/profiling'
require_relative 'datadog/appsec'
# Line probes will not work on Ruby < 2.6 because of lack of :script_compiled
# trace point. Only load DI on supported Ruby versions.
require_relative 'datadog/di' if RUBY_VERSION >= '2.6' && RUBY_ENGINE != 'jruby'
require_relative 'datadog/di'
require_relative 'datadog/kit'
8 changes: 4 additions & 4 deletions lib/datadog/core/telemetry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ def products
profiler: {
enabled: Datadog::Profiling.enabled?,
},
# DEV: Not implemented yet
# dynamic_instrumentation: {
# enabled: true,
# }
dynamic_instrumentation: {
enabled: defined?(Datadog::DI) && Datadog::DI.respond_to?(:enabled?) && Datadog::DI.enabled?,
}
}

if (unsupported_reason = Datadog::Profiling.unsupported_reason)
Expand All @@ -91,6 +90,7 @@ def products
end

TARGET_OPTIONS = %w[
dynamic_instrumentation.enabled
logger.level
profiling.advanced.code_provenance_enabled
profiling.advanced.endpoint.collection.enabled
Expand Down
37 changes: 5 additions & 32 deletions lib/datadog/di.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
# frozen_string_literal: true

require_relative 'di/logger'
require_relative 'di/base'
require_relative 'di/error'
require_relative 'di/code_tracker'
require_relative 'di/component'
require_relative 'di/configuration'
require_relative 'di/extensions'
require_relative 'di/instrumenter'
require_relative 'di/probe'
require_relative 'di/probe_builder'
require_relative 'di/probe_manager'
require_relative 'di/probe_notification_builder'
require_relative 'di/probe_notifier_worker'
require_relative 'di/redactor'
require_relative 'di/remote'
require_relative 'di/serializer'
#require_relative 'di/transport'
require_relative 'di/transport/http'
require_relative 'di/utils'

module Datadog
# Namespace for Datadog dynamic instrumentation.
Expand Down Expand Up @@ -52,19 +36,8 @@ def component
end
end

if %w(1 true).include?(ENV['DD_DYNAMIC_INSTRUMENTATION_ENABLED']) # steep:ignore
# For initial release of Dynamic Instrumentation, activate code tracking
# only if DI is explicitly requested in the environment.
# Code tracking is required for line probes to work; see the comments
# above for the implementation of the method.
#
# If DI is enabled programmatically, the application can (and must,
# for line probes to work) activate tracking in an initializer.
# We seem to have Datadog.logger here already
Datadog.logger.debug("di: activating code tracking")
Datadog::DI.activate_tracking
end

require_relative 'di/contrib'

Datadog::DI::Contrib.load_now_or_later
# Line probes will not work on Ruby < 2.6 because of lack of :script_compiled
# trace point. Activate DI automatically on supported Ruby versions but
# always load its settings so that, for example, turning DI off when
# we are on Ruby 2.5 does not produce exceptions.
require_relative 'di/boot' if RUBY_VERSION >= '2.6' && RUBY_ENGINE != 'jruby'
34 changes: 34 additions & 0 deletions lib/datadog/di/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require_relative 'logger'
require_relative 'base'
require_relative 'error'
require_relative 'code_tracker'
require_relative 'component'
require_relative 'instrumenter'
require_relative 'probe'
require_relative 'probe_builder'
require_relative 'probe_manager'
require_relative 'probe_notification_builder'
require_relative 'probe_notifier_worker'
require_relative 'redactor'
require_relative 'serializer'
require_relative 'transport/http'
require_relative 'utils'

if %w[1 true yes].include?(ENV['DD_DYNAMIC_INSTRUMENTATION_ENABLED']) # steep:ignore
# For initial release of Dynamic Instrumentation, activate code tracking
# only if DI is explicitly requested in the environment.
# Code tracking is required for line probes to work; see the comments
# above for the implementation of the method.
#
# If DI is enabled programmatically, the application can (and must,
# for line probes to work) activate tracking in an initializer.
# We seem to have Datadog.logger here already
Datadog.logger.debug("di: activating code tracking")
Datadog::DI.activate_tracking
end

require_relative 'contrib'

Datadog::DI::Contrib.load_now_or_later
2 changes: 2 additions & 0 deletions lib/datadog/di/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class << self
PRODUCT = 'LIVE_DEBUGGING'

def products
# TODO: do not send our product on unsupported runtimes
# (Ruby 2.5 / JRuby)
[PRODUCT]
end

Expand Down
1 change: 1 addition & 0 deletions sig/datadog/di.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Datadog
module DI
def self.component: () -> Component?
def self.enabled?: () -> bool

end
end
Empty file added sig/datadog/di/boot.rbs
Empty file.
4 changes: 4 additions & 0 deletions spec/datadog/core/telemetry/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def contain_configuration(*array)
appsec: {
enabled: false,
},
dynamic_instrumentation: {
enabled: false,
},
profiler: hash_including(enabled: false),
},
configuration: contain_configuration(
Expand All @@ -62,6 +65,7 @@ def contain_configuration(*array)
['DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED', true],
['DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED', false],
['DD_TRACE_PEER_SERVICE_MAPPING', 'foo:bar'],
['dynamic_instrumentation.enabled', false],
['logger.level', 0],
['profiling.advanced.code_provenance_enabled', true],
['profiling.advanced.endpoint.collection.enabled', true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
let(:expected_products_hash) do
{
'appsec' => { 'enabled' => false },
'dynamic_instrumentation' => { 'enabled' => false },
'profiler' => { 'enabled' => false },
}
end
Expand Down
1 change: 1 addition & 0 deletions spec/datadog/di/code_tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'datadog/di'
require 'datadog/di/code_tracker'
require "datadog/di/spec_helper"

RSpec.describe Datadog::DI::CodeTracker do
Expand Down
3 changes: 3 additions & 0 deletions spec/datadog/di/integration/probe_notifier_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require "datadog/di/spec_helper"
require 'datadog/di'
require "datadog/di/probe_notifier_worker"

# standard tries to wreck regular expressions in this fiel
# rubocop:disable Style/PercentLiteralDelimiters
# rubocop:disable Layout/LineContinuationSpacing

RSpec.describe Datadog::DI::ProbeNotifierWorker do
di_test

let(:worker) do
described_class.new(settings, logger, agent_settings: agent_settings)
end
Expand Down
27 changes: 26 additions & 1 deletion spec/loading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
end
end

RSpec.describe 'load core only and configure library' do
RSpec.describe 'load core only and configure library with no settings' do
let(:code) do
<<-E
if defined?(Datadog)
Expand All @@ -76,3 +76,28 @@
expect(rv).to be true
end
end

RSpec.describe 'load datadog and enable dynamic instrumentation' do
let(:code) do
<<-E
if defined?(Datadog)
unless Datadog.constants == [:VERSION]
exit 1
end
end

require 'datadog'

Datadog.configure do |c|
c.dynamic_instrumentation.enabled = true
end
E
end

# DI is not available in all environments, however asking for it to be
# turned on should not produce exceptions.
it 'configures successfully' do
rv = system("ruby -e #{Shellwords.shellescape(code)}")
expect(rv).to be true
end
end
Loading