Class: LogBrew::Rails::Configuration
- Inherits:
-
Object
- Object
- LogBrew::Rails::Configuration
- Defined in:
- lib/logbrew/rails_integration.rb
Overview
Immutable, environment-derived settings for the automatic Rails adapter.
Constant Summary collapse
- DEFAULT_ENDPOINT =
LogBrew::HttpTransport::DEFAULT_ENDPOINT
- DEFAULT_REQUEST_TIMEOUT_MS =
10_000- DEFAULT_FLUSH_INTERVAL_MS =
5_000- DEFAULT_FLUSH_THRESHOLD =
100- MAX_LABEL_BYTES =
255- MAX_ENDPOINT_BYTES =
2_048- LOOPBACK_HOSTS =
%w[localhost 127.0.0.1 ::1 [::1]].freeze
Class Method Summary collapse
- .disabled(application_name, rails_environment, rails_version) ⇒ Object
- .from_environment(environment, application_name:, rails_environment:, rails_version:) ⇒ Object
Instance Method Summary collapse
- #capture_exception_messages? ⇒ Boolean
- #capture_rails_logs? ⇒ Boolean
- #enabled? ⇒ Boolean
- #include_exception_backtrace? ⇒ Boolean
-
#initialize(**attributes) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(**attributes) ⇒ Configuration
Returns a new instance of Configuration.
204 205 206 207 208 209 210 |
# File 'lib/logbrew/rails_integration.rb', line 204 def initialize(**attributes) raise ArgumentError, "Rails configuration attributes do not match" unless attributes.keys.sort == ATTRIBUTES.sort ATTRIBUTES.each { |name| instance_variable_set("@#{name}", attributes.fetch(name)) } @api_key = @api_key&.dup&.freeze freeze end |
Class Method Details
.disabled(application_name, rails_environment, rails_version) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/logbrew/rails_integration.rb', line 100 def self.disabled(application_name, rails_environment, rails_version) new( enabled: false, api_key: nil, service_name: bounded_label(application_name, "Rails application name"), app_environment: bounded_label(rails_environment, "Rails environment"), rails_version: bounded_label(rails_version, "Rails version"), release: nil, endpoint: DEFAULT_ENDPOINT, request_timeout: DEFAULT_REQUEST_TIMEOUT_MS / 1_000.0, flush_interval: DEFAULT_FLUSH_INTERVAL_MS / 1_000.0, flush_threshold: DEFAULT_FLUSH_THRESHOLD, capture_exception_messages: false, capture_rails_logs: false, include_exception_backtrace: false ) end |
.from_environment(environment, application_name:, rails_environment:, rails_version:) ⇒ Object
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/logbrew/rails_integration.rb', line 29 def self.from_environment(environment, application_name:, rails_environment:, rails_version:) unless environment.respond_to?(:[]) && environment.respond_to?(:key?) raise SdkError.new("configuration_error", "Rails environment must provide key lookup") end enabled_setting = boolean_value(environment, "LOGBREW_ENABLED", nil) return disabled(application_name, rails_environment, rails_version) if enabled_setting == false canonical_key = server_key_value(environment["LOGBREW_SERVER_API_KEY"]) if canonical_key.nil? legacy_present = %w[LOGBREW_API_KEY LOGBREW_INGEST_KEY].any? do |name| !optional_text(environment[name]).nil? end if enabled_setting == true || legacy_present || environment.key?("LOGBREW_SERVER_API_KEY") raise SdkError.new( "configuration_error", "set LOGBREW_SERVER_API_KEY to a non-empty server API key, or set LOGBREW_ENABLED=false" ) end return disabled(application_name, rails_environment, rails_version) end new( enabled: true, api_key: canonical_key, service_name: bounded_label( optional_text(environment["LOGBREW_SERVICE_NAME"]) || application_name, "LOGBREW_SERVICE_NAME" ), app_environment: bounded_label( optional_text(environment["LOGBREW_ENVIRONMENT"]) || rails_environment, "LOGBREW_ENVIRONMENT" ), rails_version: bounded_label(rails_version, "Rails version"), release: optional_bounded_label(environment["LOGBREW_RELEASE"], "LOGBREW_RELEASE"), endpoint: endpoint_value(environment["LOGBREW_ENDPOINT"]), request_timeout: integer_value( environment, "LOGBREW_REQUEST_TIMEOUT_MS", DEFAULT_REQUEST_TIMEOUT_MS, 1, 600_000 ) / 1_000.0, flush_interval: integer_value( environment, "LOGBREW_FLUSH_INTERVAL_MS", DEFAULT_FLUSH_INTERVAL_MS, 10, 3_600_000 ) / 1_000.0, flush_threshold: integer_value( environment, "LOGBREW_FLUSH_THRESHOLD", DEFAULT_FLUSH_THRESHOLD, 1, 1_000 ), capture_exception_messages: boolean_value( environment, "LOGBREW_CAPTURE_EXCEPTION_MESSAGES", false ), capture_rails_logs: boolean_value(environment, "LOGBREW_CAPTURE_RAILS_LOGS", false), include_exception_backtrace: boolean_value( environment, "LOGBREW_INCLUDE_EXCEPTION_BACKTRACE", false ) ) end |
Instance Method Details
#capture_exception_messages? ⇒ Boolean
216 217 218 |
# File 'lib/logbrew/rails_integration.rb', line 216 def @capture_exception_messages end |
#capture_rails_logs? ⇒ Boolean
220 221 222 |
# File 'lib/logbrew/rails_integration.rb', line 220 def capture_rails_logs? @capture_rails_logs end |
#enabled? ⇒ Boolean
212 213 214 |
# File 'lib/logbrew/rails_integration.rb', line 212 def enabled? @enabled end |
#include_exception_backtrace? ⇒ Boolean
224 225 226 |
# File 'lib/logbrew/rails_integration.rb', line 224 def include_exception_backtrace? @include_exception_backtrace end |