Class: Checkend::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/checkend/configuration.rb

Overview

Configuration holds all settings for the Checkend SDK.

Settings can be configured via environment variables or the configure block:

Checkend.configure do |config|
config.api_key = 'your-ingestion-key'
config.endpoint = 'https://your-checkend-server.com'
end

Constant Summary collapse

DEFAULT_FILTER_KEYS =
%w[
  password
  password_confirmation
  passwd
  secret
  token
  api_key
  access_token
  refresh_token
  authorization
  bearer
  credit_card
  card_number
  cvv
  cvc
  ssn
].freeze
DEFAULT_IGNORED_EXCEPTIONS =
%w[
  ActiveRecord::RecordNotFound
  ActionController::RoutingError
  ActionController::InvalidAuthenticityToken
  ActionController::UnknownAction
  ActionController::UnknownFormat
  ActionController::UnknownHttpMethod
  ActionDispatch::Http::MimeNegotiation::InvalidType
  CGI::Session::CookieStore::TamperedWithCookie
  Mongoid::Errors::DocumentNotFound
  Sinatra::NotFound
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Configuration

Returns a new instance of Configuration.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/checkend/configuration.rb', line 85

def initialize
  @api_key = ENV.fetch('CHECKEND_API_KEY', nil)
  @endpoint = ENV.fetch('CHECKEND_ENDPOINT', nil)
  @environment = detect_environment
  @enabled = nil # Will be computed based on environment
  @timeout = 15
  @open_timeout = 5
  @ssl_verify = true
  @ignored_exceptions = DEFAULT_IGNORED_EXCEPTIONS.dup
  @filter_keys = DEFAULT_FILTER_KEYS.dup
  @before_notify = []
  @send_request_data = true
  @send_session_data = true
  @send_environment = false
  @send_user_data = true
  @async = true
  @max_queue_size = 1000
  @shutdown_timeout = 5
  @debug = ENV.fetch('CHECKEND_DEBUG', 'false') == 'true'
end

Instance Attribute Details

#api_key ⇒ Object

Core settings



17
18
19
# File 'lib/checkend/configuration.rb', line 17

def api_key
  @api_key
end

#app_name ⇒ Object

Application metadata



23
24
25
# File 'lib/checkend/configuration.rb', line 23

def app_name
  @app_name
end

#async ⇒ Object

Async settings



46
47
48
# File 'lib/checkend/configuration.rb', line 46

def async
  @async
end

#before_notify ⇒ Object

Returns the value of attribute before_notify.



37
38
39
# File 'lib/checkend/configuration.rb', line 37

def before_notify
  @before_notify
end

#debug ⇒ Object

Returns the value of attribute debug.



52
53
54
# File 'lib/checkend/configuration.rb', line 52

def debug
  @debug
end

#enabled ⇒ Object

Returns the value of attribute enabled.



20
21
22
# File 'lib/checkend/configuration.rb', line 20

def enabled
  @enabled
end

#endpoint ⇒ Object

Returns the value of attribute endpoint.



18
19
20
# File 'lib/checkend/configuration.rb', line 18

def endpoint
  @endpoint
end

#environment ⇒ Object

Returns the value of attribute environment.



19
20
21
# File 'lib/checkend/configuration.rb', line 19

def environment
  @environment
end

#filter_keys ⇒ Object

Returns the value of attribute filter_keys.



36
37
38
# File 'lib/checkend/configuration.rb', line 36

def filter_keys
  @filter_keys
end

#ignored_exceptions ⇒ Object

Error filtering



35
36
37
# File 'lib/checkend/configuration.rb', line 35

def ignored_exceptions
  @ignored_exceptions
end

#logger ⇒ Object

Logging



51
52
53
# File 'lib/checkend/configuration.rb', line 51

def logger
  @logger
end

#max_queue_size ⇒ Object

Returns the value of attribute max_queue_size.



47
48
49
# File 'lib/checkend/configuration.rb', line 47

def max_queue_size
  @max_queue_size
end

#open_timeout ⇒ Object

Returns the value of attribute open_timeout.



29
30
31
# File 'lib/checkend/configuration.rb', line 29

def open_timeout
  @open_timeout
end

#proxy ⇒ Object

Returns the value of attribute proxy.



30
31
32
# File 'lib/checkend/configuration.rb', line 30

def proxy
  @proxy
end

#revision ⇒ Object

Returns the value of attribute revision.



24
25
26
# File 'lib/checkend/configuration.rb', line 24

def revision
  @revision
end

#root_path ⇒ Object

Returns the value of attribute root_path.



25
26
27
# File 'lib/checkend/configuration.rb', line 25

def root_path
  @root_path
end

#send_environment ⇒ Object

Returns the value of attribute send_environment.



42
43
44
# File 'lib/checkend/configuration.rb', line 42

def send_environment
  @send_environment
end

#send_request_data ⇒ Object

Context settings



40
41
42
# File 'lib/checkend/configuration.rb', line 40

def send_request_data
  @send_request_data
end

#send_session_data ⇒ Object

Returns the value of attribute send_session_data.



41
42
43
# File 'lib/checkend/configuration.rb', line 41

def send_session_data
  @send_session_data
end

#send_user_data ⇒ Object

Returns the value of attribute send_user_data.



43
44
45
# File 'lib/checkend/configuration.rb', line 43

def send_user_data
  @send_user_data
end

#shutdown_timeout ⇒ Object

Returns the value of attribute shutdown_timeout.



48
49
50
# File 'lib/checkend/configuration.rb', line 48

def shutdown_timeout
  @shutdown_timeout
end

#ssl_ca_path ⇒ Object

Returns the value of attribute ssl_ca_path.



31
32
33
# File 'lib/checkend/configuration.rb', line 31

def ssl_ca_path
  @ssl_ca_path
end

#ssl_verify ⇒ Object

Returns the value of attribute ssl_verify.



32
33
34
# File 'lib/checkend/configuration.rb', line 32

def ssl_verify
  @ssl_verify
end

#timeout ⇒ Object

HTTP settings



28
29
30
# File 'lib/checkend/configuration.rb', line 28

def timeout
  @timeout
end

Instance Method Details

#enabled? ⇒ Boolean

Check if SDK is enabled (considers explicit setting and environment)

Returns:

  • (Boolean)


112
113
114
115
116
# File 'lib/checkend/configuration.rb', line 112

def enabled?
  return @enabled unless @enabled.nil?

  production_or_staging?
end

#ignore_exception?(exception) ⇒ Boolean

Check if an exception should be ignored

Returns:

  • (Boolean)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/checkend/configuration.rb', line 119

def ignore_exception?(exception)
  exception_class_name = exception.class.name

  ignored_exceptions.any? do |ignored|
    if ignored.is_a?(String)
      exception_class_name == ignored || exception_ancestors_include?(exception, ignored)
    elsif ignored.is_a?(Class)
      exception.is_a?(ignored)
    elsif ignored.is_a?(Regexp)
      ignored.match?(exception_class_name)
    else
      false
    end
  end
end

#resolved_logger ⇒ Object

Get the logger instance



136
137
138
# File 'lib/checkend/configuration.rb', line 136

def resolved_logger
  @logger || default_logger
end

#valid? ⇒ Boolean

Check if configuration is valid for sending errors

Returns:

  • (Boolean)


107
108
109
# File 'lib/checkend/configuration.rb', line 107

def valid?
  !api_key.nil? && !api_key.empty? && !endpoint.nil? && !endpoint.empty?
end