Class: Datadog::Core::Telemetry::Component Private
- Inherits:
-
Object
- Object
- Datadog::Core::Telemetry::Component
- Includes:
- Logging, Utils::Forking
- Defined in:
- lib/datadog/core/telemetry/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.
Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecycle. Note: Telemetry does not spawn its worker thread in fork processes, thus no telemetry is sent in forked processes.
Instance Attribute Summary collapse
- #enabled ⇒ Object readonly private
- #logger ⇒ Object readonly private
- #transport ⇒ Object readonly private
- #worker ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#client_configuration_change!(changes) ⇒ Object
private
Report configuration changes caused by Remote Configuration.
-
#dec(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
private
Decremenets a count metric.
- #disable! ⇒ Object private
-
#distribution(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
private
Tracks distribution metric.
- #emit_closing! ⇒ Object private
-
#flush ⇒ Object
private
Wait for the worker to send out all events that have already been queued, up to 15 seconds.
-
#gauge(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
private
Tracks gauge metric.
-
#inc(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
private
Increments a count metric.
-
#initialize(settings:, agent_settings:, logger:, enabled:) ⇒ Component
constructor
private
A new instance of Component.
- #integrations_change! ⇒ Object private
- #log!(event) ⇒ Object private
-
#rate(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
private
Tracks rate metric.
- #shutdown! ⇒ Object private
- #start(initial_event_is_change = false) ⇒ Object private
Methods included from Logging
Methods included from Utils::Forking
#after_fork!, extended, #fork_pid, #forked?, included, #update_fork_pid!
Constructor Details
#initialize(settings:, agent_settings:, logger:, enabled:) ⇒ 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.
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/datadog/core/telemetry/component.rb', line 45 def initialize( # standard:disable Metrics/MethodLength settings:, agent_settings:, logger:, enabled: ) @enabled = enabled @log_collection_enabled = settings.telemetry.log_collection_enabled @logger = logger @metrics_manager = MetricsManager.new( enabled: @enabled && settings.telemetry.metrics_enabled, aggregation_interval: settings.telemetry.metrics_aggregation_interval_seconds, ) @stopped = false return unless @enabled @transport = if settings.telemetry.agentless_enabled agent_settings = Core::Configuration::AgentlessSettingsResolver.call( settings, host_prefix: 'instrumentation-telemetry-intake', url_override: settings.telemetry.agentless_url_override, url_override_source: 'c.telemetry.agentless_url_override', logger: logger, ) Telemetry::Transport::HTTP.agentless_telemetry( agent_settings: agent_settings, logger: logger, # api_key should have already validated to be # not nil by +build+ method above. api_key: settings.api_key, ) else Telemetry::Transport::HTTP.agent_telemetry( agent_settings: agent_settings, logger: logger, ) end @worker = Telemetry::Worker.new( enabled: @enabled, heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds, metrics_aggregation_interval_seconds: settings.telemetry.metrics_aggregation_interval_seconds, emitter: Emitter.new( @transport, logger: @logger, debug: settings.telemetry.debug, ), metrics_manager: @metrics_manager, dependency_collection: settings.telemetry.dependency_collection, logger: logger, shutdown_timeout: settings.telemetry.shutdown_timeout_seconds, ) end |
Instance Attribute Details
#enabled ⇒ 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.
22 23 24 |
# File 'lib/datadog/core/telemetry/component.rb', line 22 def enabled @enabled 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.
22 23 24 |
# File 'lib/datadog/core/telemetry/component.rb', line 22 def logger @logger 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.
22 23 24 |
# File 'lib/datadog/core/telemetry/component.rb', line 22 def transport @transport end |
#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.
22 23 24 |
# File 'lib/datadog/core/telemetry/component.rb', line 22 def worker @worker end |
Class Method Details
.build(settings, agent_settings, logger) ⇒ 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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/datadog/core/telemetry/component.rb', line 27 def self.build(settings, agent_settings, logger) enabled = settings.telemetry.enabled agentless_enabled = settings.telemetry.agentless_enabled if agentless_enabled && settings.api_key.nil? enabled = false logger.debug { 'Telemetry disabled. Agentless telemetry requires a DD_API_KEY variable to be set.' } end Telemetry::Component.new( settings: settings, agent_settings: agent_settings, enabled: enabled, logger: logger, ) end |
Instance Method Details
#client_configuration_change!(changes) ⇒ 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.
Report configuration changes caused by Remote Configuration.
158 159 160 161 162 |
# File 'lib/datadog/core/telemetry/component.rb', line 158 def client_configuration_change!(changes) return if !@enabled || forked? @worker.enqueue(Event::AppClientConfigurationChange.new(changes, 'remote_config')) end |
#dec(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.
Decremenets a count metric.
170 171 172 |
# File 'lib/datadog/core/telemetry/component.rb', line 170 def dec(namespace, metric_name, value, tags: {}, common: true) @metrics_manager.dec(namespace, metric_name, value, tags: , common: common) end |
#disable! ⇒ 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.
101 102 103 104 |
# File 'lib/datadog/core/telemetry/component.rb', line 101 def disable! @enabled = false @worker&.enabled = false end |
#distribution(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.
Tracks distribution metric.
185 186 187 |
# File 'lib/datadog/core/telemetry/component.rb', line 185 def distribution(namespace, metric_name, value, tags: {}, common: true) @metrics_manager.distribution(namespace, metric_name, value, tags: , common: common) end |
#emit_closing! ⇒ 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.
128 129 130 131 132 |
# File 'lib/datadog/core/telemetry/component.rb', line 128 def emit_closing! return if !@enabled || forked? @worker.enqueue(Event::AppClosing.new) end |
#flush ⇒ 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.
Wait for the worker to send out all events that have already been queued, up to 15 seconds. Returns whether all events have been flushed.
151 152 153 154 155 |
# File 'lib/datadog/core/telemetry/component.rb', line 151 def flush return if !@enabled || forked? @worker.flush end |
#gauge(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.
Tracks gauge metric.
175 176 177 |
# File 'lib/datadog/core/telemetry/component.rb', line 175 def gauge(namespace, metric_name, value, tags: {}, common: true) @metrics_manager.gauge(namespace, metric_name, value, tags: , common: common) end |
#inc(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.
Increments a count metric.
165 166 167 |
# File 'lib/datadog/core/telemetry/component.rb', line 165 def inc(namespace, metric_name, value, tags: {}, common: true) @metrics_manager.inc(namespace, metric_name, value, tags: , common: common) end |
#integrations_change! ⇒ 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.
134 135 136 137 138 |
# File 'lib/datadog/core/telemetry/component.rb', line 134 def integrations_change! return if !@enabled || forked? @worker.enqueue(Event::AppIntegrationsChange.new) end |
#log!(event) ⇒ 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.
140 141 142 143 144 |
# File 'lib/datadog/core/telemetry/component.rb', line 140 def log!(event) return if !@enabled || forked? || !@log_collection_enabled @worker.enqueue(event) end |
#rate(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.
Tracks rate metric.
180 181 182 |
# File 'lib/datadog/core/telemetry/component.rb', line 180 def rate(namespace, metric_name, value, tags: {}, common: true) @metrics_manager.rate(namespace, metric_name, value, tags: , common: common) end |
#shutdown! ⇒ 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.
118 119 120 121 122 123 124 125 126 |
# File 'lib/datadog/core/telemetry/component.rb', line 118 def shutdown! return if @stopped if defined?(@worker) @worker&.stop(true) end @stopped = true end |
#start(initial_event_is_change = false) ⇒ 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.
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/datadog/core/telemetry/component.rb', line 106 def start(initial_event_is_change = false) return if !@enabled initial_event = if initial_event_is_change Event::SynthAppClientConfigurationChange.new else Event::AppStarted.new end @worker.start(initial_event) end |