Class: Sentry::Configuration
Constant Summary collapse
- IGNORE_DEFAULT =
Most of these errors generate 4XX responses. In general, Sentry clients only automatically report 5xx responses.
[ 'Mongoid::Errors::DocumentNotFound', 'Rack::QueryParser::InvalidParameterError', 'Rack::QueryParser::ParameterTypeError', 'Sinatra::NotFound' ].freeze
- RACK_ENV_WHITELIST_DEFAULT =
%w( REMOTE_ADDR SERVER_NAME SERVER_PORT ).freeze
- HEROKU_DYNO_METADATA_MESSAGE =
"You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\ "release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
- LOG_PREFIX =
"** [Sentry] ".freeze
- MODULE_SEPARATOR =
"::".freeze
- AVAILABLE_BREADCRUMBS_LOGGERS =
[:sentry_logger, :active_support_logger].freeze
- @@post_initialization_callbacks =
Post initialization callbacks are called at the end of initialization process allowing extending the configuration of sentry-ruby by multiple extensions
[]
Instance Attribute Summary collapse
-
#app_dirs_pattern ⇒ Object
Directories to be recognized as part of your app.
-
#async ⇒ Object
Provide an object that responds to
callto send events asynchronously. -
#background_worker_threads ⇒ Object
to send events in a non-blocking way, sentry-ruby has its own background worker by default, the worker holds a thread pool that has [the number of processors] threads but you can configure it with this configuration option E.g.: config.background_worker_threads = 5.
-
#backtrace_cleanup_callback ⇒ Object
a proc/lambda that takes an array of stack traces it’ll be used to silence (reduce) backtrace of the exception.
-
#before_breadcrumb ⇒ Object
Optional Proc, called before adding the breadcrumb to the current scope E.g.: lambda { |breadcrumb, hint| breadcrumb } E.g.: lambda { |breadcrumb, hint| nil } E.g.: lambda { |breadcrumb, hint| breadcrumb.message = ‘a’ breadcrumb }.
-
#before_send ⇒ Object
Optional Proc, called before sending an event to the server/ E.g.: lambda { |event, hint| event } E.g.: lambda { |event, hint| nil } E.g.: lambda { |event, hint| event = ‘a’ event }.
-
#breadcrumbs_logger ⇒ Object
An array of breadcrumbs loggers to be used.
-
#context_lines ⇒ Object
Number of lines of code context to capture, or nil for none.
-
#dsn ⇒ Object
the dsn value, whether it’s set via
config.dsn=or ‘ENV`. -
#enabled_environments ⇒ Object
Whitelist of enabled_environments that will send notifications to Sentry.
-
#environment ⇒ Object
RACK_ENV by default.
-
#errors ⇒ Object
readonly
these are not config options.
-
#exclude_loggers ⇒ Object
Logger ‘progname’s to exclude from breadcrumbs.
-
#excluded_exceptions ⇒ Object
Array of exception classes that should never be sent.
-
#gem_specs ⇒ Object
readonly
these are not config options.
-
#inspect_exception_causes_for_exclusion ⇒ Object
(also: #inspect_exception_causes_for_exclusion?)
Boolean to check nested exceptions when deciding if to exclude.
-
#linecache ⇒ Object
You may provide your own LineCache for matching paths with source files.
-
#logger ⇒ Object
Logger used by Sentry.
-
#project_root ⇒ Object
Project directory root for in_app detection.
-
#rack_env_whitelist ⇒ Object
Array of rack env parameters to be included in the event sent to sentry.
-
#release ⇒ Object
Release tag to be passed with every event sent to Sentry.
-
#sample_rate ⇒ Object
The sampling factor to apply to events.
-
#send_default_pii ⇒ Object
When send_default_pii’s value is false (default), sensitive information like - user ip - user cookie - request body will not be sent to Sentry.
-
#send_modules ⇒ Object
Include module versions in reports - boolean.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#traces_sample_rate ⇒ Object
Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
-
#traces_sampler ⇒ Object
Take a Proc that controls the sample rate for every tracing event, e.g.
-
#transport ⇒ Object
readonly
Return a Transport::Configuration object for transport-related configurations.
-
#trusted_proxies ⇒ Object
IP ranges for trusted proxies that will be skipped when calculating IP address.
Instance Method Summary collapse
- #enabled_in_current_env? ⇒ Boolean
- #error_messages ⇒ Object
- #exception_class_allowed?(exc) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #sending_allowed? ⇒ Boolean
- #tracing_enabled? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/sentry/configuration.rb', line 172 def initialize self.background_worker_threads = Concurrent.processor_count self. = [] self.context_lines = 3 self.environment = environment_from_env self.enabled_environments = [] self.exclude_loggers = [] self.excluded_exceptions = IGNORE_DEFAULT.dup self.inspect_exception_causes_for_exclusion = true self.linecache = ::Sentry::LineCache.new self.logger = ::Sentry::Logger.new(STDOUT) self.project_root = Dir.pwd self.release = detect_release self.sample_rate = 1.0 self.send_modules = true self.send_default_pii = false self.trusted_proxies = [] self.dsn = ENV['SENTRY_DSN'] self.server_name = server_name_from_env self.before_send = false self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT @transport = Transport::Configuration.new @gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map) run_post_initialization_callbacks end |
Instance Attribute Details
#app_dirs_pattern ⇒ Object
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 to set this to something like /(app|config|engines|lib)/
13 14 15 |
# File 'lib/sentry/configuration.rb', line 13 def app_dirs_pattern @app_dirs_pattern end |
#async ⇒ Object
Provide an object that responds to call to send events asynchronously. E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
17 18 19 |
# File 'lib/sentry/configuration.rb', line 17 def async @async end |
#background_worker_threads ⇒ Object
to send events in a non-blocking way, sentry-ruby has its own background worker by default, the worker holds a thread pool that has [the number of processors] threads but you can configure it with this configuration option E.g.: config.background_worker_threads = 5
if you want to send events synchronously, set the value to 0 E.g.: config.background_worker_threads = 0
26 27 28 |
# File 'lib/sentry/configuration.rb', line 26 def background_worker_threads @background_worker_threads end |
#backtrace_cleanup_callback ⇒ Object
a proc/lambda that takes an array of stack traces it’ll be used to silence (reduce) backtrace of the exception
for example:
“‘ruby Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
Rails.backtrace_cleaner.clean(backtrace)
end “‘
39 40 41 |
# File 'lib/sentry/configuration.rb', line 39 def backtrace_cleanup_callback @backtrace_cleanup_callback end |
#before_breadcrumb ⇒ Object
Optional Proc, called before adding the breadcrumb to the current scope E.g.: lambda { |breadcrumb, hint| breadcrumb } E.g.: lambda { |breadcrumb, hint| nil } E.g.: lambda { |breadcrumb, hint|
. = 'a'
}
48 49 50 |
# File 'lib/sentry/configuration.rb', line 48 def @before_breadcrumb end |
#before_send ⇒ Object
Optional Proc, called before sending an event to the server/ E.g.: lambda { |event, hint| event } E.g.: lambda { |event, hint| nil } E.g.: lambda { |event, hint|
event[:message] = 'a'
event
}
57 58 59 |
# File 'lib/sentry/configuration.rb', line 57 def before_send @before_send end |
#breadcrumbs_logger ⇒ Object
An array of breadcrumbs loggers to be used. Available options are:
-
:sentry_logger
-
:active_support_logger
62 63 64 |
# File 'lib/sentry/configuration.rb', line 62 def @breadcrumbs_logger end |
#context_lines ⇒ Object
Number of lines of code context to capture, or nil for none
65 66 67 |
# File 'lib/sentry/configuration.rb', line 65 def context_lines @context_lines end |
#dsn ⇒ Object
the dsn value, whether it’s set via config.dsn= or ‘ENV`
71 72 73 |
# File 'lib/sentry/configuration.rb', line 71 def dsn @dsn end |
#enabled_environments ⇒ Object
Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
74 75 76 |
# File 'lib/sentry/configuration.rb', line 74 def enabled_environments @enabled_environments end |
#environment ⇒ Object
RACK_ENV by default.
68 69 70 |
# File 'lib/sentry/configuration.rb', line 68 def environment @environment end |
#errors ⇒ Object (readonly)
these are not config options
143 144 145 |
# File 'lib/sentry/configuration.rb', line 143 def errors @errors end |
#exclude_loggers ⇒ Object
Logger ‘progname’s to exclude from breadcrumbs
77 78 79 |
# File 'lib/sentry/configuration.rb', line 77 def exclude_loggers @exclude_loggers end |
#excluded_exceptions ⇒ Object
Array of exception classes that should never be sent. See IGNORE_DEFAULT. You should probably append to this rather than overwrite it.
81 82 83 |
# File 'lib/sentry/configuration.rb', line 81 def excluded_exceptions @excluded_exceptions end |
#gem_specs ⇒ Object (readonly)
these are not config options
143 144 145 |
# File 'lib/sentry/configuration.rb', line 143 def gem_specs @gem_specs end |
#inspect_exception_causes_for_exclusion ⇒ Object Also known as: inspect_exception_causes_for_exclusion?
Boolean to check nested exceptions when deciding if to exclude. Defaults to false
84 85 86 |
# File 'lib/sentry/configuration.rb', line 84 def inspect_exception_causes_for_exclusion @inspect_exception_causes_for_exclusion end |
#linecache ⇒ Object
You may provide your own LineCache for matching paths with source files. This may be useful if you need to get source code from places other than the disk. See Sentry::LineCache for the required interface you must implement.
90 91 92 |
# File 'lib/sentry/configuration.rb', line 90 def linecache @linecache end |
#logger ⇒ Object
Logger used by Sentry. In Rails, this is the Rails logger, otherwise Sentry provides its own Sentry::Logger.
94 95 96 |
# File 'lib/sentry/configuration.rb', line 94 def logger @logger end |
#project_root ⇒ Object
Project directory root for in_app detection. Could be Rails root, etc. Set automatically for Rails.
98 99 100 |
# File 'lib/sentry/configuration.rb', line 98 def project_root @project_root end |
#rack_env_whitelist ⇒ Object
Array of rack env parameters to be included in the event sent to sentry.
101 102 103 |
# File 'lib/sentry/configuration.rb', line 101 def rack_env_whitelist @rack_env_whitelist end |
#release ⇒ Object
Release tag to be passed with every event sent to Sentry. We automatically try to set this to a git SHA or Capistrano release.
105 106 107 |
# File 'lib/sentry/configuration.rb', line 105 def release @release end |
#sample_rate ⇒ Object
The sampling factor to apply to events. A value of 0.0 will not send any events, and a value of 1.0 will send 100% of events.
109 110 111 |
# File 'lib/sentry/configuration.rb', line 109 def sample_rate @sample_rate end |
#send_default_pii ⇒ Object
When send_default_pii’s value is false (default), sensitive information like
-
user ip
-
user cookie
-
request body
will not be sent to Sentry.
119 120 121 |
# File 'lib/sentry/configuration.rb', line 119 def send_default_pii @send_default_pii end |
#send_modules ⇒ Object
Include module versions in reports - boolean.
112 113 114 |
# File 'lib/sentry/configuration.rb', line 112 def send_modules @send_modules end |
#server_name ⇒ Object
Returns the value of attribute server_name.
124 125 126 |
# File 'lib/sentry/configuration.rb', line 124 def server_name @server_name end |
#traces_sample_rate ⇒ Object
Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
130 131 132 |
# File 'lib/sentry/configuration.rb', line 130 def traces_sample_rate @traces_sample_rate end |
#traces_sampler ⇒ Object
Take a Proc that controls the sample rate for every tracing event, e.g. “‘ lambda do |tracing_context|
# tracing_context[:transaction_context] contains the information about the transaction
# tracing_context[:parent_sampled] contains the transaction's parent's sample decision
true # return value can be a boolean or a float between 0.0 and 1.0
end “‘
140 141 142 |
# File 'lib/sentry/configuration.rb', line 140 def traces_sampler @traces_sampler end |
#transport ⇒ Object (readonly)
Return a Transport::Configuration object for transport-related configurations.
127 128 129 |
# File 'lib/sentry/configuration.rb', line 127 def transport @transport end |
#trusted_proxies ⇒ Object
IP ranges for trusted proxies that will be skipped when calculating IP address.
122 123 124 |
# File 'lib/sentry/configuration.rb', line 122 def trusted_proxies @trusted_proxies end |
Instance Method Details
#enabled_in_current_env? ⇒ Boolean
285 286 287 |
# File 'lib/sentry/configuration.rb', line 285 def enabled_in_current_env? enabled_environments.empty? || enabled_environments.include?(environment) end |
#error_messages ⇒ Object
263 264 265 266 |
# File 'lib/sentry/configuration.rb', line 263 def @errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first @errors.join(", ") end |
#exception_class_allowed?(exc) ⇒ Boolean
272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/sentry/configuration.rb', line 272 def exception_class_allowed?(exc) if exc.is_a?(Sentry::Error) # Try to prevent error reporting loops logger.debug(LOGGER_PROGNAME) { "Refusing to capture Sentry error: #{exc.inspect}" } false elsif excluded_exception?(exc) logger.debug(LOGGER_PROGNAME) { "User excluded error: #{exc.inspect}" } false else true end end |
#sending_allowed? ⇒ Boolean
255 256 257 258 259 260 261 |
# File 'lib/sentry/configuration.rb', line 255 def sending_allowed? @errors = [] valid? && capture_in_environment? && sample_allowed? end |
#tracing_enabled? ⇒ Boolean
289 290 291 |
# File 'lib/sentry/configuration.rb', line 289 def tracing_enabled? !!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler) end |