Module: Pgbus::Integrations::Appsignal::Subscriber

Defined in:
lib/pgbus/integrations/appsignal/subscriber.rb

Overview

Translates Pgbus::Instrumentation events into AppSignal transactions and custom metrics.

Job and event-handler events open a BACKGROUND_JOB transaction so they appear under AppSignal's "Performance > Background jobs" view, with action <JobClass>#perform or <HandlerClass>#handle. All other events are reported as counters or distributions only.

All metric names are prefixed pgbus_. Tag keys avoid high-cardinality values (no msg_id, no event_id) so AppSignal's metric storage stays efficient.

Class Method Summary collapse

Class Method Details

.install!Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pgbus/integrations/appsignal/subscriber.rb', line 28

def install!
  return false if @installed

  @subscriptions = [
    subscribe("pgbus.executor.execute") { |event| on_executor_execute(event) },
    subscribe("pgbus.job_completed") { |event| on_job_completed(event) },
    subscribe("pgbus.job_failed") { |event| on_job_failed(event) },
    subscribe("pgbus.job_dead_lettered") { |event| on_job_dead_lettered(event) },
    subscribe("pgbus.event_processed") { |event| on_event_processed(event) },
    subscribe("pgbus.event_failed") { |event| on_event_failed(event) },
    subscribe("pgbus.client.send_message") { |event| on_send_message(event) },
    subscribe("pgbus.client.send_batch") { |event| on_send_batch(event) },
    subscribe("pgbus.client.read_batch") { |event| on_read_batch(event) },
    subscribe("pgbus.stream.broadcast") { |event| on_stream_broadcast(event) },
    subscribe("pgbus.outbox.publish") { |event| on_outbox_publish(event) },
    subscribe("pgbus.recurring.enqueue") { |event| on_recurring_enqueue(event) },
    subscribe("pgbus.worker.recycle") { |event| on_worker_recycle(event) },
    subscribe("pgbus.consumer.recycle") { |event| on_consumer_recycle(event) }
    # pgbus.client.pool is deliberately NOT subscribed here — the
    # minutely Probe#track_pool already reports pgbus_pool_size /
    # pgbus_pool_available gauges for AppSignal (see probe.rb).
    # Subscribing here too would double-report on every heartbeat
    # and skew the gauges.
  ]
  @installed = true
end

.installed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/pgbus/integrations/appsignal/subscriber.rb', line 55

def installed?
  @installed == true
end

.reset!Object



59
60
61
62
63
# File 'lib/pgbus/integrations/appsignal/subscriber.rb', line 59

def reset!
  @subscriptions&.each { |s| ActiveSupport::Notifications.unsubscribe(s) }
  @subscriptions = []
  @installed = false
end