Skip to content

Commit

Permalink
Merge branch 'master' into tonycthsu/crashtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Aug 8, 2024
2 parents 4fa20e6 + 850462b commit 2d70215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/datadog/core/utils/at_fork_monkey_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.apply!
].each { |target| target.prepend(KernelMonkeyPatch) }
end

::Process.singleton_class.prepend(ProcessDaemonMonkeyPatch)
::Process.singleton_class.prepend(ProcessMonkeyPatch)

true
end
Expand Down Expand Up @@ -65,15 +65,15 @@ def datadog_at_fork_blocks
end

# Adds `datadog_at_fork` behavior; see parent module for details.
module ProcessDaemonMonkeyPatch
module ProcessMonkeyPatch
# Hook provided by Ruby 3.1+ for observability libraries that want to know about fork, see
# https://github.com/ruby/ruby/pull/5017 and https://bugs.ruby-lang.org/issues/17795
def _fork
datadog_at_fork_blocks = Datadog::Core::Utils::AtForkMonkeyPatch::KernelMonkeyPatch.datadog_at_fork_blocks

pid = super

datadog_at_fork_blocks[:child].each(&:call) if datadog_at_fork_blocks.key?(:child) && pid == 0
datadog_at_fork_blocks[:child].each(&:call) if pid == 0 && datadog_at_fork_blocks.key?(:child)

pid
end
Expand All @@ -94,7 +94,7 @@ def daemon(*args)
# NOTE: You probably want to wrap any calls to datadog_at_fork with a OnlyOnce so as to not re-register
# the same block/behavior more than once.
def datadog_at_fork(stage, &block)
ProcessDaemonMonkeyPatch.datadog_at_fork(stage, &block)
ProcessMonkeyPatch.datadog_at_fork(stage, &block)
end

# Also allow calling without going through Process for tests
Expand Down
12 changes: 6 additions & 6 deletions spec/datadog/core/utils/at_fork_monkey_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

context 'when forking is supported' do
before do
if ::Process.singleton_class.ancestors.include?(Datadog::Core::Utils::AtForkMonkeyPatch::ProcessDaemonMonkeyPatch)
if ::Process.singleton_class.ancestors.include?(Datadog::Core::Utils::AtForkMonkeyPatch::ProcessMonkeyPatch)
skip 'Monkey patch already applied (unclean state)'
end
end
Expand All @@ -23,7 +23,7 @@
apply!

expect(::Process.ancestors).to include(described_class::KernelMonkeyPatch)
expect(::Process.ancestors).to include(described_class::ProcessDaemonMonkeyPatch)
expect(::Process.ancestors).to include(described_class::ProcessMonkeyPatch)
expect(::Kernel.ancestors).to include(described_class::KernelMonkeyPatch)
expect(toplevel_receiver.class.ancestors).to include(described_class::KernelMonkeyPatch)

Expand All @@ -42,7 +42,7 @@
expect_in_fork do
apply!

expect(::Process.ancestors).to include(described_class::ProcessDaemonMonkeyPatch)
expect(::Process.ancestors).to include(described_class::ProcessMonkeyPatch)
expect(::Process.method(:daemon).source_location.first).to match(/.*at_fork_monkey_patch.rb/)
expect(::Process.method(:_fork).source_location.first).to match(/.*at_fork_monkey_patch.rb/)
end
Expand Down Expand Up @@ -95,7 +95,7 @@ def fork(&block)
let(:child) { double('child') }

before do
Datadog::Core::Utils::AtForkMonkeyPatch::ProcessDaemonMonkeyPatch.datadog_at_fork(:child) { child.call }
Datadog::Core::Utils::AtForkMonkeyPatch::ProcessMonkeyPatch.datadog_at_fork(:child) { child.call }
end

after do
Expand Down Expand Up @@ -172,7 +172,7 @@ def fork(&block)
let(:block) { proc { callback.call } }

subject(:datadog_at_fork) do
Datadog::Core::Utils::AtForkMonkeyPatch::ProcessDaemonMonkeyPatch.datadog_at_fork(:child, &block)
Datadog::Core::Utils::AtForkMonkeyPatch::ProcessMonkeyPatch.datadog_at_fork(:child, &block)
end

it 'adds a child callback' do
Expand Down Expand Up @@ -209,7 +209,7 @@ def fork(&block)
end
end

describe Datadog::Core::Utils::AtForkMonkeyPatch::ProcessDaemonMonkeyPatch do
describe Datadog::Core::Utils::AtForkMonkeyPatch::ProcessMonkeyPatch do
let(:_fork_result) { nil }
let(:process_module) do
result = _fork_result
Expand Down

0 comments on commit 2d70215

Please sign in to comment.