Class: Datadog::DI::Component Private
- Inherits:
-
Object
- Object
- Datadog::DI::Component
- Defined in:
- lib/datadog/di/component.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Component for dynamic instrumentation.
Only one instance of the Component should ever be active; if configuration is changed, the old distance should be shut down prior to the new instance being created.
The Component instance stores all state related to DI, for example which probes have been retrieved via remote config, intalled tracepoints and so on. Component will clean up all resources and installed tracepoints upon shutdown.
Instance Attribute Summary collapse
- #agent_settings ⇒ Object readonly private
- #instrumenter ⇒ Object readonly private
- #logger ⇒ Object readonly private
- #probe_manager ⇒ Object readonly private
- #probe_notification_builder ⇒ Object readonly private
- #probe_notifier_worker ⇒ Object readonly private
- #redactor ⇒ Object readonly private
- #serializer ⇒ Object readonly private
- #settings ⇒ Object readonly private
- #telemetry ⇒ Object readonly private
- #transport ⇒ Object readonly private
Class Method Summary collapse
- .build(settings, agent_settings, logger, telemetry: nil) ⇒ Object private
- .build!(settings, agent_settings, logger, telemetry: nil) ⇒ Object private
-
.environment_supported?(settings, logger) ⇒ Boolean
private
Checks whether the runtime environment is supported by dynamic instrumentation.
Instance Method Summary collapse
-
#initialize(settings, agent_settings, logger, code_tracker: nil, telemetry: nil) ⇒ Component
constructor
private
A new instance of Component.
-
#shutdown!(replacement = nil) ⇒ Object
private
Shuts down dynamic instrumentation.
Constructor Details
#initialize(settings, agent_settings, logger, code_tracker: nil, telemetry: nil) ⇒ Component
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.
Returns a new instance of Component.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/datadog/di/component.rb', line 74 def initialize(settings, agent_settings, logger, code_tracker: nil, telemetry: nil) @settings = settings @agent_settings = agent_settings @logger = logger @telemetry = telemetry @redactor = Redactor.new(settings) @serializer = Serializer.new(settings, redactor, telemetry: telemetry) @instrumenter = Instrumenter.new(settings, serializer, logger, code_tracker: code_tracker, telemetry: telemetry) @transport = Transport.new(agent_settings) @probe_notifier_worker = ProbeNotifierWorker.new(settings, transport, logger, telemetry: telemetry) @probe_notification_builder = ProbeNotificationBuilder.new(settings, serializer) @probe_manager = ProbeManager.new(settings, instrumenter, probe_notification_builder, probe_notifier_worker, logger, telemetry: telemetry) probe_notifier_worker.start end |
Instance Attribute Details
#agent_settings ⇒ Object (readonly)
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.
90 91 92 |
# File 'lib/datadog/di/component.rb', line 90 def agent_settings @agent_settings end |
#instrumenter ⇒ Object (readonly)
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.
93 94 95 |
# File 'lib/datadog/di/component.rb', line 93 def instrumenter @instrumenter end |
#logger ⇒ Object (readonly)
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.
91 92 93 |
# File 'lib/datadog/di/component.rb', line 91 def logger @logger end |
#probe_manager ⇒ Object (readonly)
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.
97 98 99 |
# File 'lib/datadog/di/component.rb', line 97 def probe_manager @probe_manager end |
#probe_notification_builder ⇒ Object (readonly)
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.
96 97 98 |
# File 'lib/datadog/di/component.rb', line 96 def probe_notification_builder @probe_notification_builder end |
#probe_notifier_worker ⇒ Object (readonly)
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.
95 96 97 |
# File 'lib/datadog/di/component.rb', line 95 def probe_notifier_worker @probe_notifier_worker end |
#redactor ⇒ Object (readonly)
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.
98 99 100 |
# File 'lib/datadog/di/component.rb', line 98 def redactor @redactor end |
#serializer ⇒ Object (readonly)
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.
99 100 101 |
# File 'lib/datadog/di/component.rb', line 99 def serializer @serializer end |
#settings ⇒ Object (readonly)
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.
89 90 91 |
# File 'lib/datadog/di/component.rb', line 89 def settings @settings end |
#telemetry ⇒ Object (readonly)
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.
92 93 94 |
# File 'lib/datadog/di/component.rb', line 92 def telemetry @telemetry end |
#transport ⇒ Object (readonly)
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.
94 95 96 |
# File 'lib/datadog/di/component.rb', line 94 def transport @transport end |
Class Method Details
.build(settings, agent_settings, logger, telemetry: nil) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/datadog/di/component.rb', line 19 def build(settings, agent_settings, logger, telemetry: nil) return unless settings.respond_to?(:dynamic_instrumentation) && settings.dynamic_instrumentation.enabled unless settings.respond_to?(:remote) && settings.remote.enabled logger.warn("di: dynamic instrumentation could not be enabled because Remote Configuration Management is not available. To enable Remote Configuration, see https://docs.datadoghq.com/agent/remote_config") return end return unless environment_supported?(settings, logger) new(settings, agent_settings, logger, code_tracker: DI.code_tracker, telemetry: telemetry).tap do |component| DI.add_current_component(component) end end |
.build!(settings, agent_settings, logger, telemetry: nil) ⇒ Object
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datadog/di/component.rb', line 34 def build!(settings, agent_settings, logger, telemetry: nil) unless settings.respond_to?(:dynamic_instrumentation) && settings.dynamic_instrumentation.enabled raise "Requested DI component but DI is not enabled in settings" end unless settings.respond_to?(:remote) && settings.remote.enabled raise "Requested DI component but remote config is not enabled in settings" end unless environment_supported?(settings, logger) raise "DI does not support the environment (development or Ruby version too low or not MRI)" end new(settings, agent_settings, logger, code_tracker: DI.code_tracker, telemetry: telemetry) end |
.environment_supported?(settings, logger) ⇒ Boolean
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.
Checks whether the runtime environment is supported by dynamic instrumentation. Currently we only require that, if Rails is used, that Rails environment is not development because DI does not currently support code unloading and reloading.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/datadog/di/component.rb', line 54 def environment_supported?(settings, logger) # TODO add tests? unless settings.dynamic_instrumentation.internal.development if Datadog::Core::Environment::Execution.development? logger.warn("di: development environment detected; not enabling dynamic instrumentation") return false end end if RUBY_ENGINE != 'ruby' logger.warn("di: cannot enable dynamic instrumentation: MRI is required, but running on #{RUBY_ENGINE}") return false end if RUBY_VERSION < '2.6' logger.warn("di: cannot enable dynamic instrumentation: Ruby 2.6+ is required, but running on #{RUBY_VERSION}") return false end true end |
Instance Method Details
#shutdown!(replacement = nil) ⇒ Object
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.
Shuts down dynamic instrumentation.
Removes all code hooks and stops background threads.
Does not clear out the code tracker, because it’s only populated by code when code is compiled and therefore, if the code tracker was replaced by a new instance, the new instance of it wouldn’t have any of the already loaded code tracked.
109 110 111 112 113 114 115 |
# File 'lib/datadog/di/component.rb', line 109 def shutdown!(replacement = nil) DI.remove_current_component(self) probe_manager.clear_hooks probe_manager.close probe_notifier_worker.stop end |