activerecord-instrumentation 0.6.0.jhemphill3 → 0.6.0.jhemphill4

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: 95c186a845e1f54640ec23d41c6f4af63672c70a2b40eead66abd7dfdfa9a5d9
4
- data.tar.gz: 5dbd6b7b69424ff53fe2aaaecd2c9980ea427f32ac85b69f779b6bd60fbfe1c5
3
+ metadata.gz: 5fceef2796a103f493c939152dcdaa4428111c082e3908354abfbe04b1614f16
4
+ data.tar.gz: ef23a8d9a4fe682d7dfd5c6d23b8bb45fd188917240d79b27fa1417c56522c90
5
5
  SHA512:
6
- metadata.gz: 1542c660df6a46953df85ed993648afcf28b3a5195560176b528d7f03dd148ad404bbe53e732ea8ac4a0fa6f81cc471e89bb8931da42aa0c181ac93c819f8b36
7
- data.tar.gz: bf4172f41056e08ef86bbcab7a6c56cd2d044d90f18ccd600ac59758ead73abf056283e7b2424771460b6a1ed6fd9a74d0d36ac790986629810d429167d259b6
6
+ metadata.gz: 70d78da8a4bb59a1f917d94b65bc5c7cdb75a16de16220727ef21ae4c03cf0ba7fa7d12a8d4a266af693cc4971c91b78e8327550f0cc254b169c1da76446b012
7
+ data.tar.gz: 33b0aa8435da2e6aa7d9877d1019feb37d9d984a39a2906d6dfd614fc26f75afdb53d1bad0782a558e3d8472b621be76abca53c2fc4df87a2fa7c3a27a8060ee
data/CHANGELOG.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- ## 0.6.0.jhemphill3 07/11/2022
4
+ ## 0.6.0.jhemphill4 07/11/2022
5
5
  * Fixed query tagging for empty queries
6
6
 
7
7
  ## 0.5.2 01/24/2022
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-instrumentation (0.6.0.jhemphill3)
4
+ activerecord-instrumentation (0.6.0.jhemphill4)
5
5
  activerecord
6
6
  opentracing (~> 0.5)
7
7
 
@@ -73,6 +73,8 @@ module ActiveRecord
73
73
  end
74
74
 
75
75
  def tags_for_payload(payload)
76
+ db_config = connection_config(payload[:connection])
77
+
76
78
  {
77
79
  "component" => COMPONENT_NAME,
78
80
  "span.kind" => SPAN_KIND,
@@ -80,7 +82,7 @@ module ActiveRecord
80
82
  "db.cached" => payload.fetch(:cached, false),
81
83
  "db.type" => DB_TYPE,
82
84
  "peer.mysql_db_name" => mysql_db_name_tag(payload.fetch(:connection, nil)&.raw_connection),
83
- "peer.address" => peer_address_tag
85
+ "peer.address" => peer_address_tag(db_config)
84
86
  }.merge(db_statement(payload))
85
87
  end
86
88
 
@@ -110,24 +112,36 @@ module ActiveRecord
110
112
  return nil
111
113
  end
112
114
 
113
- def peer_address_tag
114
- @peer_address_tag ||=
115
- [
116
- "#{connection_config.fetch(:adapter)}://",
117
- connection_config[:username],
118
- connection_config[:host] && "@#{connection_config[:host]}",
119
- "/#{db_instance}"
120
- ].join
115
+ def peer_address_tag(config)
116
+ @peer_address_tag ||= [
117
+ "#{config.fetch(:adapter)}://",
118
+ config[:username],
119
+ config[:host] && "@#{config[:host]}",
120
+ "/#{db_instance}"
121
+ ].join
121
122
  end
122
123
 
123
124
  def db_instance
124
125
  @db_instance ||= connection_config.fetch(:database)
125
126
  end
126
127
 
127
- def connection_config
128
- # Rails 6.2 will deprecate ActiveRecord::Base.connection_config
129
- @connection_config ||=
130
- ActiveRecord::Base.try(:connection_db_config)&.configuration_hash || ActiveRecord::Base.connection_config
128
+ # If a connection is passed in, pull the db config options hash from it. This connection
129
+ # is likely to be attached to the query/query client. Fall back to the application level
130
+ # config. This change will show writer vs reader/replica dbs in spans when it is determined
131
+ # at the query level.
132
+ def connection_config(connection = nil)
133
+ unless defined? @connection_config
134
+ if connection.raw_connection && connection.raw_connection.respond_to?(:query_options)
135
+ # you have a mysql client
136
+ @connection_config = connection.raw_connection.query_options
137
+ else
138
+ # Rails 6.2 will deprecate ActiveRecord::Base.connection_config
139
+ @connection_config = ActiveRecord::Base.try(:connection_db_config)&.configuration_hash ||
140
+ ActiveRecord::Base.connection_config
141
+ end
142
+ end
143
+
144
+ @connection_config
131
145
  end
132
146
  end
133
147
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module OpenTracing
5
- VERSION = "0.6.0.jhemphill3"
5
+ VERSION = "0.6.0.jhemphill4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.jhemphill3
4
+ version: 0.6.0.jhemphill4
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers