Module: Datadog::Core::Diagnostics::EnvironmentCollector

Defined in:
lib/datadog/core/diagnostics/environment_logger.rb

Overview

Collects environment information for Core diagnostic logging

Class Method Summary collapse

Class Method Details

.collect_config!Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 62

def collect_config!
  {
    date: date,
    os_name: os_name,
    version: version,
    lang: lang,
    lang_version: lang_version,
    env: env,
    service: service,
    dd_version: dd_version,
    debug: debug,
    tags: tags,
    runtime_metrics_enabled: runtime_metrics_enabled,
    vm: vm,
    health_metrics_enabled: health_metrics_enabled
  }
end

.dateString

Returns current time in ISO8601 format.

Returns:

  • (String)

    current time in ISO8601 format



81
82
83
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 81

def date
  Time.now.utc.iso8601
end

.dd_versionString

Returns configured application version.

Returns:

  • (String)

    configured application version



119
120
121
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 119

def dd_version
  Datadog.configuration.version
end

.debugBoolean?

Returns debug mode enabled in configuration.

Returns:

  • (Boolean, nil)

    debug mode enabled in configuration



124
125
126
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 124

def debug
  !!Datadog.configuration.diagnostics.debug
end

.envString

Returns configured application environment.

Returns:

  • (String)

    configured application environment



109
110
111
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 109

def env
  Datadog.configuration.env
end

.health_metrics_enabledBoolean?

Returns health metrics enabled in configuration.

Returns:

  • (Boolean, nil)

    health metrics enabled in configuration



156
157
158
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 156

def health_metrics_enabled
  !!Datadog.configuration.health_metrics.enabled
end

.langString

Returns “ruby”.

Returns:

  • (String)

    “ruby”



97
98
99
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 97

def lang
  Core::Environment::Ext::LANG
end

.lang_versionString

Supported Ruby language version. Will be distinct from VM version for non-MRI environments.

Returns:

  • (String)


104
105
106
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 104

def lang_version
  Core::Environment::Ext::LANG_VERSION
end

.os_nameString

Best portable guess of OS information.

Returns:

  • (String)

    platform string



87
88
89
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 87

def os_name
  RbConfig::CONFIG['host']
end

.runtime_metrics_enabledBoolean?

Returns runtime metrics enabled in configuration.

Returns:

  • (Boolean, nil)

    runtime metrics enabled in configuration



137
138
139
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 137

def runtime_metrics_enabled
  Datadog.configuration.runtime_metrics.enabled
end

.serviceString

Returns configured application service name.

Returns:

  • (String)

    configured application service name



114
115
116
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 114

def service
  Datadog.configuration.service
end

.tagsHash?

Returns concatenated list of global tracer tags configured.

Returns:

  • (Hash, nil)

    concatenated list of global tracer tags configured



129
130
131
132
133
134
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 129

def tags
  tags = Datadog.configuration.tags
  return nil if tags.empty?

  hash_serializer(tags)
end

.versionString

Returns datadog version.

Returns:

  • (String)

    datadog version



92
93
94
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 92

def version
  Datadog::VERSION::STRING
end

.vmString?

Ruby VM name and version. Examples: “ruby-2.7.1”, “jruby-9.2.11.1”, “truffleruby-20.1.0”

Returns:

  • (String, nil)


144
145
146
147
148
149
150
151
152
153
# File 'lib/datadog/core/diagnostics/environment_logger.rb', line 144

def vm
  # RUBY_ENGINE_VERSION returns the VM version, which
  # will differ from RUBY_VERSION for non-mri VMs.
  if defined?(RUBY_ENGINE_VERSION)
    "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}"
  else
    # Ruby < 2.3 doesn't support RUBY_ENGINE_VERSION
    "#{RUBY_ENGINE}-#{RUBY_VERSION}"
  end
end