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
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.
48 49 50 51 52 53 54 |
# File 'lib/datadog/core/crashtracking/component.rb', line 48 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
7 |
# File 'ext/libdatadog_api/crashtracker.c', line 7
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self);
|
._native_stop ⇒ Object
8 |
# File 'ext/libdatadog_api/crashtracker.c', line 8 static VALUE _native_stop(DDTRACE_UNUSED VALUE _self); |
.build(settings, agent_settings, logger:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datadog/core/crashtracking/component.rb', line 23 def self.build(settings, agent_settings, logger:) = TagBuilder.call(settings) agent_base_url = agent_settings.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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/datadog/core/crashtracking/component.rb', line 56 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, allow_initialization: false)&.crashtracker&.update_on_fork end end end |
#stop ⇒ Object
77 78 79 80 81 82 |
# File 'lib/datadog/core/crashtracking/component.rb', line 77 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
71 72 73 74 75 |
# File 'lib/datadog/core/crashtracking/component.rb', line 71 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 |