activerecord-instrumentation 0.6.1.pre → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0c5d0d44e18ee992c3f8458ab3e4a8f6fe3738ce47cbb553224aec647901113
4
- data.tar.gz: 73152d2108ae460ee4c4795b1e3b50e4af567cc8292469b0c02ee7b7f251046b
3
+ metadata.gz: 8603038dd7ae6f69abee6711888a7d19ff52c1367978b870de7af88f95ca25da
4
+ data.tar.gz: be0315e02ee883a8d0f92c876a13c444fa33b26b160857dae518f2536de2e449
5
5
  SHA512:
6
- metadata.gz: 51ba7e18ebd147dd0ea8f80c50f675f8655f29bb77b360b95f1d1b94685c7c9d00f00a1ca5083055e21d48a520a73e8ff6d1228ac19dfc9032c9ac995911bd2e
7
- data.tar.gz: c108734ef121ad092f5fe24b7a477a287c6cabc57ca956f407547eddf77e13d5663d1174c8f77960cfb28889d2f1bd9c390900531edd19f51c1c85f070487e56
6
+ metadata.gz: 863be5ed15faafa248f2e6a78dbce8c51afc06bcf1f1be26cc217bfe552b1c9e074ccfd39963713706d6d91d6e61e8460e85c7937a890f1f40320420606d1c1d
7
+ data.tar.gz: 78fb8df31957e3b538584c5e8ae84613f43f047896d37fe899607544ac3464fb1aa3ca35aa387088aed4859e91c1285224084f571a1b2bf6f53d07be6e3dbdd7
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- ## 0.6.1.pre 09/07/2022
4
+ ## 0.6.2 11/21/2023
5
+ * Add db.role tag
6
+
7
+ ## 0.6.1 09/07/2022
8
+ * Update for ruby 3.x compatibility
5
9
  * Splat hash when passing method expecting keyword args
6
10
 
7
11
  ## 0.6.0 07/11/2022
data/Gemfile.lock CHANGED
@@ -1,31 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-instrumentation (0.6.1.pre)
4
+ activerecord-instrumentation (0.6.2)
5
5
  activerecord
6
6
  opentracing (~> 0.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.1.6.1)
12
- activesupport (= 6.1.6.1)
13
- activerecord (6.1.6.1)
14
- activemodel (= 6.1.6.1)
15
- activesupport (= 6.1.6.1)
16
- activesupport (6.1.6.1)
11
+ activemodel (7.1.2)
12
+ activesupport (= 7.1.2)
13
+ activerecord (7.1.2)
14
+ activemodel (= 7.1.2)
15
+ activesupport (= 7.1.2)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.1.2)
18
+ base64
19
+ bigdecimal
17
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ connection_pool (>= 2.2.5)
22
+ drb
18
23
  i18n (>= 1.6, < 2)
19
24
  minitest (>= 5.1)
25
+ mutex_m
20
26
  tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
22
27
  ast (2.4.0)
23
- concurrent-ruby (1.1.10)
28
+ base64 (0.2.0)
29
+ bigdecimal (3.1.4)
30
+ concurrent-ruby (1.2.2)
31
+ connection_pool (2.4.1)
24
32
  diff-lcs (1.3)
25
- i18n (1.11.0)
33
+ drb (2.2.0)
34
+ ruby2_keywords
35
+ i18n (1.14.1)
26
36
  concurrent-ruby (~> 1.0)
27
37
  jaro_winkler (1.5.4)
28
- minitest (5.16.2)
38
+ minitest (5.20.0)
39
+ mutex_m (0.2.0)
29
40
  opentracing (0.5.0)
30
41
  opentracing_test_tracer (0.1.1)
31
42
  opentracing
@@ -60,13 +71,14 @@ GEM
60
71
  rubocop-rspec (1.37.1)
61
72
  rubocop (>= 0.68.1)
62
73
  ruby-progressbar (1.10.1)
74
+ ruby2_keywords (0.0.5)
63
75
  sdoc (1.1.0)
64
76
  rdoc (>= 5.0)
65
77
  sqlite3 (1.4.2)
66
- tzinfo (2.0.4)
78
+ timeout (0.4.1)
79
+ tzinfo (2.0.6)
67
80
  concurrent-ruby (~> 1.0)
68
81
  unicode-display_width (1.6.1)
69
- zeitwerk (2.6.0)
70
82
 
71
83
  PLATFORMS
72
84
  ruby
@@ -74,6 +74,7 @@ module ActiveRecord
74
74
 
75
75
  def tags_for_payload(payload)
76
76
  db_config = connection_config(payload[:connection])
77
+ db_instance = db_config.fetch(:database)
77
78
 
78
79
  {
79
80
  "component" => COMPONENT_NAME,
@@ -81,7 +82,8 @@ module ActiveRecord
81
82
  "db.instance" => db_instance,
82
83
  "db.cached" => payload.fetch(:cached, false),
83
84
  "db.type" => DB_TYPE,
84
- "peer.address" => peer_address_tag(db_config)
85
+ "db.role" => db_role_for(payload[:connection]),
86
+ "peer.address" => peer_address_tag(db_config, db_instance)
85
87
  }.merge(db_statement(payload))
86
88
  end
87
89
 
@@ -106,8 +108,8 @@ module ActiveRecord
106
108
  sanitizer ? sanitizer.sanitize(sql) : sql
107
109
  end
108
110
 
109
- def peer_address_tag(config)
110
- @peer_address_tag ||= [
111
+ def peer_address_tag(config, db_instance)
112
+ [
111
113
  "#{config.fetch(:adapter)}://",
112
114
  config[:username],
113
115
  config[:host] && "@#{config[:host]}",
@@ -115,27 +117,42 @@ module ActiveRecord
115
117
  ].join
116
118
  end
117
119
 
118
- def db_instance
119
- @db_instance ||= connection_config.fetch(:database)
120
- end
121
-
122
120
  # If a connection is passed in, pull the db config options hash from it. This connection
123
121
  # is likely to be attached to the query/query client. Fall back to the application level
124
122
  # config. This change will show writer vs reader/replica dbs in spans when it is determined
125
123
  # at the query level.
126
124
  def connection_config(connection = nil)
127
- unless defined? @connection_config
128
- if connection.raw_connection && connection.raw_connection.respond_to?(:query_options)
129
- # you have a mysql client
130
- @connection_config = connection.raw_connection.query_options
131
- else
132
- # Rails 6.2 will deprecate ActiveRecord::Base.connection_config
133
- @connection_config = ActiveRecord::Base.try(:connection_db_config)&.configuration_hash ||
134
- ActiveRecord::Base.connection_config
135
- end
125
+ if connection && connection.raw_connection && connection.raw_connection.respond_to?(:query_options)
126
+ # you have a mysql client
127
+ connection.raw_connection.query_options
128
+ else
129
+ # Rails 6.2 will deprecate ActiveRecord::Base.connection_config
130
+ ActiveRecord::Base.try(:connection_db_config)&.configuration_hash ||
131
+ ActiveRecord::Base.connection_config
136
132
  end
133
+ end
137
134
 
138
- @connection_config
135
+ DB_NAME_TO_ROLE = {
136
+ "primary" => "writing",
137
+ "primary_replica" => "reading"
138
+ }
139
+
140
+ # Returns the database role for the current connection. Usually, this will
141
+ # be either writing or reading (when using reader replicas).
142
+ #
143
+ # * connection.role was introduced in Rails 7 so we fallback to reading the db_config name
144
+ # and translate based on common values.
145
+ # * connection.role calls connection.pool.role and a NoMethodError is raised when
146
+ # the connection's pool is a ActiveRecord::ConnectionAdapters::NullPool.
147
+ def db_role_for(connection)
148
+ if connection.respond_to?(:role)
149
+ connection.role.to_s
150
+ else
151
+ db_name = connection.pool.pool_config.db_config.name
152
+ DB_NAME_TO_ROLE.fetch(db_name, "unknown")
153
+ end
154
+ rescue NoMethodError
155
+ "unknown"
139
156
  end
140
157
  end
141
158
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module OpenTracing
5
- VERSION = "0.6.1.pre"
5
+ VERSION = "0.6.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.pre
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  - Doximity
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-07 00:00:00.000000000 Z
12
+ date: 2023-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -198,7 +198,7 @@ homepage: https://github.com/doximity/ruby-activerecord-opentracing
198
198
  licenses:
199
199
  - MIT
200
200
  metadata: {}
201
- post_install_message:
201
+ post_install_message:
202
202
  rdoc_options: []
203
203
  require_paths:
204
204
  - lib
@@ -209,12 +209,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - ">"
212
+ - - ">="
213
213
  - !ruby/object:Gem::Version
214
- version: 1.3.1
214
+ version: '0'
215
215
  requirements: []
216
- rubygems_version: 3.1.6
217
- signing_key:
216
+ rubygems_version: 3.3.7
217
+ signing_key:
218
218
  specification_version: 4
219
219
  summary: ActiveRecord OpenTracing intrumenter
220
220
  test_files: []