Module: Datadog::Kit::EnableCoreDumps
- Defined in:
- lib/datadog/kit/enable_core_dumps.rb
Overview
This helper is used to enable core dumps for the current Ruby app. This is useful when debugging native-level crashes.
It can be enabled simply by adding ‘require ’datadog/kit/enable_core_dumps’‘ to start of the app.
Class Method Summary collapse
Class Method Details
.call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/datadog/kit/enable_core_dumps.rb', line 10 def self.call current_size, maximum_size = Process.getrlimit(:CORE) core_pattern = begin File.read('/proc/sys/kernel/core_pattern').strip rescue '(Could not open /proc/sys/kernel/core_pattern)' end enabled_status = "Maximum size: #{maximum_size} Output pattern: '#{core_pattern}'" if maximum_size <= 0 Kernel.warn("[ddtrace] Could not enable core dumps on crash, maximum size is #{maximum_size} (disabled).") return elsif maximum_size == current_size Kernel.warn("[ddtrace] Core dumps already enabled, nothing to do. #{enabled_status}") return end begin Process.setrlimit(:CORE, maximum_size) rescue => e Kernel.warn( "[ddtrace] Failed to enable core dumps. Cause: #{e.class.name} #{e.} " \ "Location: #{Array(e.backtrace).first}" ) return end if current_size == 0 Kernel.warn("[ddtrace] Enabled core dumps. #{enabled_status}") else Kernel.warn("[ddtrace] Raised core dump limit. Old size: #{current_size} #{enabled_status}") end end |