Class: CloseYourIt::Configuration

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

Overview

Tiene tutte le opzioni del client. Costruita da ‘CloseYourIt.init { |c| … }`. Senza `endpoint_url`/`token`/`project_id` (o con `http://` in produzione) il client è no-op.

Constant Summary collapse

DEFAULT_EXCLUDED_EXCEPTIONS =
%w[
  ActionController::RoutingError
  ActiveRecord::RecordNotFound
].freeze
DEFAULT_REQUEST_HEADER_ALLOWLIST =

Header HTTP catturati nel contesto request (mai Authorization/Cookie → niente PII/segreti).

%w[Accept Content-Type User-Agent Referer].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
36
37
38
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
66
67
68
69
70
# File 'lib/closeyourit/configuration.rb', line 29

def initialize
  @endpoint_url = ENV.fetch("CLOSEYOURIT_ENDPOINT_URL", nil)
  @token        = ENV.fetch("CLOSEYOURIT_TOKEN", nil)
  @project_id   = ENV.fetch("CLOSEYOURIT_PROJECT_ID", nil)
  @release      = ENV.fetch("CLOSEYOURIT_RELEASE", nil)
  @environment  = ENV.fetch("CLOSEYOURIT_ENVIRONMENT") { detect_environment }

  @excluded_exceptions = DEFAULT_EXCLUDED_EXCEPTIONS.dup
  @before_send         = nil

  @async_threads               = default_threads
  @background_worker_max_queue  = 30

  @slow_query_threshold_ms  = 100
  @slow_method_threshold_ms = 200

  @send_pii         = false
  @obfuscate_sql    = true
  @send_server_name = true

  # Contesto HTTP della richiesta (method/url/header allowlist). Body/query/IP solo con send_pii.
  @capture_request          = true
  @request_header_allowlist = DEFAULT_REQUEST_HEADER_ALLOWLIST.dup

  # Breadcrumbs: cronologia (query offuscate, eventi custom) allegata all'errore.
  @breadcrumbs_enabled = true
  @max_breadcrumbs     = 100

  # Sampling probabilistico di errori/messaggi (1.0 = invia tutto, 0.0 = niente).
  @sample_rate = 1.0

  # Cattura errori handled (Rails.error.report) e degli ActiveJob/Sidekiq (oggi persi).
  @capture_handled_errors   = true
  @report_active_job_errors = true

  # Cattura valori dei parametri — opt-in, default OFF (privacy). I bind/argomenti possono contenere PII.
  @capture_query_bindings   = false
  @capture_method_arguments = false

  @filter_parameters      = []
  @scrub_message_patterns = []
end

Instance Attribute Details

#async_threadsObject

Returns the value of attribute async_threads.



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

def async_threads
  @async_threads
end

#background_worker_max_queueObject

Returns the value of attribute background_worker_max_queue.



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

def background_worker_max_queue
  @background_worker_max_queue
end

#before_sendObject

Returns the value of attribute before_send.



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

def before_send
  @before_send
end

Returns the value of attribute breadcrumbs_enabled.



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

def breadcrumbs_enabled
  @breadcrumbs_enabled
end

#capture_handled_errorsObject

Returns the value of attribute capture_handled_errors.



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

def capture_handled_errors
  @capture_handled_errors
end

#capture_method_argumentsObject

Returns the value of attribute capture_method_arguments.



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

def capture_method_arguments
  @capture_method_arguments
end

#capture_query_bindingsObject

Returns the value of attribute capture_query_bindings.



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

def capture_query_bindings
  @capture_query_bindings
end

#capture_requestObject

Returns the value of attribute capture_request.



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

def capture_request
  @capture_request
end

#endpoint_urlObject

Returns the value of attribute endpoint_url.



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

def endpoint_url
  @endpoint_url
end

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#excluded_exceptionsObject

Returns the value of attribute excluded_exceptions.



27
28
29
# File 'lib/closeyourit/configuration.rb', line 27

def excluded_exceptions
  @excluded_exceptions
end

#filter_parametersObject

Returns the value of attribute filter_parameters.



27
28
29
# File 'lib/closeyourit/configuration.rb', line 27

def filter_parameters
  @filter_parameters
end

#max_breadcrumbsObject

Returns the value of attribute max_breadcrumbs.



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

def max_breadcrumbs
  @max_breadcrumbs
end

#obfuscate_sqlObject

Returns the value of attribute obfuscate_sql.



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

def obfuscate_sql
  @obfuscate_sql
end

#project_idObject

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

#releaseObject

Release effettiva: quella impostata, altrimenti auto-rilevata (ENV di deploy/CI o git).



105
106
107
108
109
# File 'lib/closeyourit/configuration.rb', line 105

def release
  return @release unless @release.nil?

  @release = detect_release
end

#report_active_job_errorsObject

Returns the value of attribute report_active_job_errors.



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

def report_active_job_errors
  @report_active_job_errors
end

#request_header_allowlistObject

Returns the value of attribute request_header_allowlist.



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

def request_header_allowlist
  @request_header_allowlist
end

#sample_rateObject

Returns the value of attribute sample_rate.



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

def sample_rate
  @sample_rate
end

#scrub_message_patternsObject

Returns the value of attribute scrub_message_patterns.



27
28
29
# File 'lib/closeyourit/configuration.rb', line 27

def scrub_message_patterns
  @scrub_message_patterns
end

#send_piiObject

Returns the value of attribute send_pii.



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

def send_pii
  @send_pii
end

#send_server_nameObject

Returns the value of attribute send_server_name.



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

def send_server_name
  @send_server_name
end

#slow_method_threshold_msObject

Returns the value of attribute slow_method_threshold_ms.



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

def slow_method_threshold_ms
  @slow_method_threshold_ms
end

#slow_query_threshold_msObject

Returns the value of attribute slow_query_threshold_ms.



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

def slow_query_threshold_ms
  @slow_query_threshold_ms
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#detect_releaseObject

Auto-rilevamento release dalle env di deploy/CI o dal git short SHA. Mai solleva.



112
113
114
115
116
117
118
119
120
121
# File 'lib/closeyourit/configuration.rb', line 112

def detect_release
  ENV["KAMAL_VERSION"] ||
    ENV["GIT_SHA"] ||
    ENV["GIT_REVISION"] ||
    ENV["SOURCE_VERSION"] ||
    ENV["HEROKU_SLUG_COMMIT"] ||
    git_revision
rescue StandardError
  nil
end

#enabled?Boolean

Il client invia solo con credenziali complete (endpoint + token + project_id) e trasporto sicuro (http:// ammesso fuori produzione).

Returns:

  • (Boolean)


91
92
93
94
95
96
# File 'lib/closeyourit/configuration.rb', line 91

def enabled?
  return false if blank?(endpoint_url) || blank?(token) || blank?(project_id)
  return false if insecure_endpoint? && production?

  true
end

#production?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/closeyourit/configuration.rb', line 85

def production?
  environment.to_s == "production"
end

#validate!Object

Logga i warning di configurazione (es. endpoint http://). Chiamata da ‘CloseYourIt.init`.



99
100
101
102
# File 'lib/closeyourit/configuration.rb', line 99

def validate!
  CloseYourIt.logger.warn(insecure_endpoint_message) if insecure_endpoint?
  self
end