forked from DataDog/dd-trace-rb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "DEBUG-2334 Add Debugger component (DataDog#3640)""
This reverts commit 554b6d9.
- Loading branch information
Showing
16 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'debugger/component' | ||
require_relative 'debugger/configuration' | ||
require_relative 'debugger/extensions' | ||
|
||
module Datadog | ||
# Namespace for Datadog Debugger instrumentation | ||
module Debugger | ||
class << self | ||
def enabled? | ||
Datadog.configuration.debugger.enabled | ||
end | ||
end | ||
|
||
# Expose Debugger to global shared objects | ||
Extensions.activate! | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Debugger | ||
# Core-pluggable component for Debugger | ||
class Component | ||
class << self | ||
def build(settings) | ||
return unless settings.respond_to?(:debugger) && settings.debugger.enabled | ||
|
||
new | ||
end | ||
end | ||
|
||
def shutdown!(replacement = nil); end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Debugger | ||
# Configuration for Debugger | ||
module Configuration | ||
end | ||
end | ||
end | ||
|
||
require_relative 'configuration/settings' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Debugger | ||
module Configuration | ||
# Settings | ||
module Settings | ||
def self.extended(base) | ||
base = base.singleton_class unless base.is_a?(Class) | ||
add_settings!(base) | ||
end | ||
|
||
def self.add_settings!(base) | ||
base.class_eval do | ||
settings :debugger do | ||
option :enabled do |o| | ||
o.type :bool | ||
o.env 'DD_DYNAMIC_INSTRUMENTATION_ENABLED' | ||
o.default false | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'configuration' | ||
|
||
module Datadog | ||
module Debugger | ||
# Extends Datadog tracing with Debugger features | ||
module Extensions | ||
# Inject Debugger into global objects. | ||
def self.activate! | ||
Core::Configuration::Settings.extend(Configuration::Settings) | ||
end | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Datadog | ||
module Debugger | ||
def self.enabled?: () -> bool | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Datadog | ||
module Debugger | ||
class Component | ||
def self.build: (Datadog::Core::Configuration::Settings settings) -> Datadog::Debugger::Component? | ||
|
||
private | ||
|
||
def shutdown!: () -> untyped | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Datadog | ||
module Debugger | ||
module Configuration | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Datadog | ||
module Debugger | ||
module Configuration | ||
# Settings | ||
module Settings | ||
extend Datadog::Core::Configuration::Base::ClassMethods | ||
include Datadog::Core::Configuration::Base::InstanceMethods | ||
extend Datadog::Core::Configuration::Options::ClassMethods | ||
include Datadog::Core::Configuration::Options::InstanceMethods | ||
|
||
def self.extended: (untyped base) -> untyped | ||
|
||
def self.add_settings!: (untyped base) -> untyped | ||
|
||
def self.enabled: -> bool | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Datadog | ||
module Debugger | ||
module Extensions | ||
def self.activate!: () -> untyped | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'datadog/debugger/component' | ||
|
||
RSpec.describe Datadog::Debugger::Component do | ||
describe '.build' do | ||
let(:settings) do | ||
settings = Datadog::Core::Configuration::Settings.new | ||
settings.debugger.enabled = debugger_enabled | ||
settings | ||
end | ||
|
||
context 'when debugger is enabled' do | ||
let(:debugger_enabled) { true } | ||
|
||
it 'returns a Datadog::Debugger::Component instance' do | ||
component = described_class.build(settings) | ||
expect(component).to be_a(described_class) | ||
end | ||
end | ||
|
||
context 'when debugger is disabled' do | ||
let(:debugger_enabled) { false } | ||
|
||
it 'returns nil' do | ||
component = described_class.build(settings) | ||
expect(component).to be nil | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Datadog::Debugger::Configuration::Settings do | ||
subject(:settings) { Datadog::Core::Configuration::Settings.new } | ||
|
||
describe 'debugger' do | ||
describe '#enabled' do | ||
subject(:enabled) { settings.debugger.enabled } | ||
|
||
context 'when DD_DYNAMIC_INSTRUMENTATION_ENABLED' do | ||
around do |example| | ||
ClimateControl.modify('DD_DYNAMIC_INSTRUMENTATION_ENABLED' => debugger_enabled) do | ||
example.run | ||
end | ||
end | ||
|
||
context 'is not defined' do | ||
let(:debugger_enabled) { nil } | ||
|
||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'is defined' do | ||
let(:debugger_enabled) { 'true' } | ||
|
||
it { is_expected.to eq(true) } | ||
end | ||
end | ||
end | ||
|
||
describe '#enabled=' do | ||
subject(:set_debugger_enabled) { settings.debugger.enabled = debugger_enabled } | ||
|
||
[true, false].each do |value| | ||
context "when given #{value}" do | ||
let(:debugger_enabled) { value } | ||
|
||
before { set_debugger_enabled } | ||
|
||
it { expect(settings.debugger.enabled).to eq(value) } | ||
end | ||
end | ||
end | ||
end | ||
end |