Skip to content

Commit

Permalink
feat: Add support for $SENTRY_DEBUG and $SENTRY_SPOTLIGHT
Browse files Browse the repository at this point in the history
Part of getsentry/spotlight#482. Similar to sentry-python#3443 but it also adds support for `$SENTRY_DEBUG` which was lacking in the Ruby SDK.
  • Loading branch information
Burak Yigit Kaya committed Aug 15, 2024
1 parent fa0973a commit a9334bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Configuration
include CustomInspection
include LoggingHelper
include ArgumentCheckingHelper
include EnvHelper

# Directories to be recognized as part of your app. e.g. if you
# have an `engines` dir at the root of your project, you may want
Expand Down Expand Up @@ -350,7 +351,7 @@ def add_post_initialization_callback(&block)

def initialize
self.app_dirs_pattern = nil
self.debug = false
self.debug = env_to_bool(ENV["SENTRY_DEBUG"])
self.background_worker_threads = (processor_count / 2.0).ceil
self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE
self.backtrace_cleanup_callback = nil
Expand All @@ -377,7 +378,10 @@ def initialize
self.enable_backpressure_handling = false
self.trusted_proxies = []
self.dsn = ENV['SENTRY_DSN']
self.spotlight = false

spotlight_env = ENV['SENTRY_SPOTLIGHT']
spotlight_bool = env_to_bool(spotlight_env, true)
self.spotlight = spotlight_bool.ni? ? spotlight_env : spotlight_bool
self.server_name = server_name_from_env
self.instrumenter = :sentry
self.trace_propagation_targets = [PROPAGATION_TARGETS_MATCH_ALL]
Expand Down
23 changes: 23 additions & 0 deletions sentry-ruby/lib/sentry/utils/env_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Sentry
module EnvHelper
TRUTHY_ENV_VALUES = %w(t true yes y 1 on).freeze
FALSY_ENV_VALUES = %w(f false no n 0 off).freeze

def env_to_bool(value, strict=false)
value = value.to_s
normalized = value.downcase

if FALSY_ENV_VALUES.include?(normalized)
return false
end

if TRUTHY_ENV_VALUES.include?(normalized)
return true
end

return strict ? nil : !(value.nil? || value.empty?)
end
end
end

0 comments on commit a9334bf

Please sign in to comment.