Sha256: 1167d1e87de17539e2ef9cbd1bb9b95569de754135673df1df8aba25d3393daa

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_relative "../../core/utils/only_once"
require_relative "../../core/utils/at_fork_monkey_patch"

module Datadog
  module Profiling
    module Tasks
      # Takes care of restarting the profiler when the process forks
      class Setup
        ACTIVATE_EXTENSIONS_ONLY_ONCE = Core::Utils::OnlyOnce.new

        def run
          ACTIVATE_EXTENSIONS_ONLY_ONCE.run do
            Datadog::Core::Utils::AtForkMonkeyPatch.apply!
            setup_at_fork_hooks
          rescue StandardError, ScriptError => e
            Datadog.logger.warn do
              "Profiler extensions unavailable. Cause: #{e.class.name} #{e.message} " \
              "Location: #{Array(e.backtrace).first}"
            end
          end
        end

        private

        def setup_at_fork_hooks
          Datadog::Core::Utils::AtForkMonkeyPatch.at_fork(:child) do
            # Restart profiler, if enabled
            Profiling.start_if_enabled
          rescue => e
            Datadog.logger.warn do
              "Error during post-fork hooks. Cause: #{e.class.name} #{e.message} " \
              "Location: #{Array(e.backtrace).first}"
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
datadog-2.9.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.8.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.7.1 lib/datadog/profiling/tasks/setup.rb
datadog-2.7.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.6.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.5.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.4.0 lib/datadog/profiling/tasks/setup.rb
datadog-2.3.0 lib/datadog/profiling/tasks/setup.rb