Class: AllStak::Config
- Inherits:
-
Object
- Object
- AllStak::Config
- Defined in:
- lib/allstak/config.rb
Overview
SDK configuration. Populated via configure.
Constant Summary collapse
- SDK_NAME =
"allstak-ruby"- SDK_VERSION =
Single source of truth: keep the wire ‘sdk.version` in lockstep with the gem version declared in version.rb.
AllStak::VERSION
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#auto_detect_release ⇒ Object
Returns the value of attribute auto_detect_release.
-
#auto_register_release ⇒ Object
Returns the value of attribute auto_register_release.
-
#before_send ⇒ Object
Returns the value of attribute before_send.
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#buffer_size ⇒ Object
Returns the value of attribute buffer_size.
-
#capture_http_requests ⇒ Object
Returns the value of attribute capture_http_requests.
-
#capture_sql ⇒ Object
Returns the value of attribute capture_sql.
-
#capture_unhandled_exceptions ⇒ Object
Returns the value of attribute capture_unhandled_exceptions.
-
#capture_user_context ⇒ Object
Returns the value of attribute capture_user_context.
-
#commit_sha ⇒ Object
Returns the value of attribute commit_sha.
-
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#dist ⇒ Object
Returns the value of attribute dist.
-
#enable_auto_session_tracking ⇒ Object
Returns the value of attribute enable_auto_session_tracking.
-
#enable_offline_queue ⇒ Object
Returns the value of attribute enable_offline_queue.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#extra_denylist ⇒ Object
Returns the value of attribute extra_denylist.
-
#flush_interval_ms ⇒ Object
Returns the value of attribute flush_interval_ms.
-
#host ⇒ Object
Returns the value of attribute host.
-
#install_at_exit_handler ⇒ Object
Returns the value of attribute install_at_exit_handler.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#offline_queue_dir ⇒ Object
Returns the value of attribute offline_queue_dir.
-
#offline_queue_max_age_s ⇒ Object
Returns the value of attribute offline_queue_max_age_s.
-
#offline_queue_max_bytes ⇒ Object
Returns the value of attribute offline_queue_max_bytes.
-
#offline_queue_max_entries ⇒ Object
Returns the value of attribute offline_queue_max_entries.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#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.
-
#sdk_name ⇒ Object
Returns the value of attribute sdk_name.
-
#sdk_version ⇒ Object
Returns the value of attribute sdk_version.
-
#send_default_pii ⇒ Object
Returns the value of attribute send_default_pii.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#traces_sample_rate ⇒ Object
Returns the value of attribute traces_sample_rate.
Class Method Summary collapse
-
.cached_git_release ⇒ Object
Resolve the git-derived release once per process and cache it.
-
.reset_git_release_cache! ⇒ Object
Test seam: reset the cache between examples.
-
.seed_git_release_cache!(value) ⇒ Object
Test seam: pre-seed the resolved git release so #finalize_release! can be exercised without shelling out to a real repo.
Instance Method Summary collapse
-
#finalize_release! ⇒ Object
Resolve the release after explicit user config has been applied (called from configure once the user’s block has run).
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#release_tags ⇒ Object
Release-tracking tags merged into every event payload’s metadata.
-
#send_default_pii? ⇒ Boolean
Idiomatic predicate for the PII toggle (coerces truthy config values).
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/allstak/config.rb', line 179 def initialize @api_key = ENV["ALLSTAK_API_KEY"].to_s @host = ENV["ALLSTAK_HOST"] || "https://api.allstak.sa" @environment = ENV["ALLSTAK_ENVIRONMENT"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "production" # 1. explicit release is set via AllStak.configure after initialize. # 2. env-var detection (unchanged). @release = ENV["ALLSTAK_RELEASE"] || ENV["VERCEL_GIT_COMMIT_SHA"]&.slice(0, 12) || ENV["RAILWAY_GIT_COMMIT_SHA"]&.slice(0, 12) || ENV["RENDER_GIT_COMMIT"]&.slice(0, 12) @auto_detect_release = true @auto_register_release = true @enable_auto_session_tracking = true # Offline/persistent event queue: default ON for server runtimes; nil dir # → <tmpdir>/allstak-spool. nil bound knobs fall back to EventSpool # defaults. Honors ALLSTAK_OFFLINE_QUEUE=0/false and ALLSTAK_OFFLINE_QUEUE_DIR. @enable_offline_queue = !%w[0 false no off].include?(ENV["ALLSTAK_OFFLINE_QUEUE"].to_s.strip.downcase) @offline_queue_dir = ENV["ALLSTAK_OFFLINE_QUEUE_DIR"] @offline_queue_max_entries = nil @offline_queue_max_bytes = nil @offline_queue_max_age_s = nil # Sentry parity: default FALSE. Opt in via ALLSTAK_SEND_DEFAULT_PII. @send_default_pii = %w[1 true yes on].include?(ENV["ALLSTAK_SEND_DEFAULT_PII"].to_s.strip.downcase) @extra_denylist = parse_extra_denylist(ENV["ALLSTAK_EXTRA_DENYLIST"]) @service_name = ENV["ALLSTAK_SERVICE"] || "ruby-service" @flush_interval_ms = 2_000 @buffer_size = 500 @debug = !ENV["ALLSTAK_DEBUG"].to_s.empty? @connect_timeout = 3 @read_timeout = 3 @max_retries = 5 @capture_unhandled_exceptions = true @capture_http_requests = true @capture_user_context = true @capture_sql = true @install_at_exit_handler = true @before_send = nil @sample_rate = 1.0 @traces_sample_rate = nil # Release metadata @platform = "ruby" @sdk_name = SDK_NAME @sdk_version = SDK_VERSION @commit_sha = ENV["ALLSTAK_COMMIT_SHA"] || ENV["GIT_COMMIT"] || ENV["VERCEL_GIT_COMMIT_SHA"] || ENV["RAILWAY_GIT_COMMIT_SHA"] || ENV["RENDER_GIT_COMMIT"] @branch = ENV["ALLSTAK_BRANCH"] || ENV["GIT_BRANCH"] || ENV["VERCEL_GIT_COMMIT_REF"] || ENV["RAILWAY_GIT_BRANCH"] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def api_key @api_key end |
#auto_detect_release ⇒ Object
Returns the value of attribute auto_detect_release.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def auto_detect_release @auto_detect_release end |
#auto_register_release ⇒ Object
Returns the value of attribute auto_register_release.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def auto_register_release @auto_register_release end |
#before_send ⇒ Object
Returns the value of attribute before_send.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def before_send @before_send end |
#branch ⇒ Object
Returns the value of attribute branch.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def branch @branch end |
#buffer_size ⇒ Object
Returns the value of attribute buffer_size.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def buffer_size @buffer_size end |
#capture_http_requests ⇒ Object
Returns the value of attribute capture_http_requests.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def capture_http_requests @capture_http_requests end |
#capture_sql ⇒ Object
Returns the value of attribute capture_sql.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def capture_sql @capture_sql end |
#capture_unhandled_exceptions ⇒ Object
Returns the value of attribute capture_unhandled_exceptions.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def capture_unhandled_exceptions @capture_unhandled_exceptions end |
#capture_user_context ⇒ Object
Returns the value of attribute capture_user_context.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def capture_user_context @capture_user_context end |
#commit_sha ⇒ Object
Returns the value of attribute commit_sha.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def commit_sha @commit_sha end |
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def connect_timeout @connect_timeout end |
#debug ⇒ Object
Returns the value of attribute debug.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def debug @debug end |
#dist ⇒ Object
Returns the value of attribute dist.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def dist @dist end |
#enable_auto_session_tracking ⇒ Object
Returns the value of attribute enable_auto_session_tracking.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def enable_auto_session_tracking @enable_auto_session_tracking end |
#enable_offline_queue ⇒ Object
Returns the value of attribute enable_offline_queue.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def enable_offline_queue @enable_offline_queue end |
#environment ⇒ Object
Returns the value of attribute environment.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def environment @environment end |
#extra_denylist ⇒ Object
Returns the value of attribute extra_denylist.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def extra_denylist @extra_denylist end |
#flush_interval_ms ⇒ Object
Returns the value of attribute flush_interval_ms.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def flush_interval_ms @flush_interval_ms end |
#host ⇒ Object
Returns the value of attribute host.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def host @host end |
#install_at_exit_handler ⇒ Object
Returns the value of attribute install_at_exit_handler.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def install_at_exit_handler @install_at_exit_handler end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def max_retries @max_retries end |
#offline_queue_dir ⇒ Object
Returns the value of attribute offline_queue_dir.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def offline_queue_dir @offline_queue_dir end |
#offline_queue_max_age_s ⇒ Object
Returns the value of attribute offline_queue_max_age_s.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def offline_queue_max_age_s @offline_queue_max_age_s end |
#offline_queue_max_bytes ⇒ Object
Returns the value of attribute offline_queue_max_bytes.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def offline_queue_max_bytes @offline_queue_max_bytes end |
#offline_queue_max_entries ⇒ Object
Returns the value of attribute offline_queue_max_entries.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def offline_queue_max_entries @offline_queue_max_entries end |
#platform ⇒ Object
Returns the value of attribute platform.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def platform @platform end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def read_timeout @read_timeout end |
#release ⇒ Object
Returns the value of attribute release.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def release @release end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def sample_rate @sample_rate end |
#sdk_name ⇒ Object
Returns the value of attribute sdk_name.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def sdk_name @sdk_name end |
#sdk_version ⇒ Object
Returns the value of attribute sdk_version.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def sdk_version @sdk_version end |
#send_default_pii ⇒ Object
Returns the value of attribute send_default_pii.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def send_default_pii @send_default_pii end |
#service_name ⇒ Object
Returns the value of attribute service_name.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def service_name @service_name end |
#traces_sample_rate ⇒ Object
Returns the value of attribute traces_sample_rate.
71 72 73 |
# File 'lib/allstak/config.rb', line 71 def traces_sample_rate @traces_sample_rate end |
Class Method Details
.cached_git_release ⇒ Object
Resolve the git-derived release once per process and cache it.
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/allstak/config.rb', line 153 def cached_git_release return @git_release_cache if @git_release_resolved @git_release_resolved = true @git_release_cache = begin GitRelease.detect_release rescue StandardError nil end end |
.reset_git_release_cache! ⇒ Object
Test seam: reset the cache between examples.
166 167 168 169 |
# File 'lib/allstak/config.rb', line 166 def reset_git_release_cache! @git_release_resolved = false @git_release_cache = nil end |
.seed_git_release_cache!(value) ⇒ Object
Test seam: pre-seed the resolved git release so #finalize_release! can be exercised without shelling out to a real repo.
173 174 175 176 |
# File 'lib/allstak/config.rb', line 173 def seed_git_release_cache!(value) @git_release_resolved = true @git_release_cache = value end |
Instance Method Details
#finalize_release! ⇒ Object
Resolve the release after explicit user config has been applied (called from AllStak.configure once the user’s block has run). Resolution order:
1. explicit @release (set by the user) — kept as-is.
2. release env var — already applied in #initialize.
3. local git (cached, guarded) when auto_detect_release.
4. SDK version constant when auto_detect_release.
Never raises and never overwrites a non-empty release.
235 236 237 238 239 240 241 242 |
# File 'lib/allstak/config.rb', line 235 def finalize_release! return self unless @release.nil? || @release.to_s.empty? return self unless @auto_detect_release @release = AllStak::Config.cached_git_release @release = SDK_VERSION if @release.nil? || @release.to_s.empty? self end |
#release_tags ⇒ Object
Release-tracking tags merged into every event payload’s metadata.
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/allstak/config.rb', line 245 def = {} ["sdk.name"] = @sdk_name if @sdk_name ["sdk.version"] = @sdk_version if @sdk_version ["platform"] = @platform if @platform ["dist"] = @dist if @dist ["commit.sha"] = @commit_sha if @commit_sha ["commit.branch"] = @branch if @branch end |
#send_default_pii? ⇒ Boolean
Idiomatic predicate for the PII toggle (coerces truthy config values).
261 262 263 |
# File 'lib/allstak/config.rb', line 261 def send_default_pii? @send_default_pii ? true : false end |
#valid? ⇒ Boolean
256 257 258 |
# File 'lib/allstak/config.rb', line 256 def valid? !@api_key.to_s.empty? end |