activerecord-instrumentation 0.6.1 → 0.6.2

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: f4946d5d97ab8aab8e8bbc51756e729aeb83ef93e7631d177071d109a60cd1a3
4
- data.tar.gz: 46e7086f48e49b5ffec1c6c7a84d6a4502eb805599b268748f7a12b2ace248b8
3
+ metadata.gz: 8603038dd7ae6f69abee6711888a7d19ff52c1367978b870de7af88f95ca25da
4
+ data.tar.gz: be0315e02ee883a8d0f92c876a13c444fa33b26b160857dae518f2536de2e449
5
5
  SHA512:
6
- metadata.gz: cc6b52f3e074b8b357c9f542d8980c09eb40346c1f61ccebb9f7d6b474f22a573fa295a7d4ea4d6e448763bb8c17272d70420da4cdf938a78eef183a6d050b11
7
- data.tar.gz: f20c110b0971e300b1b34f8cbc9987ffa55b75defece93eeb1c0efd125f238250e0eb2153176a6fa9ce1f3bd657e2d8e24da7181d2f87ace075b30b5e48cf333
6
+ metadata.gz: 863be5ed15faafa248f2e6a78dbce8c51afc06bcf1f1be26cc217bfe552b1c9e074ccfd39963713706d6d91d6e61e8460e85c7937a890f1f40320420606d1c1d
7
+ data.tar.gz: 78fb8df31957e3b538584c5e8ae84613f43f047896d37fe899607544ac3464fb1aa3ca35aa387088aed4859e91c1285224084f571a1b2bf6f53d07be6e3dbdd7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 0.6.2 11/21/2023
5
+ * Add db.role tag
6
+
4
7
  ## 0.6.1 09/07/2022
5
8
  * Update for ruby 3.x compatibility
6
9
  * Splat hash when passing method expecting keyword args
data/Gemfile.lock CHANGED
@@ -1,30 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-instrumentation (0.6.1)
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 (7.0.4)
12
- activesupport (= 7.0.4)
13
- activerecord (7.0.4)
14
- activemodel (= 7.0.4)
15
- activesupport (= 7.0.4)
16
- activesupport (7.0.4)
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
27
  ast (2.4.0)
22
- 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)
23
32
  diff-lcs (1.3)
24
- i18n (1.12.0)
33
+ drb (2.2.0)
34
+ ruby2_keywords
35
+ i18n (1.14.1)
25
36
  concurrent-ruby (~> 1.0)
26
37
  jaro_winkler (1.5.4)
27
- minitest (5.16.3)
38
+ minitest (5.20.0)
39
+ mutex_m (0.2.0)
28
40
  opentracing (0.5.0)
29
41
  opentracing_test_tracer (0.1.1)
30
42
  opentracing
@@ -59,10 +71,12 @@ GEM
59
71
  rubocop-rspec (1.37.1)
60
72
  rubocop (>= 0.68.1)
61
73
  ruby-progressbar (1.10.1)
74
+ ruby2_keywords (0.0.5)
62
75
  sdoc (1.1.0)
63
76
  rdoc (>= 5.0)
64
77
  sqlite3 (1.4.2)
65
- tzinfo (2.0.5)
78
+ timeout (0.4.1)
79
+ tzinfo (2.0.6)
66
80
  concurrent-ruby (~> 1.0)
67
81
  unicode-display_width (1.6.1)
68
82
 
@@ -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"
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
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-28 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
@@ -213,8 +213,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  - !ruby/object:Gem::Version
214
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: []