Method: Honeybadger::Agent#event

Defined in:
lib/honeybadger/agent.rb

#event(event_type, payload = {}) ⇒ void

This method returns an undefined value.

Sends event to events backend

Examples:

# With event type as first argument (recommended):
Honeybadger.event("user_signed_up", user_id: 123)

# With just a payload:
Honeybadger.event(event_type: "user_signed_up", user_id: 123)

Parameters:

  • event_name (String, Hash)

    a String describing the event or a Hash when the second argument is omitted.

  • payload (Hash) (defaults to: {})

    Additional data to be sent with the event as keyword arguments

[View source]

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/honeybadger/agent.rb', line 409

def event(event_type, payload = {})
  init_events_worker

  extra_payload = {}.tap do |p|
    p[:request_id] = context_manager.get_request_id if context_manager.get_request_id
    p[:hostname] = config[:hostname].to_s if config[:'events.attach_hostname']
  end

  event = Event.new(event_type, extra_payload.merge(payload))

  config.before_event_hooks.each do |hook|
    with_error_handling { hook.call(event) }
  end

  return if config.ignored_events.any? do |check|
    with_error_handling do
      check.all? do |keys, value|
        if keys == [:event_type]
          event.event_type&.match?(value)
        elsif event.dig(*keys)
          event.dig(*keys).to_s.match?(value)
        end
      end
    end
  end

  return if event.halted?

  events_worker.push(event.as_json)
end