Module: Condux::TestEvent

Defined in:
lib/condux/test_event.rb

Overview

condux test-event — prove the pipeline end to end.

An error monitor's failure mode is silence, and silence looks exactly like health. This sends one info-level message through the real client and transport and reports the delivery outcome, so "did my DSN / network / relay work" is one command instead of waiting for a production error.

Constant Summary collapse

USAGE =
"Usage: condux test-event [--dsn <dsn>] [--message <text>]"

Class Method Summary collapse

Class Method Details

.argument(argv, name) ⇒ Object



46
47
48
49
# File 'lib/condux/test_event.rb', line 46

def argument(argv, name)
  index = argv.index(name)
  index && argv[index + 1]
end

.report(result, out, err) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/condux/test_event.rb', line 33

def report(result, out, err)
  message_count = "#{result.attempts} attempt#{result.attempts == 1 ? "" : "s"}"
  if result.ok
    out.puts "Delivered (#{message_count}). Check your project's issues list; a test message " \
             "appears as an info-level issue."
    return 0
  end

  err.puts "Delivery FAILED after #{message_count}: #{result.error || "relay answered #{result.status}"}. " \
           "Check the DSN (Project settings -> DSN keys) and that the ingest host is reachable."
  1
end

.run(argv, out: $stdout, err: $stderr) ⇒ Object

Runs the command; returns the process exit code (0 delivered, 1 failed, 2 usage).



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/condux/test_event.rb', line 17

def run(argv, out: $stdout, err: $stderr)
  command = argv.first
  return usage(err, "unknown command '#{command}'") unless command == "test-event"

  dsn = argument(argv, "--dsn") || ENV.fetch("CONDUX_DSN", nil)
  return usage(err, "no DSN. Pass --dsn <dsn> or set CONDUX_DSN") if dsn.nil? || dsn.empty?

  begin
    Condux.init(dsn: dsn, environment: "condux-test")
  rescue ArgumentError, URI::InvalidURIError => e
    return usage(err, e.message)
  end

  report(Condux.capture_message(argument(argv, "--message") || "Condux test event"), out, err)
end

.usage(err, reason) ⇒ Object



51
52
53
54
# File 'lib/condux/test_event.rb', line 51

def usage(err, reason)
  err.puts "condux: #{reason}. #{USAGE}"
  2
end