Class: Beacon::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/beacon/configuration.rb', line 11

def initialize
  @endpoint        = ENV["BEACON_ENDPOINT"] || "http://127.0.0.1:4680"
  @environment     = ENV["BEACON_ENVIRONMENT"] || ENV["RAILS_ENV"] || "development"
  @deploy_sha      = ENV["GIT_SHA"] || ENV["KAMAL_VERSION"]
  @auth_token      = ENV["BEACON_AUTH_TOKEN"]
  @async           = true
  @app_root        = Dir.pwd
  @pillars         = %i[outcomes perf errors]
  @flush_interval  = 1.0
  @flush_threshold = 100
  @queue_size      = 10_000
  @connect_timeout = 1.0
  @read_timeout    = 2.0
  # Shared cap for the middleware's LRU caches (per-request path
  # name cache and per-fingerprint stack-throttle cache). One knob
  # because both caches sit on the same Middleware instance, both
  # are bounded for the same reason (protect against high-cardinality
  # probes), and there is no realistic scenario where one should be
  # tuned independently of the other.
  @cache_size = 1024

  # Ambient mode: when true, middleware sends kind: 'ambient' events
  # for HTTP requests in addition to perf events.
  @ambient = false

  # Enrichment block: called on every request to provide dimensions
  # (country, plan, locale, etc.) that flow to all event kinds.
  @enrich_context_block = nil

  # Global kill switch. When false, Beacon::Middleware is a
  # passthrough, Beacon.track returns nil, and the flusher thread
  # is not started.
  #
  # Default resolution (in priority order):
  #   1. BEACON_DISABLED explicitly set → honored in both directions.
  #        "1" / "true" / "yes" / "on"   → disabled
  #        "0" / "false" / "no" / "off"  → forced enabled
  #   2. RAILS_ENV / RACK_ENV is "test" → disabled.
  #   3. Otherwise → enabled (development, staging, production).
  #
  # The test-env default matches Honeybadger/Sentry/AppSignal: an
  # observability gem should not chatter across a hermetic test
  # suite by default. A test that WANTS to assert Beacon was called
  # (via Beacon::Testing::FakeTransport) opts back in locally, or
  # sets BEACON_DISABLED=0 for the whole run.
  @enabled = default_enabled
end

Instance Attribute Details

#ambientObject

Returns the value of attribute ambient.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def ambient
  @ambient
end

#app_rootObject

Returns the value of attribute app_root.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def app_root
  @app_root
end

#asyncObject

Returns the value of attribute async.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def async
  @async
end

#auth_tokenObject

Returns the value of attribute auth_token.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def auth_token
  @auth_token
end

#cache_sizeObject

Returns the value of attribute cache_size.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def cache_size
  @cache_size
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def connect_timeout
  @connect_timeout
end

#deploy_shaObject

Returns the value of attribute deploy_sha.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def deploy_sha
  @deploy_sha
end

#enabledObject

Returns the value of attribute enabled.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def enabled
  @enabled
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def endpoint
  @endpoint
end

#environmentObject

Returns the value of attribute environment.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def environment
  @environment
end

#flush_intervalObject

Returns the value of attribute flush_interval.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def flush_interval
  @flush_interval
end

#flush_thresholdObject

Returns the value of attribute flush_threshold.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def flush_threshold
  @flush_threshold
end

#pillarsObject

Returns the value of attribute pillars.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def pillars
  @pillars
end

#queue_sizeObject

Returns the value of attribute queue_size.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def queue_size
  @queue_size
end

#read_timeoutObject

Returns the value of attribute read_timeout.



5
6
7
# File 'lib/beacon/configuration.rb', line 5

def read_timeout
  @read_timeout
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/beacon/configuration.rb', line 59

def enabled?
  @enabled && endpoint_usable?
end

#enrich_context(&block) ⇒ Object

Register or read the enrichment block. With a block: registers it. Without: returns the current block (or nil). The block receives a Rack request and returns a Hash of dimensions (e.g. { country: “US” }).



70
71
72
73
74
75
76
# File 'lib/beacon/configuration.rb', line 70

def enrich_context(&block)
  if block
    @enrich_context_block = block
  else
    @enrich_context_block
  end
end

#pillar?(name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/beacon/configuration.rb', line 63

def pillar?(name)
  @pillars.include?(name)
end