Class: Sixty::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sixty/config.rb

Overview

Configuration, under both names.

The product is called sixty, so its variables are SIXTY_*. They used to be DRIFT_*, and that name is not ours to retire: it is set in other people's deployments — a Dockerfile, a Fly secret, a CI job someone configured once and has not thought about since. Renaming without reading the old name would not produce an error anybody could act on. It would produce an agent that starts cleanly, finds no key, and reports nothing, in exactly the silence this product exists to eliminate.

Nothing here warns when the old name is used. A warning would fire on every boot of a correctly configured service that simply predates the rename, which teaches people to filter our log lines out.

Constant Summary collapse

ATTRIBUTES =
%i[
  api_key endpoint service environment release repo_url
  flush_interval sample_rate slow_trace_ms capture_plans
  instrument ignore_paths debug on_warn logger
].freeze
RELEASE_VARS =

Most PaaS providers set one of these without the user doing anything, and release attribution is what makes deploy-anchored detection possible — so the agent tries hard to find one before giving up. Without a release, two deploys are one undifferentiated stream and nothing can be compared against anything.

%w[
  HEROKU_SLUG_COMMIT RENDER_GIT_COMMIT RAILWAY_GIT_COMMIT_SHA
  GITHUB_SHA FLY_MACHINE_VERSION SOURCE_VERSION VERCEL_GIT_COMMIT_SHA
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



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
# File 'lib/sixty/config.rb', line 36

def initialize(options = {})
  @api_key = options[:api_key] || env('API_KEY')
  @endpoint = options[:endpoint] || env('ENDPOINT') || 'http://localhost:4319'
  @service = options[:service] || env('SERVICE') || infer_service
  @environment = options[:environment] || env('ENV') || rails_env || 'development'
  @release = options[:release] || env('RELEASE') || detect_release || ''
  @repo_url = options[:repo_url] || env('REPO_URL') || github_repo_url || ''
  # Seconds when passed in code, milliseconds in the environment — because
  # `SIXTY_FLUSH_MS` is the name every other agent in this repository reads,
  # and a Ruby app and a Node app sharing a compose file must not need two
  # spellings of the same knob.
  @flush_interval = options[:flush_interval] || (env_number('FLUSH_MS', 15_000) / 1000.0)
  @sample_rate = options[:sample_rate] || env_number('SAMPLE_RATE', 0.05)
  @slow_trace_ms = options[:slow_trace_ms] || env_number('SLOW_TRACE_MS', 1000)
  @capture_plans = options.fetch(:capture_plans, env('CAPTURE_PLANS') != '0')
  # Which database clients to measure. nil means "decide from what is in the
  # process" — see Sixty.install_database_instrumentation, which is where
  # the ActiveRecord-versus-raw-driver choice is made and explained.
  @instrument = options[:instrument] || env_list('INSTRUMENT')
  # Health checks and asset requests are noise: they are not the
  # application, and left in they dominate the operation list of every
  # service behind a load balancer.
  @ignore_paths = options[:ignore_paths] || [
    %r{\A/assets/}, %r{\A/packs/}, %r{\A/rails/active_storage/},
    %r{\A/health}, %r{\A/up\z}, /favicon\.ico\z/
  ]
  @debug = options.fetch(:debug, env('DEBUG') == '1')
  @logger = options[:logger] || rails_logger
  @on_warn = options[:on_warn] || default_warn
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/sixty/config.rb', line 67

def active?
  !api_key.to_s.empty?
end

#ignore?(path) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/sixty/config.rb', line 71

def ignore?(path)
  ignore_paths.any? { |pattern| pattern.match?(path) }
end