module Datadog::Utils::Forking

Helper methods for managing forking behavior

Public Class Methods

extended(base) click to toggle source
# File lib/ddtrace/utils/forking.rb, line 10
def self.extended(base)
  # Explicitly update PID here because there's a case where
  # the code path that lazily updates the PID may not be exercised
  # until after a fork occurs, thus causing the event to be missed.
  # By eagerly setting this, we avoid this scenario.
  base.update_fork_pid!
end
included(base) click to toggle source
# File lib/ddtrace/utils/forking.rb, line 6
def self.included(base)
  base.prepend(ClassExtensions) if base.is_a?(Class)
end

Public Instance Methods

after_fork!() { || ... } click to toggle source
# File lib/ddtrace/utils/forking.rb, line 18
def after_fork!
  if forked?
    yield
    update_fork_pid!
    true
  else
    false
  end
end
fork_pid() click to toggle source
# File lib/ddtrace/utils/forking.rb, line 36
def fork_pid
  @fork_pid ||= Process.pid
end
forked?() click to toggle source
# File lib/ddtrace/utils/forking.rb, line 28
def forked?
  Process.pid != fork_pid
end
update_fork_pid!() click to toggle source
# File lib/ddtrace/utils/forking.rb, line 32
def update_fork_pid!
  @fork_pid = Process.pid
end