Module: OpenTelemetry::SDK::Metrics::ForkHooks

Defined in:
lib/opentelemetry/sdk/metrics/fork_hooks.rb

Overview

ForkHooks implements methods to run callbacks before and after forking a Process by overriding Process::_fork This is used to ensure that the PeriodicMetricReader is restarted after forking

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.after_forkObject



20
21
22
23
24
# File 'lib/opentelemetry/sdk/metrics/fork_hooks.rb', line 20

def self.after_fork
  ::OpenTelemetry.meter_provider.metric_readers.each do |reader|
    reader.after_fork if reader.respond_to?(:after_fork)
  end
end

.attach!Object



13
14
15
16
17
18
# File 'lib/opentelemetry/sdk/metrics/fork_hooks.rb', line 13

def self.attach!
  return if @fork_hooks_attached

  Process.singleton_class.prepend(ForkHooks)
  @fork_hooks_attached = true
end

Instance Method Details

#_forkObject



26
27
28
29
30
31
# File 'lib/opentelemetry/sdk/metrics/fork_hooks.rb', line 26

def _fork
  parent_pid = Process.pid
  super.tap do
    ForkHooks.after_fork unless Process.pid == parent_pid
  end
end