Class: Errsight::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
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
37
38
39
40
41
# File 'lib/errsight/configuration.rb', line 9

def initialize
  @api_key       = ENV["ERRSIGHT_API_KEY"]
  @environment   = ENV.fetch("ERRSIGHT_ENV", "production")
  @min_level     = :warning
  @host          = ENV.fetch("ERRSIGHT_HOST", "https://errsight.com")
  @timeout       = 5
  @enabled       = true
  @batch_size    = 10
  @flush_interval = 2  # seconds
  @max_queue_size = 1_000
  @logger                  = defined?(Rails) ? Rails.logger : Logger.new($stdout)
  # Off by default. When true, every Rails.logger call at min_level or
  # above becomes an Errsight event, which floods the issue list with
  # framework deprecation noise and burns customer event quota for
  # something that should be in their log aggregator, not their error
  # tracker. Customers who actually want log forwarding can opt in.
  @attach_to_rails_logger  = false
  @release                 = ENV["ERRSIGHT_RELEASE"]
  @shutdown_timeout        = 5  # seconds to wait for flush thread on shutdown
  # Auto-collect SQL queries as breadcrumbs via the sql.active_record
  # notification. Default on — this is the headline Rails feature.
  # Customers with extreme-query-volume workloads can disable.
  @breadcrumbs_active_record = true
  # Bind values can carry PII (emails, tokens, customer IDs) so we ship
  # the parameterized SQL only by default. Compliance-relaxed customers
  # opt in.
  @breadcrumbs_active_record_capture_binds = false
  # Per-event filter. Receives the event hash, must return a (possibly
  # modified) hash to send, or nil to drop. Used by compliance teams to
  # scrub PII, by ops teams to drop noisy errors, and by anyone who
  # wants final-mile control before events leave the process.
  @before_send                             = nil
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def api_key
  @api_key
end

#attach_to_rails_loggerObject

Returns the value of attribute attach_to_rails_logger.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def attach_to_rails_logger
  @attach_to_rails_logger
end

#batch_sizeObject

Returns the value of attribute batch_size.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def batch_size
  @batch_size
end

#before_sendObject

Returns the value of attribute before_send.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def before_send
  @before_send
end

Returns the value of attribute breadcrumbs_active_record.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def breadcrumbs_active_record
  @breadcrumbs_active_record
end

Returns the value of attribute breadcrumbs_active_record_capture_binds.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def breadcrumbs_active_record_capture_binds
  @breadcrumbs_active_record_capture_binds
end

#enabledObject

Returns the value of attribute enabled.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def enabled
  @enabled
end

#environmentObject

Returns the value of attribute environment.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def environment
  @environment
end

#flush_intervalObject

Returns the value of attribute flush_interval.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def flush_interval
  @flush_interval
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def logger
  @logger
end

#max_queue_sizeObject

Returns the value of attribute max_queue_size.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def max_queue_size
  @max_queue_size
end

#min_levelObject

Returns the value of attribute min_level.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def min_level
  @min_level
end

#releaseObject

Returns the value of attribute release.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def release
  @release
end

#shutdown_timeoutObject

Returns the value of attribute shutdown_timeout.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def shutdown_timeout
  @shutdown_timeout
end

#timeoutObject

Returns the value of attribute timeout.



3
4
5
# File 'lib/errsight/configuration.rb', line 3

def timeout
  @timeout
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  @enabled && !api_key.nil? && !api_key.strip.empty?
end

#events_endpointObject



53
54
55
# File 'lib/errsight/configuration.rb', line 53

def events_endpoint
  "#{host.chomp('/')}/api/v1/events"
end

#validate!Object



47
48
49
50
51
# File 'lib/errsight/configuration.rb', line 47

def validate!
  if api_key.nil? || api_key.strip.empty?
    logger&.debug("[Errsight] api_key is not set; Errsight is disabled until one is configured (set ERRSIGHT_API_KEY or config.api_key).")
  end
end