Class: Datadog::Core::Configuration::Components
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::Components
- Extended by:
- Tracing::Component
- Includes:
- Tracing::Component::InstanceMethods
- Defined in:
- lib/datadog/core/configuration/components.rb
Overview
Global components for the trace library.
Constant Summary
Constants included from Tracing::Component
Tracing::Component::WRITER_RECORD_ENVIRONMENT_INFORMATION_CALLBACK, Tracing::Component::WRITER_RECORD_ENVIRONMENT_INFORMATION_ONLY_ONCE
Instance Attribute Summary collapse
-
#appsec ⇒ Object
readonly
Returns the value of attribute appsec.
-
#crashtracker ⇒ Object
readonly
Returns the value of attribute crashtracker.
-
#dynamic_instrumentation ⇒ Object
readonly
Returns the value of attribute dynamic_instrumentation.
-
#health_metrics ⇒ Object
readonly
Returns the value of attribute health_metrics.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#profiler ⇒ Object
readonly
Returns the value of attribute profiler.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#runtime_metrics ⇒ Object
readonly
Returns the value of attribute runtime_metrics.
-
#telemetry ⇒ Object
readonly
Returns the value of attribute telemetry.
-
#tracer ⇒ Object
readonly
Returns the value of attribute tracer.
Class Method Summary collapse
- .build_crashtracker(settings, agent_settings, logger:) ⇒ Object
- .build_health_metrics(settings) ⇒ Object
- .build_logger(settings) ⇒ Object
- .build_runtime_metrics(settings) ⇒ Object
- .build_runtime_metrics_worker(settings) ⇒ Object
- .build_telemetry(settings, agent_settings, logger) ⇒ Object
Instance Method Summary collapse
-
#initialize(settings) ⇒ Components
constructor
A new instance of Components.
-
#shutdown!(replacement = nil) ⇒ Object
Shuts down all the components in use.
-
#startup!(settings, old_state: nil) ⇒ Object
Starts up components.
Methods included from Tracing::Component
build_sampler, build_span_sampler, build_trace_flush, build_tracer, build_writer, configure_tracing, subscribe_to_writer_events!, writer_update_priority_sampler_rates_callback
Methods included from Tracing::Component::InstanceMethods
Constructor Details
#initialize(settings) ⇒ Components
Returns a new instance of Components.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/datadog/core/configuration/components.rb', line 90 def initialize(settings) @logger = self.class.build_logger(settings) @environment_logger_extra = {} # This agent_settings is intended for use within Core. If you require # agent_settings within a product outside of core you should extend # the Core resolver from within your product/component's namespace. agent_settings = AgentSettingsResolver.call(settings, logger: @logger) @telemetry = self.class.build_telemetry(settings, agent_settings, @logger) @remote = Remote::Component.build(settings, agent_settings, telemetry: telemetry) @tracer = self.class.build_tracer(settings, agent_settings, logger: @logger) @crashtracker = self.class.build_crashtracker(settings, agent_settings, logger: @logger) @profiler, profiler_logger_extra = Datadog::Profiling::Component.build_profiler_component( settings: settings, agent_settings: agent_settings, optional_tracer: @tracer ) @environment_logger_extra.merge!(profiler_logger_extra) if profiler_logger_extra @runtime_metrics = self.class.build_runtime_metrics_worker(settings) @health_metrics = self.class.build_health_metrics(settings) @appsec = Datadog::AppSec::Component.build_appsec_component(settings, telemetry: telemetry) @dynamic_instrumentation = Datadog::DI::Component.build(settings, agent_settings, telemetry: telemetry) self.class.configure_tracing(settings) end |
Instance Attribute Details
#appsec ⇒ Object (readonly)
Returns the value of attribute appsec.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def appsec @appsec end |
#crashtracker ⇒ Object (readonly)
Returns the value of attribute crashtracker.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def crashtracker @crashtracker end |
#dynamic_instrumentation ⇒ Object (readonly)
Returns the value of attribute dynamic_instrumentation.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def dynamic_instrumentation @dynamic_instrumentation end |
#health_metrics ⇒ Object (readonly)
Returns the value of attribute health_metrics.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def health_metrics @health_metrics end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def logger @logger end |
#profiler ⇒ Object (readonly)
Returns the value of attribute profiler.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def profiler @profiler end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def remote @remote end |
#runtime_metrics ⇒ Object (readonly)
Returns the value of attribute runtime_metrics.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def runtime_metrics @runtime_metrics end |
#telemetry ⇒ Object (readonly)
Returns the value of attribute telemetry.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def telemetry @telemetry end |
#tracer ⇒ Object (readonly)
Returns the value of attribute tracer.
78 79 80 |
# File 'lib/datadog/core/configuration/components.rb', line 78 def tracer @tracer end |
Class Method Details
.build_crashtracker(settings, agent_settings, logger:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/datadog/core/configuration/components.rb', line 64 def build_crashtracker(settings, agent_settings, logger:) return unless settings.crashtracking.enabled if (libdatadog_api_failure = Datadog::Core::Crashtracking::Component::LIBDATADOG_API_FAILURE) logger.debug("Cannot enable crashtracking: #{libdatadog_api_failure}") return end Datadog::Core::Crashtracking::Component.build(settings, agent_settings, logger: logger) end |
.build_health_metrics(settings) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/datadog/core/configuration/components.rb', line 27 def build_health_metrics(settings) settings = settings.health_metrics = { enabled: settings.enabled } [:statsd] = settings.statsd unless settings.statsd.nil? Core::Diagnostics::Health::Metrics.new(**) end |
.build_logger(settings) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/datadog/core/configuration/components.rb', line 35 def build_logger(settings) logger = settings.logger.instance || Core::Logger.new($stdout) logger.level = settings.diagnostics.debug ? ::Logger::DEBUG : settings.logger.level logger end |
.build_runtime_metrics(settings) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/datadog/core/configuration/components.rb', line 42 def build_runtime_metrics(settings) = { enabled: settings.runtime_metrics.enabled } [:statsd] = settings.runtime_metrics.statsd unless settings.runtime_metrics.statsd.nil? [:services] = [settings.service] unless settings.service.nil? Core::Runtime::Metrics.new(**) end |
.build_runtime_metrics_worker(settings) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/datadog/core/configuration/components.rb', line 50 def build_runtime_metrics_worker(settings) # NOTE: Should we just ignore building the worker if its not enabled? = settings.runtime_metrics.opts.merge( enabled: settings.runtime_metrics.enabled, metrics: build_runtime_metrics(settings) ) Core::Workers::RuntimeMetrics.new() end |
Instance Method Details
#shutdown!(replacement = nil) ⇒ Object
Shuts down all the components in use. If it has another instance to compare to, it will compare and avoid tearing down parts still in use.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/datadog/core/configuration/components.rb', line 148 def shutdown!(replacement = nil) # Shutdown remote configuration remote.shutdown! if remote # Shutdown DI after remote, since remote config triggers DI operations. dynamic_instrumentation&.shutdown! # Decommission AppSec appsec.shutdown! if appsec # Shutdown the old tracer, unless it's still being used. # (e.g. a custom tracer instance passed in.) tracer.shutdown! unless replacement && tracer == replacement.tracer # Shutdown old profiler profiler.shutdown! unless profiler.nil? # Shutdown workers runtime_metrics.stop(true, close_metrics: false) # Shutdown the old metrics, unless they are still being used. # (e.g. custom Statsd instances.) # # TODO: This violates the encapsulation created by Runtime::Metrics and # Health::Metrics, by directly manipulating `statsd` and changing # it's lifecycle management. # If we need to directly have ownership of `statsd` lifecycle, we should # have direct ownership of it. old_statsd = [ runtime_metrics.metrics.statsd, health_metrics.statsd ].compact.uniq new_statsd = if replacement [ replacement.runtime_metrics.metrics.statsd, replacement.health_metrics.statsd ].compact.uniq else [] end unused_statsd = (old_statsd - (old_statsd & new_statsd)) unused_statsd.each(&:close) # enqueue closing event before stopping telemetry so it will be send out on shutdown telemetry.emit_closing! unless replacement telemetry.stop! end |
#startup!(settings, old_state: nil) ⇒ Object
Starts up components
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/datadog/core/configuration/components.rb', line 121 def startup!(settings, old_state: nil) if settings.profiling.enabled if profiler profiler.start else # Display a warning for users who expected profiling to be enabled unsupported_reason = Profiling.unsupported_reason logger.warn("Profiling was requested but is not supported, profiling disabled: #{unsupported_reason}") end end if settings.remote.enabled && old_state&.[](:remote_started) # The library was reconfigured and previously it already started # the remote component (i.e., it received at least one request # through the installed Rack middleware which started the remote). # If the new configuration also has remote enabled, start the # new remote right away. # remote should always be not nil here but steep doesn't know this. remote&.start end Core::Diagnostics::EnvironmentLogger.collect_and_log!(@environment_logger_extra) end |