Skip to content

Commit

Permalink
Merge pull request #3551 from DataDog/telemetry-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Apr 3, 2024
2 parents 9da8576 + 5f59ba3 commit 65eabdb
Show file tree
Hide file tree
Showing 70 changed files with 809 additions and 2,995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def detailed_check
profiler_threads: Thread.list.map(&:name).select { |it| it && it.include?('Profiling') },
telemetry_enabled: Datadog.configuration.telemetry.enabled,
telemetry_client_enabled: Datadog.send(:components).telemetry.enabled,
telemetry_worker_enabled: Datadog.send(:components).telemetry.worker.enabled?
}
end
end
1 change: 0 additions & 1 deletion integration/apps/rails-five/spec/integration/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
expect(json_result).to include(
telemetry_enabled: true,
telemetry_client_enabled: true,
telemetry_worker_enabled: true
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def detailed_check
profiler_threads: Thread.list.map(&:name).select { |it| it && it.include?('Profiling') },
telemetry_enabled: Datadog.configuration.telemetry.enabled,
telemetry_client_enabled: Datadog.send(:components).telemetry.enabled,
telemetry_worker_enabled: Datadog.send(:components).telemetry.worker.enabled?
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
expect(json_result).to include(
telemetry_enabled: true,
telemetry_client_enabled: true,
telemetry_worker_enabled: true
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def detailed_check
profiler_threads: Thread.list.map(&:name).select { |it| it && it.include?('Profiling') },
telemetry_enabled: Datadog.configuration.telemetry.enabled,
telemetry_client_enabled: Datadog.send(:components).telemetry.enabled,
telemetry_worker_enabled: Datadog.send(:components).telemetry.worker.enabled?
}
end
end
1 change: 0 additions & 1 deletion integration/apps/rails-six/spec/integration/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
expect(json_result).to include(
telemetry_enabled: true,
telemetry_client_enabled: true,
telemetry_worker_enabled: true
)
end

Expand Down
6 changes: 5 additions & 1 deletion lib/datadog/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,22 @@ def configure
configuration = self.configuration
yield(configuration)

start_telemetry = false

safely_synchronize do |write_components|
write_components.call(
if components?
replace_components!(configuration, @components)
else
components = build_components(configuration)
components.telemetry.started!
start_telemetry = true
components
end
)
end

components.telemetry.started! if start_telemetry

configuration
end

Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/core/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def build_telemetry(settings, agent_settings, logger)

Telemetry::Client.new(
enabled: enabled,
heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds
heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds,
dependency_collection: settings.telemetry.dependency_collection
)
end
end
Expand Down
12 changes: 7 additions & 5 deletions lib/datadog/core/configuration/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ module Configuration
# Represents an instance of an integration configuration option
# @public_api
class Option
attr_reader :definition
# @!attribute [r] definition
# The definition object that matches this option.
# @return [Configuration::OptionDefinition]
# @!attribute [r] precedence_set
# When this option was last set, what was the value precedence used?
# @return [Precedence::Value]
attr_reader :definition, :precedence_set

# Option setting precedence.
module Precedence
Expand Down Expand Up @@ -303,10 +309,6 @@ def skip_validation?
['true', '1'].include?(ENV.fetch('DD_EXPERIMENTAL_SKIP_CONFIGURATION_VALIDATION', '').strip)
end

# Used for testing
attr_reader :precedence_set
private :precedence_set

# Anchor object that represents a value that is not set.
# This is necessary because `nil` is a valid value to be set.
UNSET = Object.new
Expand Down
10 changes: 10 additions & 0 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,16 @@ def initialize(*_)
# Client-side telemetry configuration
# @public_api
settings :telemetry do
# Whether the bundled Ruby gems as reported through telemetry.
#
# @default `DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED` environment variable, otherwise `true`.
# @return [Boolean]
option :dependency_collection do |o|
o.type :bool
o.env Core::Telemetry::Ext::ENV_DEPENDENCY_COLLECTION
o.default true
end

# Enable telemetry collection. This allows telemetry events to be emitted to the telemetry API.
#
# @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
Expand Down
8 changes: 7 additions & 1 deletion lib/datadog/core/environment/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ module Environment
module Platform
module_function

# @return [String] ISA of host; `uname -m`
def architecture
Identity.lang_version >= '2.2' ? Etc.uname[:machine] : Gem::Platform.local.cpu
end

# @return [String] name of host; `uname -n`
def hostname
Identity.lang_version >= '2.2' ? Etc.uname[:nodename] : nil
end

# @return [String] name of kernel; `uname -s`
# System name, normally `Linux` or `Darwin` (but 'Mac OS X' on JRuby);
# @return [String] name of kernel; `uname -s`.
def kernel_name
Identity.lang_version >= '2.2' ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
end
Expand Down
28 changes: 18 additions & 10 deletions lib/datadog/core/telemetry/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'emitter'
require_relative 'event'
require_relative 'heartbeat'
require_relative '../utils/forking'

Expand All @@ -10,21 +11,25 @@ module Telemetry
# Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecycle.
class Client
attr_reader \
:emitter,
:enabled,
:unsupported,
:worker
:unsupported

include Core::Utils::Forking

# @param enabled [Boolean] Determines whether telemetry events should be sent to the API
# @param heartbeat_interval_seconds [Float] How frequently heartbeats will be reported, in seconds.
def initialize(heartbeat_interval_seconds:, enabled: true)
# @param [Boolean] dependency_collection Whether to send the `app-dependencies-loaded` event
def initialize(heartbeat_interval_seconds:, dependency_collection:, enabled: true)
@enabled = enabled
@emitter = Emitter.new
@stopped = false
@unsupported = false
@started = false
@dependency_collection = dependency_collection

@worker = Telemetry::Heartbeat.new(enabled: @enabled, heartbeat_interval_seconds: heartbeat_interval_seconds) do
next unless @started # `started!` should be the first event, thus ensure that `heartbeat!` is not sent first.

heartbeat!
end
end
Expand All @@ -37,21 +42,24 @@ def disable!
def started!
return if !@enabled || forked?

res = @emitter.request(:'app-started')
res = @emitter.request(Event::AppStarted.new)

if res.not_found? # Telemetry is only supported by agent versions 7.34 and up
Datadog.logger.debug('Agent does not support telemetry; disabling future telemetry events.')
disable!
@unsupported = true # Prevent telemetry from getting re-enabled
return res
end

res
@emitter.request(Event::AppDependenciesLoaded.new) if @dependency_collection

@started = true
end

def emit_closing!
return if !@enabled || forked?

@emitter.request(:'app-closing')
@emitter.request(Event::AppClosing.new)
end

def stop!
Expand All @@ -64,22 +72,22 @@ def stop!
def integrations_change!
return if !@enabled || forked?

@emitter.request(:'app-integrations-change')
@emitter.request(Event::AppIntegrationsChange.new)
end

# Report configuration changes caused by Remote Configuration.
def client_configuration_change!(changes)
return if !@enabled || forked?

@emitter.request('app-client-configuration-change', data: { changes: changes, origin: 'remote_config' })
@emitter.request(Event::AppClientConfigurationChange.new(changes, 'remote_config'))
end

private

def heartbeat!
return if !@enabled || forked?

@emitter.request(:'app-heartbeat')
@emitter.request(Event::AppHeartbeat.new)
end
end
end
Expand Down
Loading

0 comments on commit 65eabdb

Please sign in to comment.