sentry-rails 6.1.0 → 6.2.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/lib/sentry/rails/capture_exceptions.rb +1 -0
- data/lib/sentry/rails/log_subscriber.rb +3 -0
- data/lib/sentry/rails/log_subscribers/active_record_subscriber.rb +30 -22
- data/lib/sentry/rails/tracing/active_record_subscriber.rb +15 -34
- data/lib/sentry/rails/version.rb +1 -1
- data/sentry-rails.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b63ec61238dbea2a3fee7cebbdcf72d1810dc50fe4863502ecdbc66b8da7b31e
|
|
4
|
+
data.tar.gz: 165e2974b74f63c062db1587c1852c151a5b350a15df13c408cea97476d6c10f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec0d90eb1b44f1dfb45bb369586cb8ee22da1a79604679ec12f475e1916eefe646a34c1ab97de386a43e7a27c3e3999c684d61038571ad88c6e0dca667f23f45
|
|
7
|
+
data.tar.gz: fa67c7c00d3d9f71efd13fecb195ea945538f6535464e704115d5e1a8bf7f6c3cf65c3423369270809a6d49cb99ce4b7ab700cca0885756da673f39f99fac166
|
|
@@ -27,6 +27,7 @@ module Sentry
|
|
|
27
27
|
|
|
28
28
|
def capture_exception(exception, env)
|
|
29
29
|
# the exception will be swallowed by ShowExceptions middleware
|
|
30
|
+
return unless Sentry.initialized?
|
|
30
31
|
return if show_exceptions?(exception, env) && !Sentry.configuration.rails.report_rescued_exceptions
|
|
31
32
|
|
|
32
33
|
Sentry::Rails.capture_exception(exception).tap do |event|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_support/log_subscriber"
|
|
4
|
+
require "sentry/utils/logging_helper"
|
|
4
5
|
|
|
5
6
|
module Sentry
|
|
6
7
|
module Rails
|
|
@@ -27,6 +28,8 @@ module Sentry
|
|
|
27
28
|
# end
|
|
28
29
|
# end
|
|
29
30
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
|
31
|
+
include Sentry::LoggingHelper
|
|
32
|
+
|
|
30
33
|
ORIGIN = "auto.log.rails.log_subscriber"
|
|
31
34
|
|
|
32
35
|
class << self
|
|
@@ -24,12 +24,14 @@ module Sentry
|
|
|
24
24
|
include ParameterFilter
|
|
25
25
|
|
|
26
26
|
EXCLUDED_NAMES = ["SCHEMA", "TRANSACTION"].freeze
|
|
27
|
+
EMPTY_ARRAY = [].freeze
|
|
27
28
|
|
|
28
29
|
# Handle sql.active_record events
|
|
29
30
|
#
|
|
30
31
|
# @param event [ActiveSupport::Notifications::Event] The SQL event
|
|
31
32
|
def sql(event)
|
|
32
33
|
return unless Sentry.initialized?
|
|
34
|
+
return if logger && !logger.info?
|
|
33
35
|
return if EXCLUDED_NAMES.include?(event.payload[:name])
|
|
34
36
|
|
|
35
37
|
sql = event.payload[:sql]
|
|
@@ -39,8 +41,6 @@ module Sentry
|
|
|
39
41
|
cached = event.payload.fetch(:cached, false)
|
|
40
42
|
connection_id = event.payload[:connection_id]
|
|
41
43
|
|
|
42
|
-
db_config = extract_db_config(event.payload)
|
|
43
|
-
|
|
44
44
|
attributes = {
|
|
45
45
|
sql: sql,
|
|
46
46
|
duration_ms: duration_ms(event),
|
|
@@ -49,19 +49,21 @@ module Sentry
|
|
|
49
49
|
|
|
50
50
|
binds = event.payload[:binds]
|
|
51
51
|
|
|
52
|
-
if Sentry.configuration.send_default_pii && !binds
|
|
52
|
+
if Sentry.configuration.send_default_pii && (binds && !binds.empty?)
|
|
53
53
|
type_casted_binds = type_casted_binds(event)
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
type_casted_binds.each_with_index do |value, index|
|
|
56
|
+
bind = binds[index]
|
|
57
|
+
name = bind.respond_to?(:name) ? bind.name : index.to_s
|
|
58
|
+
|
|
59
|
+
attributes["db.query.parameter.#{name}"] = value.to_s
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
attributes[:statement_name] = statement_name if statement_name && statement_name != "SQL"
|
|
62
64
|
attributes[:connection_id] = connection_id if connection_id
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
maybe_add_db_config_attributes(attributes, event.payload)
|
|
65
67
|
|
|
66
68
|
message = build_log_message(statement_name)
|
|
67
69
|
|
|
@@ -70,15 +72,19 @@ module Sentry
|
|
|
70
72
|
level: :info,
|
|
71
73
|
attributes: attributes
|
|
72
74
|
)
|
|
75
|
+
rescue => e
|
|
76
|
+
log_debug("[#{self.class}] failed to log sql event: #{e.message}")
|
|
73
77
|
end
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
def type_casted_binds(event)
|
|
80
|
+
binds = event.payload[:type_casted_binds]
|
|
81
|
+
|
|
82
|
+
# When a query is cached, binds are a callable,
|
|
83
|
+
# and under JRuby they're always a callable.
|
|
84
|
+
if binds.respond_to?(:call)
|
|
85
|
+
binds.call
|
|
86
|
+
else
|
|
87
|
+
binds
|
|
82
88
|
end
|
|
83
89
|
end
|
|
84
90
|
|
|
@@ -92,15 +98,9 @@ module Sentry
|
|
|
92
98
|
end
|
|
93
99
|
end
|
|
94
100
|
|
|
95
|
-
def
|
|
96
|
-
|
|
101
|
+
def maybe_add_db_config_attributes(attributes, payload)
|
|
102
|
+
db_config = extract_db_config(payload)
|
|
97
103
|
|
|
98
|
-
return unless connection
|
|
99
|
-
|
|
100
|
-
extract_db_config_from_connection(connection)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def add_db_config_attributes(attributes, db_config)
|
|
104
104
|
return unless db_config
|
|
105
105
|
|
|
106
106
|
attributes[:db_system] = db_config[:adapter] if db_config[:adapter]
|
|
@@ -120,6 +120,14 @@ module Sentry
|
|
|
120
120
|
attributes[:server_socket_address] = db_config[:socket] if db_config[:socket]
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
+
def extract_db_config(payload)
|
|
124
|
+
connection = payload[:connection]
|
|
125
|
+
|
|
126
|
+
return unless connection
|
|
127
|
+
|
|
128
|
+
extract_db_config_from_connection(connection)
|
|
129
|
+
end
|
|
130
|
+
|
|
123
131
|
if ::Rails.version.to_f >= 6.1
|
|
124
132
|
def extract_db_config_from_connection(connection)
|
|
125
133
|
if connection.pool.respond_to?(:db_config)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sentry/rails/tracing/abstract_subscriber"
|
|
4
|
+
require "sentry/backtrace"
|
|
4
5
|
|
|
5
6
|
module Sentry
|
|
6
7
|
module Rails
|
|
@@ -14,9 +15,11 @@ module Sentry
|
|
|
14
15
|
SUPPORT_SOURCE_LOCATION = ActiveSupport::BacktraceCleaner.method_defined?(:clean_frame)
|
|
15
16
|
|
|
16
17
|
if SUPPORT_SOURCE_LOCATION
|
|
17
|
-
|
|
18
|
+
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new.tap do |cleaner|
|
|
18
19
|
cleaner.add_silencer { |line| line.include?("sentry-ruby/lib") || line.include?("sentry-rails/lib") }
|
|
19
|
-
end)
|
|
20
|
+
end.method(:clean_frame)
|
|
21
|
+
|
|
22
|
+
class_attribute :backtrace_cleaner, default: backtrace_cleaner
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
class << self
|
|
@@ -62,43 +65,21 @@ module Sentry
|
|
|
62
65
|
span.set_data(Span::DataConventions::SERVER_PORT, db_config[:port]) if db_config[:port]
|
|
63
66
|
span.set_data(Span::DataConventions::SERVER_SOCKET_ADDRESS, db_config[:socket]) if db_config[:socket]
|
|
64
67
|
|
|
65
|
-
next unless record_query_source
|
|
66
|
-
|
|
67
68
|
# both duration and query_source_threshold are in ms
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# Only JRuby has namespace in the backtrace
|
|
79
|
-
span.set_data(Span::DataConventions::NAMESPACE, backtrace_line.module_name) if backtrace_line.module_name
|
|
69
|
+
if record_query_source && duration >= query_source_threshold
|
|
70
|
+
backtrace_line = Backtrace.source_location(&backtrace_cleaner)
|
|
71
|
+
|
|
72
|
+
if backtrace_line
|
|
73
|
+
span.set_data(Span::DataConventions::FILEPATH, backtrace_line.file) if backtrace_line.file
|
|
74
|
+
span.set_data(Span::DataConventions::LINENO, backtrace_line.number) if backtrace_line.number
|
|
75
|
+
span.set_data(Span::DataConventions::FUNCTION, backtrace_line.method) if backtrace_line.method
|
|
76
|
+
# Only JRuby has namespace in the backtrace
|
|
77
|
+
span.set_data(Span::DataConventions::NAMESPACE, backtrace_line.module_name) if backtrace_line.module_name
|
|
78
|
+
end
|
|
80
79
|
end
|
|
81
80
|
end
|
|
82
81
|
end
|
|
83
82
|
end
|
|
84
|
-
|
|
85
|
-
# Thread.each_caller_location is an API added in Ruby 3.2 that doesn't always collect the entire stack like
|
|
86
|
-
# Kernel#caller or #caller_locations do. See https://github.com/rails/rails/pull/49095 for more context.
|
|
87
|
-
if SUPPORT_SOURCE_LOCATION && Thread.respond_to?(:each_caller_location)
|
|
88
|
-
def query_source_location
|
|
89
|
-
Thread.each_caller_location do |location|
|
|
90
|
-
frame = backtrace_cleaner.clean_frame(location)
|
|
91
|
-
return frame if frame
|
|
92
|
-
end
|
|
93
|
-
nil
|
|
94
|
-
end
|
|
95
|
-
else
|
|
96
|
-
# Since Sentry is mostly used in production, we don't want to fallback to the slower implementation
|
|
97
|
-
# and adds potentially big overhead to the application.
|
|
98
|
-
def query_source_location
|
|
99
|
-
nil
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
83
|
end
|
|
103
84
|
end
|
|
104
85
|
end
|
data/lib/sentry/rails/version.rb
CHANGED
data/sentry-rails.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sentry-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sentry Team
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 6.
|
|
32
|
+
version: 6.2.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 6.
|
|
39
|
+
version: 6.2.0
|
|
40
40
|
description: A gem that provides Rails integration for the Sentry error logger
|
|
41
41
|
email: accounts@sentry.io
|
|
42
42
|
executables: []
|
|
@@ -89,15 +89,15 @@ files:
|
|
|
89
89
|
- lib/sentry/rails/tracing/active_support_subscriber.rb
|
|
90
90
|
- lib/sentry/rails/version.rb
|
|
91
91
|
- sentry-rails.gemspec
|
|
92
|
-
homepage: https://github.com/getsentry/sentry-ruby/tree/6.
|
|
92
|
+
homepage: https://github.com/getsentry/sentry-ruby/tree/6.2.0/sentry-rails
|
|
93
93
|
licenses:
|
|
94
94
|
- MIT
|
|
95
95
|
metadata:
|
|
96
|
-
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/6.
|
|
97
|
-
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/6.
|
|
98
|
-
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/6.
|
|
96
|
+
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/6.2.0/sentry-rails
|
|
97
|
+
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/6.2.0/sentry-rails
|
|
98
|
+
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/6.2.0/CHANGELOG.md
|
|
99
99
|
bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
|
|
100
|
-
documentation_uri: http://www.rubydoc.info/gems/sentry-rails/6.
|
|
100
|
+
documentation_uri: http://www.rubydoc.info/gems/sentry-rails/6.2.0
|
|
101
101
|
rdoc_options: []
|
|
102
102
|
require_paths:
|
|
103
103
|
- lib
|