Skip to content

DEBUG-3700 more explicitly access active remote #4642

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 0 additions & 15 deletions lib/datadog/core/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ module Datadog
module Core
# Module to interact with core remote component
module Remote
class << self
def active_remote
remote
end

private

def components
Datadog.send(:components)
end

def remote
components.remote
end
end
end
end
end
5 changes: 3 additions & 2 deletions lib/datadog/core/remote/tie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ module Tie
)

def self.boot
return if Datadog::Core::Remote.active_remote.nil?
active_remote = Datadog.send(:components, allow_initialization: false)&.remote
return if active_remote.nil?

barrier = nil

t = Datadog::Core::Utils::Time.measure do
barrier = Datadog::Core::Remote.active_remote.barrier(:once)
barrier = active_remote.barrier(:once)
end

# steep does not permit the next line due to
Expand Down
7 changes: 4 additions & 3 deletions lib/datadog/core/remote/tie/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ def self.tag(boot, span)
return if boot.nil?
return if span.nil?

return if Datadog::Core::Remote.active_remote.nil?
active_remote = Datadog.send(:components, allow_initialization: false)&.remote
return if active_remote.nil?

# TODO: this is not thread-consistent
ready = Datadog::Core::Remote.active_remote.healthy
ready = active_remote.healthy
status = ready ? 'ready' : 'disconnected'

span.set_tag('_dd.rc.client_id', Datadog::Core::Remote.active_remote.client.id)
span.set_tag('_dd.rc.client_id', active_remote.client.id)
span.set_tag('_dd.rc.status', status)

if boot.barrier != :pass
Expand Down
7 changes: 0 additions & 7 deletions sig/datadog/core/remote.rbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module Datadog
module Core
module Remote
def self.active_remote: () -> Datadog::Core::Remote::Component

private

def self.components: () -> Datadog::Core::Configuration::Components

def self.remote: () -> Datadog::Core::Remote::Component
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
let(:remote_boot_timeout) { 1.0 }
let(:route) { '/success/' }

let(:component) { Datadog::Core::Remote.active_remote }
let(:component) { Datadog.send(:components).remote }
let(:worker) { component.instance_eval { @worker } }
let(:client) { double('Client') }
let(:transport_v7) { double('Transport') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
let(:remote_boot_timeout) { 1.0 }
let(:route) { '/success/' }

let(:component) { Datadog::Core::Remote.active_remote }
let(:component) { Datadog.send(:components).remote }
let(:worker) { component.instance_eval { @worker } }
let(:client) { double('Client') }
let(:transport_v7) { double('Transport') }
Expand Down
12 changes: 8 additions & 4 deletions spec/datadog/tracing/contrib/suite/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def build(*dynamic_configurations)
}.to_json
end

let(:active_remote) do
Datadog.send(:components).remote
end

context 'with dynamic configuration data' do
let(:dynamic_configuration) { new_dynamic_configuration(product, data) }
let(:data) { { 'lib_config' => lib_config } }
Expand All @@ -109,7 +113,7 @@ def build(*dynamic_configurations)
let(:tracing_header_tags) { [{ 'header' => 'test-header', 'tag_name' => '' }] }

it 'overrides the local values' do
Datadog::Core::Remote.active_remote.barrier(:once)
active_remote.barrier(:once)

expect(Datadog.configuration.tracing.sampling.default_rate).to be_nil
expect(Datadog.configuration.tracing.log_injection).to eq(true)
Expand All @@ -128,7 +132,7 @@ def build(*dynamic_configurations)
let(:empty_data) { { 'lib_config' => {} } }

it 'restore the local values' do
Datadog::Core::Remote.active_remote.barrier(:once)
active_remote.barrier(:once)

update_config

Expand Down Expand Up @@ -200,7 +204,7 @@ def build(*dynamic_configurations)

it 'changes default sampling rate and sampling decision' do
# Before
Datadog::Core::Remote.active_remote.barrier(:once)
active_remote.barrier(:once)
tracer.trace('test') {}

expect(trace.rule_sample_rate).to be_nil
Expand Down Expand Up @@ -236,7 +240,7 @@ def build(*dynamic_configurations)

it 'changes disables log injection' do
# Before
Datadog::Core::Remote.active_remote.barrier(:once)
active_remote.barrier(:once)
expect(Datadog.configuration.tracing.log_injection).to eq(true)

tracer.trace('test') { logger.error('test-log') }
Expand Down
Loading