Module: Datadog::DI::ProbeFileLoader Private

Defined in:
lib/datadog/di/probe_file_loader.rb,
lib/datadog/di/probe_file_loader/railtie.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Railtie

Class Method Summary collapse

Class Method Details

.load_nowObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method can be called more than once, to attempt to load DI components that depend on third-party libraries after additional dependencies are loaded (or potentially loaded).



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/datadog/di/probe_file_loader.rb', line 20

module_function def load_now
  should_propagate = false

  probe_file_path = ENV['DD_DYNAMIC_INSTRUMENTATION_PROBE_FILE']
  if probe_file_path.nil? || probe_file_path.empty?
    return
  end

  # We want to initialize the component tree here if it was not already
  # initialized.
  component = Datadog::DI.component
  return unless component

  begin
    probe_specs = File.open(probe_file_path) do |f|
      # The probe file should contain an array, JSON.parse does not work
      JSON.load(f) # standard:disable Security/JSONLoad
    end

    probe_specs.each do |probe_spec|
      probe = component.parse_probe_spec_and_notify(probe_spec)
      component.logger.debug { "di: received #{probe.type} probe at #{probe.location} (#{probe.id}) via probe file: #{probe_file_path}" }

      begin
        component.probe_manager.add_probe(probe)
      rescue DI::Error::DITargetNotInRegistry => exc
        component.telemetry&.report(exc, description: "Line probe is targeting a loaded file that is not in code tracker")

        payload = component.probe_notification_builder.build_errored(probe, exc)
        component.probe_notifier_worker.add_status(payload)
      rescue => exc
        raise if component.settings.dynamic_instrumentation.internal.propagate_all_exceptions

        component.logger.debug { "di: unhandled exception adding #{probe.type} probe at #{probe.location} (#{probe.id}) in DI probe file loader: #{exc.class}: #{exc}" }
        component.telemetry&.report(exc, description: "Unhandled exception adding probe in DI probe file loader")

        # TODO test this path
        payload = component.probe_notification_builder.build_errored(probe, exc)
        component.probe_notifier_worker.add_status(payload)
      end
    end
  rescue => exc
    if component.settings.dynamic_instrumentation.internal.propagate_all_exceptions
      should_propagate = true
      raise
    end

    component.logger.debug { "di: unhandled exception handling a probe in DI probe file loader: #{exc.class}: #{exc}" }
    component.telemetry&.report(exc, description: "Unhandled exception handling probe in DI probe file loader")
  end
rescue
  # We should generally never get here, but if component tree
  # initialization fails for some unexpected reason, don't nuke
  # the customer application.
  #
  # For the same reason, we do not check
  # component.settings.dynamic_instrumentation.internal.propagate_all_exceptions
  # here again, but rely on the local variable storing that value.
  raise if should_propagate
end

.load_now_or_laterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
# File 'lib/datadog/di/probe_file_loader.rb', line 8

module_function def load_now_or_later
  if Datadog::Core::Contrib::Rails::Utils.railtie_supported?
    Datadog.logger.debug('di: loading probe_file_loader/railtie')
    require_relative 'probe_file_loader/railtie'
  else
    load_now
  end
end