sentry-rails 6.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a75df6b4765c66d4c8844187b1cf607e75c8089441e846ecdf6b7bb4fa9e48e4
4
- data.tar.gz: df1a64e0c65f65600664b2f3259a227debd7d346a0dd5f8ce6497ddbea7b9644
3
+ metadata.gz: b63ec61238dbea2a3fee7cebbdcf72d1810dc50fe4863502ecdbc66b8da7b31e
4
+ data.tar.gz: 165e2974b74f63c062db1587c1852c151a5b350a15df13c408cea97476d6c10f
5
5
  SHA512:
6
- metadata.gz: 46e20af7bc76d8d1b66337c1e25a5fec1eabcae2817960a88d11a76ddea251076f1d39970fefee0b54fb2d80c9f6fec8b1a4b88d299f4a61bdfcf9a0a4cdb1ef
7
- data.tar.gz: d7637f46e1fb2df9c2d6b5f07bb0c4d075f17ee013979b535d9643354abce15be08eca759851439763e79b747b062ba331a20acd557291ceea54655bdcbec287
6
+ metadata.gz: ec0d90eb1b44f1dfb45bb369586cb8ee22da1a79604679ec12f475e1916eefe646a34c1ab97de386a43e7a27c3e3999c684d61038571ad88c6e0dca667f23f45
7
+ data.tar.gz: fa67c7c00d3d9f71efd13fecb195ea945538f6535464e704115d5e1a8bf7f6c3cf65c3423369270809a6d49cb99ce4b7ab700cca0885756da673f39f99fac166
@@ -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,6 +24,7 @@ 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
  #
@@ -40,8 +41,6 @@ module Sentry
40
41
  cached = event.payload.fetch(:cached, false)
41
42
  connection_id = event.payload[:connection_id]
42
43
 
43
- db_config = extract_db_config(event.payload)
44
-
45
44
  attributes = {
46
45
  sql: sql,
47
46
  duration_ms: duration_ms(event),
@@ -50,19 +49,21 @@ module Sentry
50
49
 
51
50
  binds = event.payload[:binds]
52
51
 
53
- if Sentry.configuration.send_default_pii && !binds&.empty?
52
+ if Sentry.configuration.send_default_pii && (binds && !binds.empty?)
54
53
  type_casted_binds = type_casted_binds(event)
55
54
 
56
- binds.each_with_index do |bind, index|
57
- name = bind.is_a?(Symbol) ? bind : bind.name
58
- attributes["db.query.parameter.#{name}"] = type_casted_binds[index].to_s
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
59
60
  end
60
61
  end
61
62
 
62
63
  attributes[:statement_name] = statement_name if statement_name && statement_name != "SQL"
63
64
  attributes[:connection_id] = connection_id if connection_id
64
65
 
65
- add_db_config_attributes(attributes, db_config)
66
+ maybe_add_db_config_attributes(attributes, event.payload)
66
67
 
67
68
  message = build_log_message(statement_name)
68
69
 
@@ -71,15 +72,19 @@ module Sentry
71
72
  level: :info,
72
73
  attributes: attributes
73
74
  )
75
+ rescue => e
76
+ log_debug("[#{self.class}] failed to log sql event: #{e.message}")
74
77
  end
75
78
 
76
- if RUBY_ENGINE == "jruby"
77
- def type_casted_binds(event)
78
- event.payload[:type_casted_binds].call
79
- end
80
- else
81
- def type_casted_binds(event)
82
- event.payload[:type_casted_binds]
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
83
88
  end
84
89
  end
85
90
 
@@ -93,15 +98,9 @@ module Sentry
93
98
  end
94
99
  end
95
100
 
96
- def extract_db_config(payload)
97
- connection = payload[:connection]
101
+ def maybe_add_db_config_attributes(attributes, payload)
102
+ db_config = extract_db_config(payload)
98
103
 
99
- return unless connection
100
-
101
- extract_db_config_from_connection(connection)
102
- end
103
-
104
- def add_db_config_attributes(attributes, db_config)
105
104
  return unless db_config
106
105
 
107
106
  attributes[:db_system] = db_config[:adapter] if db_config[:adapter]
@@ -121,6 +120,14 @@ module Sentry
121
120
  attributes[:server_socket_address] = db_config[:socket] if db_config[:socket]
122
121
  end
123
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
+
124
131
  if ::Rails.version.to_f >= 6.1
125
132
  def extract_db_config_from_connection(connection)
126
133
  if connection.pool.respond_to?(:db_config)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sentry
4
4
  module Rails
5
- VERSION = "6.1.1"
5
+ VERSION = "6.2.0"
6
6
  end
7
7
  end
data/sentry-rails.gemspec CHANGED
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "railties", ">= 5.2.0"
34
- spec.add_dependency "sentry-ruby", "~> 6.1.1"
34
+ spec.add_dependency "sentry-ruby", "~> 6.2.0"
35
35
  end
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.1.1
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.1.1
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.1.1
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.1.1/sentry-rails
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.1.1/sentry-rails
97
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/6.1.1/sentry-rails
98
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/6.1.1/CHANGELOG.md
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.1.1
100
+ documentation_uri: http://www.rubydoc.info/gems/sentry-rails/6.2.0
101
101
  rdoc_options: []
102
102
  require_paths:
103
103
  - lib