sentry-ruby-core 4.6.2 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/sentry/breadcrumb/sentry_logger.rb +1 -1
- data/lib/sentry/client.rb +8 -3
- data/lib/sentry/configuration.rb +11 -2
- 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 +4 -0
- data/lib/sentry/event.rb +7 -6
- data/lib/sentry/hub.rb +4 -1
- data/lib/sentry/interfaces/request.rb +15 -2
- data/lib/sentry/rake.rb +20 -19
- data/lib/sentry/scope.rb +1 -1
- data/lib/sentry/transaction_event.rb +11 -6
- data/lib/sentry/transport/configuration.rb +2 -1
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +48 -29
- data/sentry-ruby-core.gemspec +1 -1
- data/sentry-ruby.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08bb1e6f6c55f8f9a206aabcb008ac4e8322652831108a0ec5145b69ed741c1d'
|
4
|
+
data.tar.gz: 7d699edbb8b0a1e05c44b0d039f2e9ea79cba7355961488f1bc9311e8a92cb14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff6528918de5664c632d44c48cc04536cd41537e7fb2e5bc372c5794834cc4450b9d6aff82ba6ba4ad0a822ee5f96bc74a165ae6c1164299585019a187c63aad
|
7
|
+
data.tar.gz: 9cf4dcecb8d81ec03048d22ffc75a0d4647b70a4bf037e9183ff794ef044f1ece661218a4ca22aef89cdbb4992361b1c9829a5aeeab0179430afc420c2d8a01f
|
data/LICENSE.txt
CHANGED
data/lib/sentry/client.rb
CHANGED
@@ -26,7 +26,12 @@ module Sentry
|
|
26
26
|
def capture_event(event, scope, hint = {})
|
27
27
|
return unless configuration.sending_allowed?
|
28
28
|
|
29
|
-
scope.apply_to_event(event, hint)
|
29
|
+
event = scope.apply_to_event(event, hint)
|
30
|
+
|
31
|
+
if event.nil?
|
32
|
+
log_info("Discarded event because one of the event processors returned nil")
|
33
|
+
return
|
34
|
+
end
|
30
35
|
|
31
36
|
if async_block = configuration.async
|
32
37
|
dispatch_async_event(async_block, event, hint)
|
@@ -52,10 +57,10 @@ module Sentry
|
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
55
|
-
def event_from_message(message, hint = {})
|
60
|
+
def event_from_message(message, hint = {}, backtrace: nil)
|
56
61
|
integration_meta = Sentry.integrations[hint[:integration]]
|
57
62
|
event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
|
58
|
-
event.add_threads_interface(backtrace: caller)
|
63
|
+
event.add_threads_interface(backtrace: backtrace || caller)
|
59
64
|
event
|
60
65
|
end
|
61
66
|
|
data/lib/sentry/configuration.rb
CHANGED
@@ -89,7 +89,7 @@ module Sentry
|
|
89
89
|
# You should probably append to this rather than overwrite it.
|
90
90
|
attr_accessor :excluded_exceptions
|
91
91
|
|
92
|
-
# Boolean to check nested exceptions when deciding if to exclude. Defaults to
|
92
|
+
# Boolean to check nested exceptions when deciding if to exclude. Defaults to true
|
93
93
|
attr_accessor :inspect_exception_causes_for_exclusion
|
94
94
|
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
|
95
95
|
|
@@ -324,6 +324,15 @@ module Sentry
|
|
324
324
|
log_error("Error detecting release", e, debug: debug)
|
325
325
|
end
|
326
326
|
|
327
|
+
def csp_report_uri
|
328
|
+
if dsn && dsn.valid?
|
329
|
+
uri = dsn.csp_report_uri
|
330
|
+
uri += "&sentry_release=#{CGI.escape(release)}" if release && !release.empty?
|
331
|
+
uri += "&sentry_environment=#{CGI.escape(environment)}" if environment && !environment.empty?
|
332
|
+
uri
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
327
336
|
private
|
328
337
|
|
329
338
|
def excluded_exception?(incoming_exception)
|
@@ -405,7 +414,7 @@ module Sentry
|
|
405
414
|
def sample_allowed?
|
406
415
|
return true if sample_rate == 1.0
|
407
416
|
|
408
|
-
if Random
|
417
|
+
if Random.rand >= sample_rate
|
409
418
|
@errors << "Excluded by random sample"
|
410
419
|
false
|
411
420
|
else
|
data/lib/sentry/dsn.rb
CHANGED
data/lib/sentry/event.rb
CHANGED
@@ -9,7 +9,7 @@ require 'sentry/utils/request_id'
|
|
9
9
|
|
10
10
|
module Sentry
|
11
11
|
class Event
|
12
|
-
|
12
|
+
SERIALIZEABLE_ATTRIBUTES = %i(
|
13
13
|
event_id level timestamp
|
14
14
|
release environment server_name modules
|
15
15
|
message user tags contexts extra
|
@@ -17,9 +17,13 @@ module Sentry
|
|
17
17
|
platform sdk type
|
18
18
|
)
|
19
19
|
|
20
|
+
WRITER_ATTRIBUTES = SERIALIZEABLE_ATTRIBUTES - %i(type timestamp level)
|
21
|
+
|
20
22
|
MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8
|
21
23
|
|
22
|
-
|
24
|
+
attr_writer(*WRITER_ATTRIBUTES)
|
25
|
+
attr_reader(*SERIALIZEABLE_ATTRIBUTES)
|
26
|
+
|
23
27
|
attr_reader :configuration, :request, :exception, :threads
|
24
28
|
|
25
29
|
def initialize(configuration:, integration_meta: nil, message: nil)
|
@@ -99,9 +103,6 @@ module Sentry
|
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
102
|
-
def type
|
103
|
-
end
|
104
|
-
|
105
106
|
def to_hash
|
106
107
|
data = serialize_attributes
|
107
108
|
data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs
|
@@ -139,7 +140,7 @@ module Sentry
|
|
139
140
|
private
|
140
141
|
|
141
142
|
def serialize_attributes
|
142
|
-
self.class::
|
143
|
+
self.class::SERIALIZEABLE_ATTRIBUTES.each_with_object({}) do |att, memo|
|
143
144
|
if value = public_send(att)
|
144
145
|
memo[att] = value
|
145
146
|
end
|
data/lib/sentry/hub.rb
CHANGED
@@ -108,7 +108,8 @@ module Sentry
|
|
108
108
|
|
109
109
|
options[:hint] ||= {}
|
110
110
|
options[:hint][:message] = message
|
111
|
-
|
111
|
+
backtrace = options.delete(:backtrace)
|
112
|
+
event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)
|
112
113
|
capture_event(event, **options, &block)
|
113
114
|
end
|
114
115
|
|
@@ -135,6 +136,8 @@ module Sentry
|
|
135
136
|
end
|
136
137
|
|
137
138
|
def add_breadcrumb(breadcrumb, hint: {})
|
139
|
+
return unless configuration.enabled_in_current_env?
|
140
|
+
|
138
141
|
if before_breadcrumb = current_client.configuration.before_breadcrumb
|
139
142
|
breadcrumb = before_breadcrumb.call(breadcrumb, hint)
|
140
143
|
end
|
@@ -57,7 +57,7 @@ module Sentry
|
|
57
57
|
request.POST
|
58
58
|
elsif request.body # JSON requests, etc
|
59
59
|
data = request.body.read(MAX_BODY_LIMIT)
|
60
|
-
data =
|
60
|
+
data = encode_to_utf_8(data.to_s)
|
61
61
|
request.body.rewind
|
62
62
|
data
|
63
63
|
end
|
@@ -76,7 +76,8 @@ module Sentry
|
|
76
76
|
# Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
|
77
77
|
key = key.sub(/^HTTP_/, "")
|
78
78
|
key = key.split('_').map(&:capitalize).join('-')
|
79
|
-
|
79
|
+
|
80
|
+
memo[key] = encode_to_utf_8(value.to_s)
|
80
81
|
rescue StandardError => e
|
81
82
|
# Rails adds objects to the Rack env that can sometimes raise exceptions
|
82
83
|
# when `to_s` is called.
|
@@ -87,6 +88,18 @@ module Sentry
|
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
91
|
+
def encode_to_utf_8(value)
|
92
|
+
if value.encoding != Encoding::UTF_8 && value.respond_to?(:force_encoding)
|
93
|
+
value = value.dup.force_encoding(Encoding::UTF_8)
|
94
|
+
end
|
95
|
+
|
96
|
+
if !value.valid_encoding?
|
97
|
+
value = value.scrub
|
98
|
+
end
|
99
|
+
|
100
|
+
value
|
101
|
+
end
|
102
|
+
|
90
103
|
def is_skippable_header?(key)
|
91
104
|
key.upcase != key || # lower-case envs aren't real http headers
|
92
105
|
key == "HTTP_COOKIE" || # Cookies don't go here, they go somewhere else
|
data/lib/sentry/rake.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
require "rake"
|
2
2
|
require "rake/task"
|
3
3
|
|
4
|
-
module
|
5
|
-
|
4
|
+
module Sentry
|
5
|
+
module Rake
|
6
|
+
module Application
|
7
|
+
def display_error_message(ex)
|
8
|
+
Sentry.capture_exception(ex, hint: { background: false }) do |scope|
|
9
|
+
task_name = top_level_tasks.join(' ')
|
10
|
+
scope.set_transaction_name(task_name)
|
11
|
+
scope.set_tag("rake_task", task_name)
|
12
|
+
end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
Sentry.capture_exception(ex, hint: { background: false }) do |scope|
|
10
|
-
task_name = top_level_tasks.join(' ')
|
11
|
-
scope.set_transaction_name(task_name)
|
12
|
-
scope.set_tag("rake_task", task_name)
|
13
|
-
end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration
|
14
|
-
|
15
|
-
orig_display_error_messsage(ex)
|
14
|
+
super
|
15
|
+
end
|
16
16
|
end
|
17
|
-
end
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
module Task
|
19
|
+
def execute(args=nil)
|
20
|
+
return super unless Sentry.initialized? && Sentry.get_current_hub
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Sentry.get_current_hub.with_background_worker_disabled do
|
26
|
-
orig_execute
|
22
|
+
Sentry.get_current_hub.with_background_worker_disabled do
|
23
|
+
super
|
24
|
+
end
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
29
|
+
|
30
|
+
Rake::Application.prepend(Sentry::Rake::Application)
|
31
|
+
Rake::Task.prepend(Sentry::Rake::Task)
|
data/lib/sentry/scope.rb
CHANGED
@@ -23,6 +23,7 @@ module Sentry
|
|
23
23
|
event.user = user.merge(event.user)
|
24
24
|
event.extra = extra.merge(event.extra)
|
25
25
|
event.contexts = contexts.merge(event.contexts)
|
26
|
+
event.transaction = transaction_name if transaction_name
|
26
27
|
|
27
28
|
if span
|
28
29
|
event.contexts[:trace] = span.get_trace_context
|
@@ -30,7 +31,6 @@ module Sentry
|
|
30
31
|
|
31
32
|
event.fingerprint = fingerprint
|
32
33
|
event.level = level
|
33
|
-
event.transaction = transaction_names.last
|
34
34
|
event.breadcrumbs = breadcrumbs
|
35
35
|
event.rack_env = rack_env if rack_env
|
36
36
|
|
@@ -4,22 +4,27 @@ module Sentry
|
|
4
4
|
class TransactionEvent < Event
|
5
5
|
TYPE = "transaction"
|
6
6
|
|
7
|
-
|
7
|
+
SERIALIZEABLE_ATTRIBUTES = %i(
|
8
8
|
event_id level timestamp start_timestamp
|
9
9
|
release environment server_name modules
|
10
10
|
user tags contexts extra
|
11
11
|
transaction platform sdk type
|
12
12
|
)
|
13
13
|
|
14
|
-
|
14
|
+
WRITER_ATTRIBUTES = SERIALIZEABLE_ATTRIBUTES - %i(type timestamp start_timestamp level)
|
15
|
+
|
16
|
+
attr_writer(*WRITER_ATTRIBUTES)
|
17
|
+
attr_reader(*SERIALIZEABLE_ATTRIBUTES)
|
18
|
+
|
15
19
|
attr_accessor :spans
|
16
20
|
|
17
|
-
def
|
18
|
-
|
21
|
+
def initialize(configuration:, integration_meta: nil, message: nil)
|
22
|
+
super
|
23
|
+
@type = TYPE
|
19
24
|
end
|
20
25
|
|
21
|
-
def
|
22
|
-
|
26
|
+
def start_timestamp=(time)
|
27
|
+
@start_timestamp = time.is_a?(Time) ? time.to_f : time
|
23
28
|
end
|
24
29
|
|
25
30
|
def to_hash
|
@@ -2,7 +2,8 @@ module Sentry
|
|
2
2
|
class Transport
|
3
3
|
class Configuration
|
4
4
|
attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder,
|
5
|
-
:
|
5
|
+
:encoding
|
6
|
+
attr_reader :transport_class
|
6
7
|
|
7
8
|
def initialize
|
8
9
|
@ssl_verification = true
|
data/lib/sentry/version.rb
CHANGED
data/lib/sentry-ruby.rb
CHANGED
@@ -36,15 +36,27 @@ module Sentry
|
|
36
36
|
|
37
37
|
THREAD_LOCAL = :sentry_hub
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
39
|
+
class << self
|
40
|
+
attr_accessor :background_worker
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
##### Patch Registration #####
|
43
|
+
#
|
44
|
+
def register_patch(&block)
|
45
|
+
registered_patches << block
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
+
def apply_patches(config)
|
49
|
+
registered_patches.each do |patch|
|
50
|
+
patch.call(config)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def registered_patches
|
55
|
+
@registered_patches ||= []
|
56
|
+
end
|
57
|
+
|
58
|
+
##### Integrations #####
|
59
|
+
#
|
48
60
|
# Returns a hash that contains all the integrations that have been registered to the main SDK.
|
49
61
|
def integrations
|
50
62
|
@integrations ||= {}
|
@@ -55,32 +67,16 @@ module Sentry
|
|
55
67
|
meta = { name: "sentry.ruby.#{name}", version: version }.freeze
|
56
68
|
integrations[name.to_s] = meta
|
57
69
|
end
|
58
|
-
end
|
59
70
|
|
60
|
-
|
71
|
+
##### Method Delegation #####
|
72
|
+
#
|
61
73
|
extend Forwardable
|
62
74
|
|
63
75
|
def_delegators :get_current_client, :configuration, :send_event
|
64
76
|
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
|
65
77
|
|
66
|
-
|
67
|
-
|
68
|
-
@@registered_patches = []
|
69
|
-
|
70
|
-
def register_patch(&block)
|
71
|
-
registered_patches << block
|
72
|
-
end
|
73
|
-
|
74
|
-
def apply_patches(config)
|
75
|
-
registered_patches.each do |patch|
|
76
|
-
patch.call(config)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def registered_patches
|
81
|
-
@@registered_patches
|
82
|
-
end
|
83
|
-
|
78
|
+
##### Main APIs #####
|
79
|
+
#
|
84
80
|
def init(&block)
|
85
81
|
config = Configuration.new
|
86
82
|
yield(config) if block_given?
|
@@ -94,14 +90,26 @@ module Sentry
|
|
94
90
|
@background_worker = Sentry::BackgroundWorker.new(config)
|
95
91
|
end
|
96
92
|
|
93
|
+
# Returns an uri for security policy reporting that's generated from the given DSN
|
94
|
+
# (To learn more about security policy reporting: https://docs.sentry.io/product/security-policy-reporting/)
|
95
|
+
#
|
96
|
+
# It returns nil if
|
97
|
+
#
|
98
|
+
# 1. The SDK is not initialized yet.
|
99
|
+
# 2. The DSN is not provided or is invalid.
|
100
|
+
def csp_report_uri
|
101
|
+
return unless initialized?
|
102
|
+
configuration.csp_report_uri
|
103
|
+
end
|
104
|
+
|
97
105
|
# Returns the main thread's active hub.
|
98
106
|
def get_main_hub
|
99
107
|
@main_hub
|
100
108
|
end
|
101
109
|
|
102
110
|
# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
|
103
|
-
def add_breadcrumb(breadcrumb)
|
104
|
-
get_current_hub&.add_breadcrumb(breadcrumb)
|
111
|
+
def add_breadcrumb(breadcrumb, **options)
|
112
|
+
get_current_hub&.add_breadcrumb(breadcrumb, **options)
|
105
113
|
end
|
106
114
|
|
107
115
|
# Returns the current active hub.
|
@@ -193,6 +201,9 @@ module Sentry
|
|
193
201
|
get_current_hub&.last_event_id
|
194
202
|
end
|
195
203
|
|
204
|
+
|
205
|
+
##### Helpers #####
|
206
|
+
#
|
196
207
|
def sys_command(command)
|
197
208
|
result = `#{command} 2>&1` rescue nil
|
198
209
|
return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
|
@@ -207,6 +218,14 @@ module Sentry
|
|
207
218
|
def logger
|
208
219
|
configuration.logger
|
209
220
|
end
|
221
|
+
|
222
|
+
def sdk_meta
|
223
|
+
META
|
224
|
+
end
|
225
|
+
|
226
|
+
def utc_now
|
227
|
+
Time.now.utc
|
228
|
+
end
|
210
229
|
end
|
211
230
|
end
|
212
231
|
|
data/sentry-ruby-core.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Sentry Team"]
|
7
7
|
spec.description = spec.summary = "A gem that provides a client interface for the Sentry error logger"
|
8
8
|
spec.email = "accounts@sentry.io"
|
9
|
-
spec.license = '
|
9
|
+
spec.license = 'MIT'
|
10
10
|
spec.homepage = "https://github.com/getsentry/sentry-ruby"
|
11
11
|
|
12
12
|
spec.platform = Gem::Platform::RUBY
|
data/sentry-ruby.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Sentry Team"]
|
7
7
|
spec.description = spec.summary = "A gem that provides a client interface for the Sentry error logger"
|
8
8
|
spec.email = "accounts@sentry.io"
|
9
|
-
spec.license = '
|
9
|
+
spec.license = 'MIT'
|
10
10
|
spec.homepage = "https://github.com/getsentry/sentry-ruby"
|
11
11
|
|
12
12
|
spec.platform = Gem::Platform::RUBY
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-ruby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -103,7 +103,7 @@ files:
|
|
103
103
|
- sentry-ruby.gemspec
|
104
104
|
homepage: https://github.com/getsentry/sentry-ruby
|
105
105
|
licenses:
|
106
|
-
-
|
106
|
+
- MIT
|
107
107
|
metadata:
|
108
108
|
homepage_uri: https://github.com/getsentry/sentry-ruby
|
109
109
|
source_code_uri: https://github.com/getsentry/sentry-ruby
|