Module: NetworkResiliency::Adapter::Postgres::Instrumentation

Defined in:
lib/network_resiliency/adapter/postgres.rb

Instance Method Summary collapse

Instance Method Details

#connect_start(opts) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/network_resiliency/adapter/postgres.rb', line 20

def connect_start(opts)
  host = opts[:host].split(",")[0] if opts[:host]

  return super unless NetworkResiliency.enabled?(:postgres)

  begin
    ts = -NetworkResiliency.timestamp

    super
  rescue PG::Error => e
    # capture error
    raise
  ensure
    ts += NetworkResiliency.timestamp

    NetworkResiliency.record(
      adapter: :postgres,
      action: :connect,
      destination: host,
      error: e&.class,
      duration: ts,
      timeout: opts[:connect_timeout].to_i * 1_000,
    )
  end
end