Class: Datadog::Core::Crashtracking::Component
- Inherits:
-
Object
- Object
- Datadog::Core::Crashtracking::Component
- Defined in:
- lib/datadog/core/crashtracking/component.rb,
ext/libdatadog_api/crashtracker.c
Overview
Used to report Ruby VM crashes.
NOTE: The crashtracker native state is a singleton; so even if you create multiple instances of ‘Crashtracking::Component` and start them, it only works as “last writer wins”. Same for stop – there’s only one state, so calling stop on it will stop the crash tracker, regardless of which instance started it.
Methods prefixed with native are implemented in ‘crashtracker.c`
Constant Summary collapse
- LIBDATADOG_API_FAILURE =
begin require "libdatadog_api.#{RUBY_VERSION[/\d+.\d+/]}_#{RUBY_PLATFORM}" nil rescue LoadError => e e. end
- ONLY_ONCE =
Core::Utils::OnlyOnce.new
Class Method Summary collapse
- ._native_start_or_update_on_fork ⇒ Object
- ._native_stop ⇒ Object
- .build(settings, agent_settings, logger:) ⇒ Object
Instance Method Summary collapse
-
#initialize(tags:, agent_base_url:, ld_library_path:, path_to_crashtracking_receiver_binary:, logger:) ⇒ Component
constructor
A new instance of Component.
- #start ⇒ Object
- #stop ⇒ Object
- #update_on_fork(settings: Datadog.configuration) ⇒ Object
Constructor Details
#initialize(tags:, agent_base_url:, ld_library_path:, path_to_crashtracking_receiver_binary:, logger:) ⇒ Component
Returns a new instance of Component.
58 59 60 61 62 63 64 |
# File 'lib/datadog/core/crashtracking/component.rb', line 58 def initialize(tags:, agent_base_url:, ld_library_path:, path_to_crashtracking_receiver_binary:, logger:) @tags = @agent_base_url = agent_base_url @ld_library_path = ld_library_path @path_to_crashtracking_receiver_binary = path_to_crashtracking_receiver_binary @logger = logger end |
Class Method Details
._native_start_or_update_on_fork ⇒ Object
6 |
# File 'ext/libdatadog_api/crashtracker.c', line 6
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self);
|
._native_stop ⇒ Object
7 |
# File 'ext/libdatadog_api/crashtracker.c', line 7 static VALUE _native_stop(DDTRACE_UNUSED VALUE _self); |
.build(settings, agent_settings, logger:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/datadog/core/crashtracking/component.rb', line 32 def self.build(settings, agent_settings, logger:) = TagBuilder.call(settings) agent_base_url = AgentBaseUrl.resolve(agent_settings) logger.warn('Missing agent base URL; cannot enable crash tracking') unless agent_base_url ld_library_path = ::Libdatadog.ld_library_path logger.warn('Missing ld_library_path; cannot enable crash tracking') unless ld_library_path path_to_crashtracking_receiver_binary = ::Libdatadog.path_to_crashtracking_receiver_binary unless path_to_crashtracking_receiver_binary logger.warn('Missing path_to_crashtracking_receiver_binary; cannot enable crash tracking') end return unless agent_base_url return unless ld_library_path return unless path_to_crashtracking_receiver_binary new( tags: , agent_base_url: agent_base_url, ld_library_path: ld_library_path, path_to_crashtracking_receiver_binary: path_to_crashtracking_receiver_binary, logger: logger ).tap(&:start) end |
Instance Method Details
#start ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/datadog/core/crashtracking/component.rb', line 66 def start Utils::AtForkMonkeyPatch.apply! start_or_update_on_fork(action: :start, tags: ) ONLY_ONCE.run do Utils::AtForkMonkeyPatch.at_fork(:child) do # Must NOT reference `self` here, as only the first instance will # be captured by the ONLY_ONCE and we want to pick the latest active one # (which may have different tags or agent config) Datadog.send(:components).crashtracker&.update_on_fork end end end |
#stop ⇒ Object
87 88 89 90 91 92 |
# File 'lib/datadog/core/crashtracking/component.rb', line 87 def stop self.class._native_stop logger.debug('Crash tracking stopped successfully') rescue => e logger.error("Failed to stop crash tracking: #{e.}") end |
#update_on_fork(settings: Datadog.configuration) ⇒ Object
81 82 83 84 85 |
# File 'lib/datadog/core/crashtracking/component.rb', line 81 def update_on_fork(settings: Datadog.configuration) # Here we pick up the latest settings, so that we pick up any tags that change after forking # such as the pid or runtime-id start_or_update_on_fork(action: :update_on_fork, tags: TagBuilder.call(settings)) end |