Module: Datadog::CI::Git::Telemetry

Defined in:
lib/datadog/ci/git/telemetry.rb

Class Method Summary collapse

Class Method Details

.exit_code_for(exit_code: nil, executable_missing: false) ⇒ Object



42
43
44
45
46
47
# File 'lib/datadog/ci/git/telemetry.rb', line 42

def self.exit_code_for(exit_code: nil, executable_missing: false)
  return Ext::Telemetry::ExitCode::MISSING if executable_missing
  return exit_code.to_s if exit_code

  nil
end

.git_command(command) ⇒ Object



10
11
12
# File 'lib/datadog/ci/git/telemetry.rb', line 10

def self.git_command(command)
  Utils::Telemetry.inc(Ext::Telemetry::METRIC_GIT_COMMAND, 1, tags_for_command(command))
end

.git_command_errors(command, exit_code: nil, executable_missing: false) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/datadog/ci/git/telemetry.rb', line 14

def self.git_command_errors(command, exit_code: nil, executable_missing: false)
  tags = tags_for_command(command)

  exit_code_tag_value = exit_code_for(exit_code: exit_code, executable_missing: executable_missing)
  tags[Ext::Telemetry::TAG_EXIT_CODE] = exit_code_tag_value if exit_code_tag_value

  Utils::Telemetry.inc(Ext::Telemetry::METRIC_GIT_COMMAND_ERRORS, 1, tags)
end

.git_command_ms(command, duration_ms) ⇒ Object



23
24
25
# File 'lib/datadog/ci/git/telemetry.rb', line 23

def self.git_command_ms(command, duration_ms)
  Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_COMMAND_MS, duration_ms, tags_for_command(command))
end

.tags_for_command(command) ⇒ Object



38
39
40
# File 'lib/datadog/ci/git/telemetry.rb', line 38

def self.tags_for_command(command)
  {Ext::Telemetry::TAG_COMMAND => command}
end

.track_error(e, command) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/datadog/ci/git/telemetry.rb', line 27

def self.track_error(e, command)
  case e
  when Errno::ENOENT
    git_command_errors(command, executable_missing: true)
  when CLI::GitCommandExecutionError
    git_command_errors(command, exit_code: e.status&.to_i)
  else
    git_command_errors(command, exit_code: -9000)
  end
end