sentry-ruby-core 4.8.0 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/lib/sentry/background_worker.rb +33 -3
- data/lib/sentry/backtrace.rb +1 -3
- data/lib/sentry/breadcrumb/sentry_logger.rb +2 -0
- data/lib/sentry/breadcrumb.rb +24 -3
- data/lib/sentry/breadcrumb_buffer.rb +16 -0
- data/lib/sentry/client.rb +33 -1
- data/lib/sentry/configuration.rb +88 -41
- data/lib/sentry/core_ext/object/deep_dup.rb +2 -0
- data/lib/sentry/core_ext/object/duplicable.rb +1 -0
- data/lib/sentry/dsn.rb +2 -0
- data/lib/sentry/envelope.rb +26 -0
- data/lib/sentry/event.rb +54 -18
- data/lib/sentry/exceptions.rb +2 -0
- data/lib/sentry/hub.rb +2 -0
- data/lib/sentry/integrable.rb +2 -0
- data/lib/sentry/interface.rb +3 -10
- data/lib/sentry/interfaces/exception.rb +13 -3
- data/lib/sentry/interfaces/request.rb +34 -18
- data/lib/sentry/interfaces/single_exception.rb +2 -0
- data/lib/sentry/interfaces/stacktrace.rb +6 -0
- data/lib/sentry/interfaces/stacktrace_builder.rb +39 -10
- data/lib/sentry/interfaces/threads.rb +12 -2
- data/lib/sentry/linecache.rb +3 -0
- data/lib/sentry/net/http.rb +52 -64
- data/lib/sentry/rack/capture_exceptions.rb +2 -0
- data/lib/sentry/rack.rb +2 -0
- data/lib/sentry/rake.rb +16 -6
- data/lib/sentry/release_detector.rb +3 -0
- data/lib/sentry/scope.rb +75 -5
- data/lib/sentry/span.rb +84 -8
- data/lib/sentry/transaction.rb +44 -9
- data/lib/sentry/transaction_event.rb +8 -0
- data/lib/sentry/transport/configuration.rb +2 -0
- data/lib/sentry/transport/dummy_transport.rb +2 -0
- data/lib/sentry/transport/http_transport.rb +6 -4
- data/lib/sentry/transport.rb +23 -25
- data/lib/sentry/utils/argument_checking_helper.rb +2 -0
- data/lib/sentry/utils/custom_inspection.rb +2 -0
- data/lib/sentry/utils/exception_cause_chain.rb +2 -0
- data/lib/sentry/utils/logging_helper.rb +6 -4
- data/lib/sentry/utils/real_ip.rb +2 -0
- data/lib/sentry/utils/request_id.rb +2 -0
- data/lib/sentry/version.rb +3 -1
- data/lib/sentry-ruby.rb +122 -29
- data/sentry-ruby.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acac59016a784fe97a900098b0dbd42d74996a3193d8e8f6026da3d097593d19
|
4
|
+
data.tar.gz: 2e670fbe76abfbd62e0c45e5272929a5cce1ba3ffb556afb68b50f35b4969be3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68fd8755acacba19433d948722cb02a751c61ea822360a6dcfb245a9657f197df08f11ceef800f6db06bc75b4c5e39862b8d2f2cb88c0f844718bccf2dffec77
|
7
|
+
data.tar.gz: f3083e8f467ecc06c878aa568c01dfcfd4c793da989196f1397684ef0276107b2500eeb2233557e34a55ad6e7a53e9110fcfb06ccb68077cac63d1f3810ae3b4
|
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -78,6 +78,8 @@ end
|
|
78
78
|
|
79
79
|
To learn more about sampling transactions, please visit the [official documentation](https://docs.sentry.io/platforms/ruby/configuration/sampling/#configuring-the-transaction-sample-rate).
|
80
80
|
|
81
|
+
### [Migration Guide](https://docs.sentry.io/platforms/ruby/migration/)
|
82
|
+
|
81
83
|
### Integrations
|
82
84
|
|
83
85
|
- [Rack](https://docs.sentry.io/platforms/ruby/guides/rack/)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "concurrent/executor/thread_pool_executor"
|
2
4
|
require "concurrent/executor/immediate_executor"
|
3
5
|
require "concurrent/configuration"
|
@@ -6,12 +8,18 @@ module Sentry
|
|
6
8
|
class BackgroundWorker
|
7
9
|
include LoggingHelper
|
8
10
|
|
9
|
-
attr_reader :max_queue, :number_of_threads
|
11
|
+
attr_reader :max_queue, :number_of_threads
|
12
|
+
# @deprecated Use Sentry.logger to retrieve the current logger instead.
|
13
|
+
attr_reader :logger
|
14
|
+
attr_accessor :shutdown_timeout
|
10
15
|
|
11
16
|
def initialize(configuration)
|
12
17
|
@max_queue = 30
|
18
|
+
@shutdown_timeout = 1
|
13
19
|
@number_of_threads = configuration.background_worker_threads
|
14
20
|
@logger = configuration.logger
|
21
|
+
@debug = configuration.debug
|
22
|
+
@shutdown_callback = nil
|
15
23
|
|
16
24
|
@executor =
|
17
25
|
if configuration.async
|
@@ -23,19 +31,41 @@ module Sentry
|
|
23
31
|
else
|
24
32
|
log_debug("initialized a background worker with #{@number_of_threads} threads")
|
25
33
|
|
26
|
-
Concurrent::ThreadPoolExecutor.new(
|
34
|
+
executor = Concurrent::ThreadPoolExecutor.new(
|
27
35
|
min_threads: 0,
|
28
36
|
max_threads: @number_of_threads,
|
29
37
|
max_queue: @max_queue,
|
30
38
|
fallback_policy: :discard
|
31
39
|
)
|
40
|
+
|
41
|
+
@shutdown_callback = proc do
|
42
|
+
executor.shutdown
|
43
|
+
executor.wait_for_termination(@shutdown_timeout)
|
44
|
+
end
|
45
|
+
|
46
|
+
executor
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
50
|
+
# if you want to monkey-patch this method, please override `_perform` instead
|
35
51
|
def perform(&block)
|
36
52
|
@executor.post do
|
37
|
-
|
53
|
+
begin
|
54
|
+
_perform(&block)
|
55
|
+
rescue Exception => e
|
56
|
+
log_error("exception happened in background worker", e, debug: @debug)
|
57
|
+
end
|
38
58
|
end
|
39
59
|
end
|
60
|
+
|
61
|
+
def shutdown
|
62
|
+
@shutdown_callback&.call
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def _perform(&block)
|
68
|
+
block.call
|
69
|
+
end
|
40
70
|
end
|
41
71
|
end
|
data/lib/sentry/backtrace.rb
CHANGED
data/lib/sentry/breadcrumb.rb
CHANGED
@@ -1,10 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sentry
|
2
4
|
class Breadcrumb
|
3
5
|
DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"
|
4
6
|
|
5
|
-
|
7
|
+
# @return [String, nil]
|
8
|
+
attr_accessor :category
|
9
|
+
# @return [Hash, nil]
|
10
|
+
attr_accessor :data
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_accessor :level
|
13
|
+
# @return [Time, Integer, nil]
|
14
|
+
attr_accessor :timestamp
|
15
|
+
# @return [String, nil]
|
16
|
+
attr_accessor :type
|
17
|
+
# @return [String, nil]
|
6
18
|
attr_reader :message
|
7
19
|
|
20
|
+
# @param category [String, nil]
|
21
|
+
# @param data [Hash, nil]
|
22
|
+
# @param message [String, nil]
|
23
|
+
# @param timestamp [Time, Integer, nil]
|
24
|
+
# @param level [String, nil]
|
25
|
+
# @param type [String, nil]
|
8
26
|
def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
|
9
27
|
@category = category
|
10
28
|
@data = data || {}
|
@@ -14,6 +32,7 @@ module Sentry
|
|
14
32
|
self.message = message
|
15
33
|
end
|
16
34
|
|
35
|
+
# @return [Hash]
|
17
36
|
def to_hash
|
18
37
|
{
|
19
38
|
category: @category,
|
@@ -25,8 +44,10 @@ module Sentry
|
|
25
44
|
}
|
26
45
|
end
|
27
46
|
|
28
|
-
|
29
|
-
|
47
|
+
# @param message [String]
|
48
|
+
# @return [void]
|
49
|
+
def message=(message)
|
50
|
+
@message = (message || "").byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)
|
30
51
|
end
|
31
52
|
|
32
53
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "sentry/breadcrumb"
|
2
4
|
|
3
5
|
module Sentry
|
@@ -5,40 +7,54 @@ module Sentry
|
|
5
7
|
DEFAULT_SIZE = 100
|
6
8
|
include Enumerable
|
7
9
|
|
10
|
+
# @return [Array]
|
8
11
|
attr_accessor :buffer
|
9
12
|
|
13
|
+
# @param size [Integer, nil] If it's not provided, it'll fallback to DEFAULT_SIZE
|
10
14
|
def initialize(size = nil)
|
11
15
|
@buffer = Array.new(size || DEFAULT_SIZE)
|
12
16
|
end
|
13
17
|
|
18
|
+
# @param crumb [Breadcrumb]
|
19
|
+
# @return [void]
|
14
20
|
def record(crumb)
|
15
21
|
yield(crumb) if block_given?
|
16
22
|
@buffer.slice!(0)
|
17
23
|
@buffer << crumb
|
18
24
|
end
|
19
25
|
|
26
|
+
# @return [Array]
|
20
27
|
def members
|
21
28
|
@buffer.compact
|
22
29
|
end
|
23
30
|
|
31
|
+
# Returns the last breadcrumb stored in the buffer. If the buffer it's empty, it returns nil.
|
32
|
+
# @return [Breadcrumb, nil]
|
24
33
|
def peek
|
25
34
|
members.last
|
26
35
|
end
|
27
36
|
|
37
|
+
# Iterates through all breadcrumbs.
|
38
|
+
# @param block [Proc]
|
39
|
+
# @yieldparam crumb [Breadcrumb]
|
40
|
+
# @return [Array]
|
28
41
|
def each(&block)
|
29
42
|
members.each(&block)
|
30
43
|
end
|
31
44
|
|
45
|
+
# @return [Boolean]
|
32
46
|
def empty?
|
33
47
|
members.none?
|
34
48
|
end
|
35
49
|
|
50
|
+
# @return [Hash]
|
36
51
|
def to_hash
|
37
52
|
{
|
38
53
|
values: members.map(&:to_hash)
|
39
54
|
}
|
40
55
|
end
|
41
56
|
|
57
|
+
# @return [BreadcrumbBuffer]
|
42
58
|
def dup
|
43
59
|
copy = super
|
44
60
|
copy.buffer = buffer.deep_dup
|
data/lib/sentry/client.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "sentry/transport"
|
2
4
|
|
3
5
|
module Sentry
|
4
6
|
class Client
|
5
7
|
include LoggingHelper
|
6
8
|
|
7
|
-
|
9
|
+
# The Transport object that'll send events for the client.
|
10
|
+
# @return [Transport]
|
11
|
+
attr_reader :transport
|
12
|
+
|
13
|
+
# @!macro configuration
|
14
|
+
attr_reader :configuration
|
15
|
+
|
16
|
+
# @deprecated Use Sentry.logger to retrieve the current logger instead.
|
17
|
+
attr_reader :logger
|
8
18
|
|
19
|
+
# @param configuration [Configuration]
|
9
20
|
def initialize(configuration)
|
10
21
|
@configuration = configuration
|
11
22
|
@logger = configuration.logger
|
@@ -23,6 +34,11 @@ module Sentry
|
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
37
|
+
# Applies the given scope's data to the event and sends it to Sentry.
|
38
|
+
# @param event [Event] the event to be sent.
|
39
|
+
# @param scope [Scope] the scope with contextual data that'll be applied to the event before it's sent.
|
40
|
+
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
|
41
|
+
# @return [Event, nil]
|
26
42
|
def capture_event(event, scope, hint = {})
|
27
43
|
return unless configuration.sending_allowed?
|
28
44
|
|
@@ -55,6 +71,10 @@ module Sentry
|
|
55
71
|
nil
|
56
72
|
end
|
57
73
|
|
74
|
+
# Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting.
|
75
|
+
# @param exception [Exception] the exception to be reported.
|
76
|
+
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
|
77
|
+
# @return [Event, nil]
|
58
78
|
def event_from_exception(exception, hint = {})
|
59
79
|
integration_meta = Sentry.integrations[hint[:integration]]
|
60
80
|
return unless @configuration.exception_class_allowed?(exception)
|
@@ -65,6 +85,10 @@ module Sentry
|
|
65
85
|
end
|
66
86
|
end
|
67
87
|
|
88
|
+
# Initializes an Event object with the given message.
|
89
|
+
# @param message [String] the message to be reported.
|
90
|
+
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
|
91
|
+
# @return [Event]
|
68
92
|
def event_from_message(message, hint = {}, backtrace: nil)
|
69
93
|
integration_meta = Sentry.integrations[hint[:integration]]
|
70
94
|
event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
|
@@ -72,6 +96,9 @@ module Sentry
|
|
72
96
|
event
|
73
97
|
end
|
74
98
|
|
99
|
+
# Initializes an Event object with the given Transaction object.
|
100
|
+
# @param transaction [Transaction] the transaction to be recorded.
|
101
|
+
# @return [TransactionEvent]
|
75
102
|
def event_from_transaction(transaction)
|
76
103
|
TransactionEvent.new(configuration: configuration).tap do |event|
|
77
104
|
event.transaction = transaction.name
|
@@ -84,6 +111,7 @@ module Sentry
|
|
84
111
|
end
|
85
112
|
end
|
86
113
|
|
114
|
+
# @!macro send_event
|
87
115
|
def send_event(event, hint = nil)
|
88
116
|
event_type = event.is_a?(Event) ? event.type : event["type"]
|
89
117
|
|
@@ -110,6 +138,10 @@ module Sentry
|
|
110
138
|
raise
|
111
139
|
end
|
112
140
|
|
141
|
+
# Generates a Sentry trace for distribted tracing from the given Span.
|
142
|
+
# Returns `nil` if `config.propagate_traces` is `false`.
|
143
|
+
# @param span [Span] the span to generate trace from.
|
144
|
+
# @return [String, nil]
|
113
145
|
def generate_sentry_trace(span)
|
114
146
|
return unless configuration.propagate_traces
|
115
147
|
|
data/lib/sentry/configuration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "concurrent/utility/processor_counter"
|
2
4
|
|
3
5
|
require "sentry/utils/exception_cause_chain"
|
@@ -15,10 +17,15 @@ module Sentry
|
|
15
17
|
# Directories to be recognized as part of your app. e.g. if you
|
16
18
|
# have an `engines` dir at the root of your project, you may want
|
17
19
|
# to set this to something like /(app|config|engines|lib)/
|
20
|
+
#
|
21
|
+
# @return [Regexp, nil]
|
18
22
|
attr_accessor :app_dirs_pattern
|
19
23
|
|
20
24
|
# Provide an object that responds to `call` to send events asynchronously.
|
21
25
|
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
|
26
|
+
#
|
27
|
+
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
|
28
|
+
# @return [Proc, nil]
|
22
29
|
attr_reader :async
|
23
30
|
|
24
31
|
# to send events in a non-blocking way, sentry-ruby has its own background worker
|
@@ -28,143 +35,179 @@ module Sentry
|
|
28
35
|
#
|
29
36
|
# if you want to send events synchronously, set the value to 0
|
30
37
|
# E.g.: config.background_worker_threads = 0
|
38
|
+
# @return [Integer]
|
31
39
|
attr_accessor :background_worker_threads
|
32
40
|
|
33
41
|
# a proc/lambda that takes an array of stack traces
|
34
42
|
# it'll be used to silence (reduce) backtrace of the exception
|
35
43
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# Rails.backtrace_cleaner.clean(backtrace)
|
41
|
-
# end
|
42
|
-
# ```
|
44
|
+
# @example
|
45
|
+
# config.backtrace_cleanup_callback = lambda do |backtrace|
|
46
|
+
# Rails.backtrace_cleaner.clean(backtrace)
|
47
|
+
# end
|
43
48
|
#
|
49
|
+
# @return [Proc, nil]
|
44
50
|
attr_accessor :backtrace_cleanup_callback
|
45
51
|
|
46
52
|
# Optional Proc, called before adding the breadcrumb to the current scope
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
+
# @example
|
54
|
+
# config.before = lambda do |breadcrumb, hint|
|
55
|
+
# breadcrumb.message = 'a'
|
56
|
+
# breadcrumb
|
57
|
+
# end
|
58
|
+
# @return [Proc]
|
53
59
|
attr_reader :before_breadcrumb
|
54
60
|
|
55
|
-
# Optional Proc, called before sending an event to the server
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
61
|
+
# Optional Proc, called before sending an event to the server
|
62
|
+
# @example
|
63
|
+
# config.before_send = lambda do |event, hint|
|
64
|
+
# # skip ZeroDivisionError exceptions
|
65
|
+
# # note: hint[:exception] would be a String if you use async callback
|
66
|
+
# if hint[:exception].is_a?(ZeroDivisionError)
|
67
|
+
# nil
|
68
|
+
# else
|
69
|
+
# event
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# @return [Proc]
|
62
73
|
attr_reader :before_send
|
63
74
|
|
64
75
|
# An array of breadcrumbs loggers to be used. Available options are:
|
65
76
|
# - :sentry_logger
|
77
|
+
# - :http_logger
|
78
|
+
#
|
79
|
+
# And if you also use sentry-rails:
|
66
80
|
# - :active_support_logger
|
81
|
+
# - :monotonic_active_support_logger
|
82
|
+
#
|
83
|
+
# @return [Array<Symbol>]
|
67
84
|
attr_reader :breadcrumbs_logger
|
68
85
|
|
69
86
|
# Whether to capture local variables from the raised exception's frame. Default is false.
|
87
|
+
# @return [Boolean]
|
70
88
|
attr_accessor :capture_exception_frame_locals
|
71
89
|
|
72
90
|
# Max number of breadcrumbs a breadcrumb buffer can hold
|
91
|
+
# @return [Integer]
|
73
92
|
attr_accessor :max_breadcrumbs
|
74
93
|
|
75
94
|
# Number of lines of code context to capture, or nil for none
|
95
|
+
# @return [Integer, nil]
|
76
96
|
attr_accessor :context_lines
|
77
97
|
|
78
98
|
# RACK_ENV by default.
|
99
|
+
# @return [String]
|
79
100
|
attr_reader :environment
|
80
101
|
|
81
102
|
# Whether the SDK should run in the debugging mode. Default is false.
|
82
103
|
# If set to true, SDK errors will be logged with backtrace
|
104
|
+
# @return [Boolean]
|
83
105
|
attr_accessor :debug
|
84
106
|
|
85
107
|
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
108
|
+
# @return [String]
|
86
109
|
attr_reader :dsn
|
87
110
|
|
88
111
|
# Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
|
112
|
+
# @return [Array<String>]
|
89
113
|
attr_accessor :enabled_environments
|
90
114
|
|
91
115
|
# Logger 'progname's to exclude from breadcrumbs
|
116
|
+
# @return [Array<String>]
|
92
117
|
attr_accessor :exclude_loggers
|
93
118
|
|
94
119
|
# Array of exception classes that should never be sent. See IGNORE_DEFAULT.
|
95
120
|
# You should probably append to this rather than overwrite it.
|
121
|
+
# @return [Array<String>]
|
96
122
|
attr_accessor :excluded_exceptions
|
97
123
|
|
98
124
|
# Boolean to check nested exceptions when deciding if to exclude. Defaults to true
|
125
|
+
# @return [Boolean]
|
99
126
|
attr_accessor :inspect_exception_causes_for_exclusion
|
100
127
|
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
|
101
128
|
|
102
129
|
# You may provide your own LineCache for matching paths with source files.
|
103
|
-
# This may be useful if you need to get source code from places other than
|
104
|
-
#
|
130
|
+
# This may be useful if you need to get source code from places other than the disk.
|
131
|
+
# @see LineCache
|
132
|
+
# @return [LineCache]
|
105
133
|
attr_accessor :linecache
|
106
134
|
|
107
135
|
# Logger used by Sentry. In Rails, this is the Rails logger, otherwise
|
108
136
|
# Sentry provides its own Sentry::Logger.
|
137
|
+
# @return [Logger]
|
109
138
|
attr_accessor :logger
|
110
139
|
|
111
140
|
# Project directory root for in_app detection. Could be Rails root, etc.
|
112
141
|
# Set automatically for Rails.
|
142
|
+
# @return [String]
|
113
143
|
attr_accessor :project_root
|
114
144
|
|
115
145
|
# Insert sentry-trace to outgoing requests' headers
|
146
|
+
# @return [Boolean]
|
116
147
|
attr_accessor :propagate_traces
|
117
148
|
|
118
149
|
# Array of rack env parameters to be included in the event sent to sentry.
|
150
|
+
# @return [Array<String>]
|
119
151
|
attr_accessor :rack_env_whitelist
|
120
152
|
|
121
153
|
# Release tag to be passed with every event sent to Sentry.
|
122
154
|
# We automatically try to set this to a git SHA or Capistrano release.
|
155
|
+
# @return [String]
|
123
156
|
attr_accessor :release
|
124
157
|
|
125
158
|
# The sampling factor to apply to events. A value of 0.0 will not send
|
126
159
|
# any events, and a value of 1.0 will send 100% of events.
|
160
|
+
# @return [Float]
|
127
161
|
attr_accessor :sample_rate
|
128
162
|
|
129
163
|
# Include module versions in reports - boolean.
|
164
|
+
# @return [Boolean]
|
130
165
|
attr_accessor :send_modules
|
131
166
|
|
132
167
|
# When send_default_pii's value is false (default), sensitive information like
|
133
168
|
# - user ip
|
134
169
|
# - user cookie
|
135
170
|
# - request body
|
171
|
+
# - query string
|
136
172
|
# will not be sent to Sentry.
|
173
|
+
# @return [Boolean]
|
137
174
|
attr_accessor :send_default_pii
|
138
175
|
|
139
176
|
# Allow to skip Sentry emails within rake tasks
|
177
|
+
# @return [Boolean]
|
140
178
|
attr_accessor :skip_rake_integration
|
141
179
|
|
142
180
|
# IP ranges for trusted proxies that will be skipped when calculating IP address.
|
143
181
|
attr_accessor :trusted_proxies
|
144
182
|
|
183
|
+
# @return [String]
|
145
184
|
attr_accessor :server_name
|
146
185
|
|
147
186
|
# Return a Transport::Configuration object for transport-related configurations.
|
187
|
+
# @return [Transport]
|
148
188
|
attr_reader :transport
|
149
189
|
|
150
190
|
# Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
|
191
|
+
# @return [Float]
|
151
192
|
attr_accessor :traces_sample_rate
|
152
193
|
|
153
194
|
# Take a Proc that controls the sample rate for every tracing event, e.g.
|
154
|
-
#
|
155
|
-
# lambda do |tracing_context|
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
195
|
+
# @example
|
196
|
+
# config.traces_sampler = lambda do |tracing_context|
|
197
|
+
# # tracing_context[:transaction_context] contains the information about the transaction
|
198
|
+
# # tracing_context[:parent_sampled] contains the transaction's parent's sample decision
|
199
|
+
# true # return value can be a boolean or a float between 0.0 and 1.0
|
200
|
+
# end
|
201
|
+
# @return [Proc]
|
161
202
|
attr_accessor :traces_sampler
|
162
203
|
|
163
204
|
# Send diagnostic client reports about dropped events, true by default
|
164
205
|
# tries to attach to an existing envelope max once every 30s
|
206
|
+
# @return [Boolean]
|
165
207
|
attr_accessor :send_client_reports
|
166
208
|
|
167
209
|
# these are not config options
|
210
|
+
# @!visibility private
|
168
211
|
attr_reader :errors, :gem_specs
|
169
212
|
|
170
213
|
# Most of these errors generate 4XX responses. In general, Sentry clients
|
@@ -285,11 +328,6 @@ module Sentry
|
|
285
328
|
Random.rand < sample_rate
|
286
329
|
end
|
287
330
|
|
288
|
-
def error_messages
|
289
|
-
@errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
|
290
|
-
@errors.join(", ")
|
291
|
-
end
|
292
|
-
|
293
331
|
def exception_class_allowed?(exc)
|
294
332
|
if exc.is_a?(Sentry::Error)
|
295
333
|
# Try to prevent error reporting loops
|
@@ -311,6 +349,17 @@ module Sentry
|
|
311
349
|
!!((@traces_sample_rate && @traces_sample_rate >= 0.0 && @traces_sample_rate <= 1.0) || @traces_sampler) && sending_allowed?
|
312
350
|
end
|
313
351
|
|
352
|
+
# @return [String, nil]
|
353
|
+
def csp_report_uri
|
354
|
+
if dsn && dsn.valid?
|
355
|
+
uri = dsn.csp_report_uri
|
356
|
+
uri += "&sentry_release=#{CGI.escape(release)}" if release && !release.empty?
|
357
|
+
uri += "&sentry_environment=#{CGI.escape(environment)}" if environment && !environment.empty?
|
358
|
+
uri
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
# @api private
|
314
363
|
def stacktrace_builder
|
315
364
|
@stacktrace_builder ||= StacktraceBuilder.new(
|
316
365
|
project_root: @project_root.to_s,
|
@@ -321,6 +370,7 @@ module Sentry
|
|
321
370
|
)
|
322
371
|
end
|
323
372
|
|
373
|
+
# @api private
|
324
374
|
def detect_release
|
325
375
|
return unless sending_allowed?
|
326
376
|
|
@@ -333,13 +383,10 @@ module Sentry
|
|
333
383
|
log_error("Error detecting release", e, debug: debug)
|
334
384
|
end
|
335
385
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
uri += "&sentry_environment=#{CGI.escape(environment)}" if environment && !environment.empty?
|
341
|
-
uri
|
342
|
-
end
|
386
|
+
# @api private
|
387
|
+
def error_messages
|
388
|
+
@errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
|
389
|
+
@errors.join(", ")
|
343
390
|
end
|
344
391
|
|
345
392
|
private
|
data/lib/sentry/dsn.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sentry
|
4
|
+
# @api private
|
5
|
+
class Envelope
|
6
|
+
def initialize(headers)
|
7
|
+
@headers = headers
|
8
|
+
@items = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_item(headers, payload)
|
12
|
+
@items << [headers, payload]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
payload = @items.map do |item_headers, item_payload|
|
17
|
+
<<~ENVELOPE
|
18
|
+
#{JSON.generate(item_headers)}
|
19
|
+
#{JSON.generate(item_payload)}
|
20
|
+
ENVELOPE
|
21
|
+
end.join("\n")
|
22
|
+
|
23
|
+
"#{JSON.generate(@headers)}\n#{payload}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|