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



66
67
68
# File 'lib/inspec/utils/telemetry.rb', line 66

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
# 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

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

    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



40
41
42
43
# File 'lib/inspec/utils/telemetry.rb', line 40

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

.note_feature_usage(feature_name) ⇒ Object



62
63
64
# File 'lib/inspec/utils/telemetry.rb', line 62

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

.run_ending(opts) ⇒ Object



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

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.



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

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)


70
71
72
# File 'lib/inspec/utils/telemetry.rb', line 70

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