Class: Inspec::Telemetry

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/utils/telemetry.rb,
lib/inspec/utils/telemetry/base.rb,
lib/inspec/utils/telemetry/http.rb,
lib/inspec/utils/telemetry/null.rb,
lib/inspec/utils/telemetry/run_context_probe.rb

Defined Under Namespace

Classes: Base, HTTP, Null, RunContextProbe

Constant Summary collapse

@@instance =
nil
@@config =
nil

Class Method Summary collapse

Class Method Details

.configObject



68
69
70
# File 'lib/inspec/utils/telemetry.rb', line 68

def self.config
  @@config
end

.determine_backend_classObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/inspec/utils/telemetry.rb', line 17

def self.determine_backend_class
  # Don't perform telemetry action for other InSpec distros
  # Don't perform telemetry action if running under Automate - Automate does LDC tracking for us
  # Don't perform telemetry action if license is a commercial license
  # Don't perform telemetry action if running under Test Kitchen

  if Inspec::Dist::EXEC_NAME != "inspec" ||
      Inspec::Telemetry::RunContextProbe.under_automate? ||
      license&.license_type&.downcase == "commercial" ||
      Inspec::Telemetry::RunContextProbe.guess_run_context == "test-kitchen"

    Inspec::Log.debug "Determined telemetry operation is not applicable and hence aborting it."
    return Inspec::Telemetry::Null
  end

  if Inspec::Dist::EXEC_NAME == "inspec" && telemetry_disabled?
    # Issue a warning if an InSpec user is explicitly trying to opt out of telemetry using cli option
    Inspec::Log.warn "Telemetry opt-out is not permissible."
  end

  Inspec::Log.debug "Determined HTTP instance for telemetry"

  Inspec::Telemetry::HTTP
end

.instanceObject



13
14
15
# File 'lib/inspec/utils/telemetry.rb', line 13

def self.instance
  @@instance ||= determine_backend_class.new
end

.licenseObject



42
43
44
45
# File 'lib/inspec/utils/telemetry.rb', line 42

def self.license
  Inspec::Log.debug "Fetching license context for telemetry check"
  @license = ChefLicensing.license_context
end

.note_feature_usage(feature_name) ⇒ Object



64
65
66
# File 'lib/inspec/utils/telemetry.rb', line 64

def self.note_feature_usage(feature_name)
  instance.note_feature_usage(feature_name)
end

.run_ending(opts) ⇒ Object



57
58
59
60
61
62
# File 'lib/inspec/utils/telemetry.rb', line 57

def self.run_ending(opts)
  @@config ||= opts[:conf]
  instance.run_ending(opts)
rescue StandardError => e
  Inspec::Log.debug "Encountered error in Telemetry end run call -> #{e.message}"
end

.run_starting(opts) ⇒ Object

These class methods make it convenient to call from anywhere within the InSpec codebase.



50
51
52
53
54
55
# File 'lib/inspec/utils/telemetry.rb', line 50

def self.run_starting(opts)
  @@config ||= opts[:conf]
  instance.run_starting(opts)
rescue StandardError => e
  Inspec::Log.debug "Encountered error in Telemetry start run call -> #{e.message}"
end

.telemetry_disabled?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/inspec/utils/telemetry.rb', line 72

def self.telemetry_disabled?
  config.telemetry_options["enable_telemetry"].nil? ? false : !config.telemetry_options["enable_telemetry"]
end