Class: CloseYourIt::Configuration
- Inherits:
-
Object
- Object
- CloseYourIt::Configuration
- 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
-
#async_threads ⇒ Object
Returns the value of attribute async_threads.
-
#background_worker_max_queue ⇒ Object
Returns the value of attribute background_worker_max_queue.
-
#before_send ⇒ Object
Returns the value of attribute before_send.
-
#breadcrumbs_enabled ⇒ Object
Returns the value of attribute breadcrumbs_enabled.
-
#capture_external_http ⇒ Object
Returns the value of attribute capture_external_http.
-
#capture_handled_errors ⇒ Object
Returns the value of attribute capture_handled_errors.
-
#capture_method_arguments ⇒ Object
Returns the value of attribute capture_method_arguments.
-
#capture_query_bindings ⇒ Object
Returns the value of attribute capture_query_bindings.
-
#capture_rails_logs ⇒ Object
Returns the value of attribute capture_rails_logs.
-
#capture_request ⇒ Object
Returns the value of attribute capture_request.
-
#detect_performance_issues ⇒ Object
Returns the value of attribute detect_performance_issues.
-
#endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#excluded_exceptions ⇒ Object
Returns the value of attribute excluded_exceptions.
-
#filter_parameters ⇒ Object
Returns the value of attribute filter_parameters.
-
#logs_batch_size ⇒ Object
Returns the value of attribute logs_batch_size.
-
#logs_enabled ⇒ Object
Returns the value of attribute logs_enabled.
-
#logs_flush_interval ⇒ Object
Returns the value of attribute logs_flush_interval.
-
#logs_min_level ⇒ Object
Returns the value of attribute logs_min_level.
-
#logs_sample_rate ⇒ Object
Returns the value of attribute logs_sample_rate.
-
#max_breadcrumbs ⇒ Object
Returns the value of attribute max_breadcrumbs.
-
#n_plus_one_threshold ⇒ Object
Returns the value of attribute n_plus_one_threshold.
-
#obfuscate_sql ⇒ Object
Returns the value of attribute obfuscate_sql.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#query_count_threshold ⇒ Object
Returns the value of attribute query_count_threshold.
-
#query_time_threshold_ms ⇒ Object
Returns the value of attribute query_time_threshold_ms.
-
#release ⇒ Object
Release effettiva: quella impostata, altrimenti auto-rilevata (ENV di deploy/CI o git).
-
#report_active_job_errors ⇒ Object
Returns the value of attribute report_active_job_errors.
-
#request_header_allowlist ⇒ Object
Returns the value of attribute request_header_allowlist.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#scrub_message_patterns ⇒ Object
Returns the value of attribute scrub_message_patterns.
-
#send_pii ⇒ Object
Returns the value of attribute send_pii.
-
#send_server_name ⇒ Object
Returns the value of attribute send_server_name.
-
#slow_external_threshold_ms ⇒ Object
Returns the value of attribute slow_external_threshold_ms.
-
#slow_method_threshold_ms ⇒ Object
Returns the value of attribute slow_method_threshold_ms.
-
#slow_query_threshold_ms ⇒ Object
Returns the value of attribute slow_query_threshold_ms.
-
#slow_request_threshold_ms ⇒ Object
Returns the value of attribute slow_request_threshold_ms.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#detect_release ⇒ Object
Auto-rilevamento release dalle env di deploy/CI o dal git short SHA.
-
#enabled? ⇒ Boolean
Il client invia solo con credenziali complete (endpoint + token + project_id) e trasporto sicuro (http:// ammesso fuori produzione).
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #production? ⇒ Boolean
-
#validate! ⇒ Object
Logga i warning di configurazione (es. endpoint http://, project_id/endpoint malformati).
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/closeyourit/configuration.rb', line 34 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 # Log strutturati (CloseYourIt.log / .logger). Master switch + sampling + batching dedicati. @logs_enabled = true @logs_sample_rate = 1.0 @logs_batch_size = 50 @logs_flush_interval = 5 # Broadcast opt-in di Rails.logger → CloseYourIt.log (default OFF; spedisce solo ≥ soglia). @capture_rails_logs = false @logs_min_level = :info # Performance issue detection (verdetti aggregati: N+1, slow request, HTTP esterne lente). # OPT-IN, default OFF: profila OGNI query della richiesta → overhead non trascurabile, va attivato # consapevolmente per-app. Le soglie sono conservative (poco rumore). Vedi Performance::Rollup. @detect_performance_issues = false @n_plus_one_threshold = 10 # stesso fingerprint+call-site eseguito > N volte in una richiesta @query_count_threshold = 100 # troppe query totali in una richiesta @query_time_threshold_ms = 500 # tempo DB totale per richiesta oltre cui = high_query_count @slow_request_threshold_ms = 1000 # durata totale della richiesta @slow_external_threshold_ms = 1000 # singola chiamata HTTP esterna @capture_external_http = true # strumenta Net::HTTP (solo se detect_performance_issues) @filter_parameters = [] @scrub_message_patterns = [] end |
Instance Attribute Details
#async_threads ⇒ Object
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_queue ⇒ Object
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_send ⇒ Object
Returns the value of attribute before_send.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def before_send @before_send end |
#breadcrumbs_enabled ⇒ Object
Returns the value of attribute breadcrumbs_enabled.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def @breadcrumbs_enabled end |
#capture_external_http ⇒ Object
Returns the value of attribute capture_external_http.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def capture_external_http @capture_external_http end |
#capture_handled_errors ⇒ Object
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_arguments ⇒ Object
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_bindings ⇒ Object
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_rails_logs ⇒ Object
Returns the value of attribute capture_rails_logs.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def capture_rails_logs @capture_rails_logs end |
#capture_request ⇒ Object
Returns the value of attribute capture_request.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def capture_request @capture_request end |
#detect_performance_issues ⇒ Object
Returns the value of attribute detect_performance_issues.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def detect_performance_issues @detect_performance_issues end |
#endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def endpoint_url @endpoint_url end |
#environment ⇒ Object
Returns the value of attribute environment.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def environment @environment end |
#excluded_exceptions ⇒ Object
Returns the value of attribute excluded_exceptions.
32 33 34 |
# File 'lib/closeyourit/configuration.rb', line 32 def excluded_exceptions @excluded_exceptions end |
#filter_parameters ⇒ Object
Returns the value of attribute filter_parameters.
32 33 34 |
# File 'lib/closeyourit/configuration.rb', line 32 def filter_parameters @filter_parameters end |
#logs_batch_size ⇒ Object
Returns the value of attribute logs_batch_size.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def logs_batch_size @logs_batch_size end |
#logs_enabled ⇒ Object
Returns the value of attribute logs_enabled.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def logs_enabled @logs_enabled end |
#logs_flush_interval ⇒ Object
Returns the value of attribute logs_flush_interval.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def logs_flush_interval @logs_flush_interval end |
#logs_min_level ⇒ Object
Returns the value of attribute logs_min_level.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def logs_min_level @logs_min_level end |
#logs_sample_rate ⇒ Object
Returns the value of attribute logs_sample_rate.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def logs_sample_rate @logs_sample_rate end |
#max_breadcrumbs ⇒ Object
Returns the value of attribute max_breadcrumbs.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def @max_breadcrumbs end |
#n_plus_one_threshold ⇒ Object
Returns the value of attribute n_plus_one_threshold.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def n_plus_one_threshold @n_plus_one_threshold end |
#obfuscate_sql ⇒ Object
Returns the value of attribute obfuscate_sql.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def obfuscate_sql @obfuscate_sql end |
#project_id ⇒ Object
Returns the value of attribute project_id.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def project_id @project_id end |
#query_count_threshold ⇒ Object
Returns the value of attribute query_count_threshold.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def query_count_threshold @query_count_threshold end |
#query_time_threshold_ms ⇒ Object
Returns the value of attribute query_time_threshold_ms.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def query_time_threshold_ms @query_time_threshold_ms end |
#release ⇒ Object
Release effettiva: quella impostata, altrimenti auto-rilevata (ENV di deploy/CI o git).
133 134 135 136 137 |
# File 'lib/closeyourit/configuration.rb', line 133 def release return @release unless @release.nil? @release = detect_release end |
#report_active_job_errors ⇒ Object
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_allowlist ⇒ Object
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_rate ⇒ Object
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_patterns ⇒ Object
Returns the value of attribute scrub_message_patterns.
32 33 34 |
# File 'lib/closeyourit/configuration.rb', line 32 def @scrub_message_patterns end |
#send_pii ⇒ Object
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_name ⇒ Object
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_external_threshold_ms ⇒ Object
Returns the value of attribute slow_external_threshold_ms.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def slow_external_threshold_ms @slow_external_threshold_ms end |
#slow_method_threshold_ms ⇒ Object
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_ms ⇒ Object
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 |
#slow_request_threshold_ms ⇒ Object
Returns the value of attribute slow_request_threshold_ms.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def slow_request_threshold_ms @slow_request_threshold_ms end |
#token ⇒ Object
Returns the value of attribute token.
18 19 20 |
# File 'lib/closeyourit/configuration.rb', line 18 def token @token end |
Instance Method Details
#detect_release ⇒ Object
Auto-rilevamento release dalle env di deploy/CI o dal git short SHA. Mai solleva.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/closeyourit/configuration.rb', line 140 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).
116 117 118 119 120 121 |
# File 'lib/closeyourit/configuration.rb', line 116 def enabled? return false if blank?(endpoint_url) || blank?(token) || blank?(project_id) return false if insecure_endpoint? && production? true end |
#production? ⇒ Boolean
110 111 112 |
# File 'lib/closeyourit/configuration.rb', line 110 def production? environment.to_s == "production" end |
#validate! ⇒ Object
Logga i warning di configurazione (es. endpoint http://, project_id/endpoint malformati).
Non solleva mai: coerente con la filosofia no-op del client. Chiamata da CloseYourIt.init.
125 126 127 128 129 130 |
# File 'lib/closeyourit/configuration.rb', line 125 def validate! CloseYourIt.internal_logger.warn() if insecure_endpoint? CloseYourIt.internal_logger.warn() if malformed_project_id? CloseYourIt.internal_logger.warn() if malformed_endpoint? self end |