Class: Alplus::Configuration
- Inherits:
-
Object
- Object
- Alplus::Configuration
- Defined in:
- lib/alplus/configuration.rb
Overview
Holds ingest key, endpoint, environment/release tags, and safety knobs.
The key is read from ALPLUS_KEY by default and is never logged —
#inspect/#to_s omit it deliberately (issue #14 story 11).
Constant Summary collapse
- DEFAULT_ENDPOINT =
"https://ingest.alplus.dev"
Instance Attribute Summary collapse
-
#app_dirs ⇒ Object
Returns the value of attribute app_dirs.
-
#before_send ⇒ Object
Returns the value of attribute before_send.
-
#breadcrumbs_enabled ⇒ Object
Returns the value of attribute breadcrumbs_enabled.
-
#context_lines ⇒ Object
Returns the value of attribute context_lines.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#excluded_exceptions ⇒ Object
Returns the value of attribute excluded_exceptions.
-
#key ⇒ Object
Returns the value of attribute key.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#logger_breadcrumbs_enabled ⇒ Object
Returns the value of attribute logger_breadcrumbs_enabled.
-
#max_queue_size ⇒ Object
Returns the value of attribute max_queue_size.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#post_error_log_window_ms ⇒ Object
Returns the value of attribute post_error_log_window_ms.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#release ⇒ Object
Returns the value of attribute release.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#scrub_fields ⇒ Object
Returns the value of attribute scrub_fields.
-
#sleeper ⇒ Object
Returns the value of attribute sleeper.
-
#test_mode ⇒ Object
Returns the value of attribute test_mode.
-
#transport ⇒ Object
Returns the value of attribute transport.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
(also: #to_s)
Never expose the key.
-
#resolved_post_error_log_window_ms ⇒ Object
The window
Clientactually uses: the explicit setting when given, otherwise 0 in test mode (synchronous delivery stays synchronous for every spec that does not opt in) and 2000 ms in a real process. - #sampled? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 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 71 72 73 74 75 |
# File 'lib/alplus/configuration.rb', line 26 def initialize @key = ENV["ALPLUS_KEY"] @endpoint = ENV["ALPLUS_ENDPOINT"] || DEFAULT_ENDPOINT @environment = ENV["ALPLUS_ENVIRONMENT"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "production" @release = ENV["ALPLUS_RELEASE"] @sample_rate = 1.0 @enabled = true @test_mode = false @app_dirs = [] @max_queue_size = 100 @open_timeout = 2 @read_timeout = 5 @logger = nil @transport = nil # Issue (SDK parity #1): called with the wire item hash just before # enqueue. Return a (possibly modified) hash to send it, or `nil` to # drop the event entirely. A raising callback never breaks capture -- # `Client` rescues it and sends the original item. `nil` by default # (no-op). @before_send = nil # Deep-walked (case-insensitive substring match) across # `context`/`contexts`/`tags`/`user` before `before_send` runs; a # matching value is replaced with `"[FILTERED]"`. See `Scrubber`. @scrub_fields = Scrubber::DEFAULT_SCRUB_FIELDS.dup # Exception class names (or an ancestor's) to never send at all -- # e.g. `"ActionController::RoutingError"`. Empty by default: a # non-Rails host app gets no surprise silent drops. @excluded_exceptions = [] # Lines of source before/after each in_app frame's line to attach # (`Stack`). `0` disables source-context capture entirely. @context_lines = 3 # Auto-breadcrumbs from `ActiveSupport::Notifications` (Rails only, # see `Railtie`). Ignored outside Rails. @breadcrumbs_enabled = true # Log-line breadcrumbs from an attached logger (issue #47, # `LoggerBreadcrumbs`; the Railtie attaches `Rails.logger`). @logger_breadcrumbs_enabled = true # Post-error log window in ms (issue #47): an exception item lingers # this long so log lines written just after the error (Rails' own # exception logging included) join its breadcrumb timeline, marked # `after_error`. `0` disables. `nil` (the default) resolves to 0 in # test mode -- specs that exercise the window opt in explicitly -- # and 2000 otherwise. `flush`/`close` seal pending items immediately. @post_error_log_window_ms = nil # Injection point for the default `Transport`'s retry backoff sleep # (issue #15/#16 follow-up): overridable per-`Configuration` so a # spec exercising `Alplus.capture_exception`/`.heartbeat` against a # retried response never waits on real wall-clock backoff. @sleeper = method(:sleep) end |
Instance Attribute Details
#app_dirs ⇒ Object
Returns the value of attribute app_dirs.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def app_dirs @app_dirs end |
#before_send ⇒ Object
Returns the value of attribute before_send.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def before_send @before_send end |
#breadcrumbs_enabled ⇒ Object
Returns the value of attribute breadcrumbs_enabled.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def @breadcrumbs_enabled end |
#context_lines ⇒ Object
Returns the value of attribute context_lines.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def context_lines @context_lines end |
#enabled ⇒ Object
Returns the value of attribute enabled.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def enabled @enabled end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def endpoint @endpoint end |
#environment ⇒ Object
Returns the value of attribute environment.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def environment @environment end |
#excluded_exceptions ⇒ Object
Returns the value of attribute excluded_exceptions.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def excluded_exceptions @excluded_exceptions end |
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def key @key end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def logger @logger end |
#logger_breadcrumbs_enabled ⇒ Object
Returns the value of attribute logger_breadcrumbs_enabled.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def @logger_breadcrumbs_enabled end |
#max_queue_size ⇒ Object
Returns the value of attribute max_queue_size.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def max_queue_size @max_queue_size end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def open_timeout @open_timeout end |
#post_error_log_window_ms ⇒ Object
Returns the value of attribute post_error_log_window_ms.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def post_error_log_window_ms @post_error_log_window_ms end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def read_timeout @read_timeout end |
#release ⇒ Object
Returns the value of attribute release.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def release @release end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def sample_rate @sample_rate end |
#scrub_fields ⇒ Object
Returns the value of attribute scrub_fields.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def scrub_fields @scrub_fields end |
#sleeper ⇒ Object
Returns the value of attribute sleeper.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def sleeper @sleeper end |
#test_mode ⇒ Object
Returns the value of attribute test_mode.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def test_mode @test_mode end |
#transport ⇒ Object
Returns the value of attribute transport.
10 11 12 |
# File 'lib/alplus/configuration.rb', line 10 def transport @transport end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
Never expose the key. A future maintainer adding a field here must not add it to this list without checking it isn't a secret.
87 88 89 90 |
# File 'lib/alplus/configuration.rb', line 87 def inspect "#<Alplus::Configuration endpoint=#{endpoint.inspect} environment=#{environment.inspect} " \ "release=#{release.inspect} enabled=#{enabled.inspect} test_mode=#{test_mode.inspect}>" end |
#resolved_post_error_log_window_ms ⇒ Object
The window Client actually uses: the explicit setting when given,
otherwise 0 in test mode (synchronous delivery stays synchronous for
every spec that does not opt in) and 2000 ms in a real process.
20 21 22 23 24 |
# File 'lib/alplus/configuration.rb', line 20 def resolved_post_error_log_window_ms return post_error_log_window_ms.to_i unless post_error_log_window_ms.nil? test_mode ? 0 : 2_000 end |
#sampled? ⇒ Boolean
81 82 83 |
# File 'lib/alplus/configuration.rb', line 81 def sampled? sample_rate >= 1.0 || rand < sample_rate end |
#valid? ⇒ Boolean
77 78 79 |
# File 'lib/alplus/configuration.rb', line 77 def valid? !enabled.nil? && enabled && !key.to_s.strip.empty? end |