Class: Chronos::Configuration

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

Overview

Mutable configuration used only while the Chronos agent is being set up.

Examples:

config = Chronos::Configuration.new
config.project_id = 'project-id'
config.project_key = 'project-key'
config.host = 'https://chronos.example.com'
snapshot = config.snapshot

Defined Under Namespace

Classes: Snapshot

Constant Summary collapse

DEFAULT_BLOCKLIST_KEYS =
%w(
  password password_confirmation passwd secret api_key apikey authorization
  token access_token refresh_token private_key client_secret cookie set-cookie
  session credit_card card_number cvv cpf cnpj
).freeze
ATTRIBUTES =
[
  :project_id, :project_key, :host, :environment, :app_version,
  :service_name, :root_directory, :logger, :timeout, :open_timeout,
  :queue_size, :workers, :enabled, :error_notifications,
  :ignored_environments, :proxy, :ssl_verify, :user_agent,
  :max_payload_size, :gzip, :blocklist_keys, :allowlist_keys,
  :filters, :hash_keys, :anonymize_ip
].freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/chronos/configuration.rb', line 39

def initialize
  @project_id = nil
  @project_key = nil
  @host = nil
  @environment = "production"
  @app_version = nil
  @service_name = nil
  @root_directory = Dir.pwd
  @logger = nil
  @timeout = 5.0
  @open_timeout = 2.0
  @queue_size = 100
  @workers = 1
  @enabled = true
  @error_notifications = true
  @ignored_environments = []
  @proxy = nil
  @ssl_verify = true
  @user_agent = "chronos-ruby/#{Chronos::VERSION}"
  @max_payload_size = 1_048_576
  @gzip = false
  @blocklist_keys = DEFAULT_BLOCKLIST_KEYS.dup
  @allowlist_keys = []
  @filters = []
  @hash_keys = []
  @anonymize_ip = true
end

Instance Method Details

#snapshotObject

Raises:



67
68
69
70
71
72
# File 'lib/chronos/configuration.rb', line 67

def snapshot
  errors = validation_errors
  raise ConfigurationError, errors.join(", ") unless errors.empty?

  Snapshot.new(to_hash)
end

#valid?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/chronos/configuration.rb', line 74

def valid?
  validation_errors.empty?
end

#validation_errorsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/chronos/configuration.rb', line 78

def validation_errors
  errors = []
  if enabled
    errors << "project_id is required" if blank?(project_id)
    errors << "project_key is required" if blank?(project_key)
    errors.concat(host_errors)
  end
  errors << "timeout must be greater than zero" unless positive_number?(timeout)
  errors << "open_timeout must be greater than zero" unless positive_number?(open_timeout)
  errors << "queue_size must be a positive integer" unless positive_integer?(queue_size)
  errors << "workers must be a positive integer" unless positive_integer?(workers)
  errors << "max_payload_size must be a positive integer" unless positive_integer?(max_payload_size)
  errors.concat(privacy_errors)
  errors
end