Class: Lapsoss::Adapters::AppsignalAdapter

Inherits:
Base
  • Object
show all
Defined in:
lib/lapsoss/adapters/appsignal_adapter.rb

Constant Summary collapse

PUSH_API_URI =
"https://push.appsignal.com"
ERRORS_API_URI =
"https://appsignal-endpoint.net"

Constants inherited from Base

Base::JSON_CONTENT_TYPE, Base::USER_AGENT

Instance Attribute Summary

Attributes inherited from Base

#name, #settings

Instance Method Summary collapse

Methods inherited from Base

#capabilities, #disable!, #enable!, #enabled?, #flush, #supports?

Methods included from Validators

logger, validate_api_key!, validate_callable!, validate_dsn!, validate_environment!, validate_presence!, validate_retries!, validate_sample_rate!, validate_timeout!, validate_url!

Constructor Details

#initialize(name, settings = {}) ⇒ AppsignalAdapter



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lapsoss/adapters/appsignal_adapter.rb', line 12

def initialize(name, settings = {})
  super
  @push_api_key = settings[:push_api_key] || ENV.fetch("APPSIGNAL_PUSH_API_KEY", nil)
  @frontend_api_key = settings[:frontend_api_key] || ENV.fetch("APPSIGNAL_FRONTEND_API_KEY", nil)
  @app_name = settings[:app_name] || ENV.fetch("APPSIGNAL_APP_NAME", nil)
  @environment = Lapsoss.configuration.environment

  # Just log if keys look unusual but don't fail
  if @push_api_key.present?
    validate_api_key!(@push_api_key, "AppSignal push API key", format: :uuid)
  end

  if @frontend_api_key.present?
    validate_api_key!(@frontend_api_key, "AppSignal frontend API key", format: :uuid)
  end

  if @push_api_key.blank? && @frontend_api_key.blank?
    Lapsoss.configuration.logger&.warn "[Lapsoss::AppsignalAdapter] No API keys provided, adapter disabled"
    @enabled = false
    return
  end

  @push_client = create_http_client(PUSH_API_URI) if @push_api_key
  @errors_client = create_http_client(ERRORS_API_URI) if @frontend_api_key
end

Instance Method Details

#capture(event) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lapsoss/adapters/appsignal_adapter.rb', line 38

def capture(event)
  return unless enabled? && @errors_client

  payload = build_error_payload(event)
  return unless payload

  path = "/errors?api_key=#{@frontend_api_key}"
  headers = default_headers(content_type: json_content_type)

  begin
    @errors_client.post(path, body: ActiveSupport::JSON.encode(payload), headers: headers)
  rescue DeliveryError => e
    # Log the error and potentially notify error handler
    Lapsoss.configuration.logger&.error("[Lapsoss::AppsignalAdapter] Failed to deliver event: #{e.message}")
    Lapsoss.configuration.error_handler&.call(e)

    # Re-raise to let the caller know delivery failed
    raise
  end
end

#shutdownObject



59
60
61
62
63
# File 'lib/lapsoss/adapters/appsignal_adapter.rb', line 59

def shutdown
  @push_client&.shutdown
  @errors_client&.shutdown
  super
end