Class: Alplus::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_dirsObject

Returns the value of attribute app_dirs.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def app_dirs
  @app_dirs
end

#before_sendObject

Returns the value of attribute before_send.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def before_send
  @before_send
end

Returns the value of attribute breadcrumbs_enabled.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def breadcrumbs_enabled
  @breadcrumbs_enabled
end

#context_linesObject

Returns the value of attribute context_lines.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def context_lines
  @context_lines
end

#enabledObject

Returns the value of attribute enabled.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def enabled
  @enabled
end

#endpointObject

Returns the value of attribute endpoint.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def endpoint
  @endpoint
end

#environmentObject

Returns the value of attribute environment.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def environment
  @environment
end

#excluded_exceptionsObject

Returns the value of attribute excluded_exceptions.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def excluded_exceptions
  @excluded_exceptions
end

#keyObject

Returns the value of attribute key.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def key
  @key
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def logger
  @logger
end

#logger_breadcrumbs_enabledObject

Returns the value of attribute logger_breadcrumbs_enabled.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def logger_breadcrumbs_enabled
  @logger_breadcrumbs_enabled
end

#max_queue_sizeObject

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_timeoutObject

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_msObject

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_timeoutObject

Returns the value of attribute read_timeout.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def read_timeout
  @read_timeout
end

#releaseObject

Returns the value of attribute release.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def release
  @release
end

#sample_rateObject

Returns the value of attribute sample_rate.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def sample_rate
  @sample_rate
end

#scrub_fieldsObject

Returns the value of attribute scrub_fields.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def scrub_fields
  @scrub_fields
end

#sleeperObject

Returns the value of attribute sleeper.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def sleeper
  @sleeper
end

#test_modeObject

Returns the value of attribute test_mode.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def test_mode
  @test_mode
end

#transportObject

Returns the value of attribute transport.



10
11
12
# File 'lib/alplus/configuration.rb', line 10

def transport
  @transport
end

Instance Method Details

#inspectObject 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_msObject

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

Returns:

  • (Boolean)


81
82
83
# File 'lib/alplus/configuration.rb', line 81

def sampled?
  sample_rate >= 1.0 || rand < sample_rate
end

#valid?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/alplus/configuration.rb', line 77

def valid?
  !enabled.nil? && enabled && !key.to_s.strip.empty?
end