Module: Datadog::Core::Telemetry::Collector

Includes:
Configuration
Included in:
Event
Defined in:
lib/datadog/core/telemetry/collector.rb

Overview

Module defining methods for collecting metadata for telemetry

Instance Attribute Summary

Attributes included from Configuration

#configuration

Instance Method Summary collapse

Methods included from Configuration

#configuration_for, #configure, #configure_onto, #health_metrics, #logger, #shutdown!

Instance Method Details

#additional_payloadObject

Forms a hash of configuration key value pairs to be sent in the additional payload



25
26
27
# File 'lib/datadog/core/telemetry/collector.rb', line 25

def additional_payload
  additional_payload_variables
end

#applicationObject

Forms a telemetry application object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/datadog/core/telemetry/collector.rb', line 30

def application
  Telemetry::V1::Application.new(
    env: env,
    language_name: Datadog::Core::Environment::Ext::LANG,
    language_version: Datadog::Core::Environment::Ext::LANG_VERSION,
    products: products,
    runtime_name: Datadog::Core::Environment::Ext::RUBY_ENGINE,
    runtime_version: Datadog::Core::Environment::Ext::ENGINE_VERSION,
    service_name: service_name,
    service_version: service_version,
    tracer_version: library_version
  )
end

#configurationsObject

Forms a hash of standard key value pairs to be sent in the app-started event configuration



45
46
47
48
49
50
51
52
53
# File 'lib/datadog/core/telemetry/collector.rb', line 45

def configurations
  hash = {
    DD_AGENT_HOST: Datadog.configuration.agent.host,
    DD_AGENT_TRANSPORT: agent_transport,
    DD_TRACE_SAMPLE_RATE: format_configuration_value(Datadog.configuration.tracing.sampling.default_rate),
  }
  hash.compact!
  hash
end

#dependenciesObject

Forms a telemetry app-started dependencies object



56
57
58
59
60
61
62
# File 'lib/datadog/core/telemetry/collector.rb', line 56

def dependencies
  Gem.loaded_specs.collect do |name, loaded_gem|
    Datadog::Core::Telemetry::V1::Dependency.new(
      name: name, version: loaded_gem.version.to_s, hash: loaded_gem.hash.to_s
    )
  end
end

#hostObject

Forms a telemetry host object



65
66
67
68
69
70
71
72
73
# File 'lib/datadog/core/telemetry/collector.rb', line 65

def host
  Telemetry::V1::Host.new(
    container_id: Core::Environment::Container.container_id,
    hostname: Core::Environment::Platform.hostname,
    kernel_name: Core::Environment::Platform.kernel_name,
    kernel_release: Core::Environment::Platform.kernel_release,
    kernel_version: Core::Environment::Platform.kernel_version
  )
end

#integrationsObject

Forms a telemetry app-started integrations object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/datadog/core/telemetry/collector.rb', line 76

def integrations
  Datadog.registry.map do |integration|
    is_instrumented = instrumented?(integration)
    is_enabled = is_instrumented && patched?(integration)
    Telemetry::V1::Integration.new(
      name: integration.name.to_s,
      enabled: is_enabled,
      version: integration_version(integration),
      compatible: integration_compatible?(integration),
      error: (patch_error(integration) if is_instrumented && !is_enabled),
      auto_enabled: is_enabled ? integration_auto_instrument?(integration) : nil
    )
  end
end

#runtime_idObject

Returns the runtime ID of the current process



92
93
94
# File 'lib/datadog/core/telemetry/collector.rb', line 92

def runtime_id
  Datadog::Core::Environment::Identity.id
end

#tracer_timeObject

Returns the current as a UNIX timestamp in seconds



97
98
99
# File 'lib/datadog/core/telemetry/collector.rb', line 97

def tracer_time
  Time.now.to_i
end