activerecord-instrumentation 0.4.0.jlauer3 → 0.5.1

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: 8198b8d854e91852b7ade88c96b024922a5e26bbb5bcaf7101f15544ab965762
4
- data.tar.gz: 39eb3c1ec55a89e3b49729d64f48c23f4aa8edc4cc41e634f9d06221c8b7e8e9
3
+ metadata.gz: ec1aa8f04a43ddc425d1b75bbb1b36e2a460a40301fa26ab3c231011acb2205a
4
+ data.tar.gz: 584f05b61f5bc532dcdbf65cd08d5e45697994f8dec83ab9c2f85b02175c0b9e
5
5
  SHA512:
6
- metadata.gz: b15c68aae2cc181dd503cd27252dfba14c053cb90f09c1599b5c5a1b5da2ef8d931668a96207f6de328f5f6637c20ae02b8a8f5e49d9d43c8e627d7ca17a7b5a
7
- data.tar.gz: 4e87fadf9dcaeaabb238eeb2453d63d80df1e4030763f46ffd7df4a8d30f5ad942c5297c8a98a45a63cb73310f5e0a54ffda5c8e414351c05141248865be8563
6
+ metadata.gz: 9f4f2a6b39886d381866f1df1e0cd0edd83c39c9f603139948276216e8627cc34a9db7be1a10a8dfdb2df660601f28e291de642a9207ffbfefc78176ca96c570
7
+ data.tar.gz: 38c5ba6648ade1f097333ce41e4b47b6ecca143ad620b96b60cae1d6c68886d10726f96039040826b71b09463fb95ffa620aead8389375777af84d4c71503f78
data/.circleci/config.yml CHANGED
@@ -7,7 +7,7 @@ executors:
7
7
  ruby-latest:
8
8
  resource_class: small
9
9
  docker:
10
- - image: circleci/ruby:latest
10
+ - image: circleci/ruby:2.7
11
11
  environment:
12
12
  BUNDLE_VERSION: "~> 1.17"
13
13
 
@@ -45,7 +45,7 @@ jobs:
45
45
  - v1-bundle-{{ checksum "Gemfile.lock" }}-
46
46
  - run:
47
47
  name: Install Ruby Dependencies
48
- command: bundle check --path=vendor/bundle || bundle install --local --frozen --path=vendor/bundle --jobs=4 --retry=3 && bundle clean
48
+ command: bundle install --path=vendor/bundle # install every time so we don't have to package vendor/bundle with the gem
49
49
  - save_cache:
50
50
  key: v1-bundle-{{ checksum "Gemfile.lock" }}-
51
51
  paths:
@@ -123,4 +123,3 @@ workflows:
123
123
  requires:
124
124
  - gem-build
125
125
  context: artifact_publishing
126
-
data/CHANGELOG.md CHANGED
@@ -1,10 +1,17 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- ## 0.4.0.jlauer3 04/27/2020
4
+ ## 0.5.1 01/20/2022
5
+ * Fixed the publishing process
6
+
7
+ ## 0.5.0 01/18/2022
8
+ * Added db.query_type and db.query_category tags
9
+ * Added forwards compatibility code for the connection_config for rails 6.2
10
+
11
+ ## 0.4.0 04/28/2020
5
12
  * Add SQL sanitizers
6
13
 
7
14
  ## 0.3.0 04/22/2020
8
15
  * Set up build pipeline with circleci and gem-publisher
9
16
  * Fixed linting issues
10
- * Renamed gem to `activerecord-instrumentation`
17
+ * Renamed gem to `activerecord-instrumentation`
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # BEFORE changing this file, read https://wiki.doximity.com/articles/gemfile-maintenance
4
- source "https://artifacts.dox.support/repository/gems"
3
+ source "https://rubygems.org"
5
4
 
6
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,43 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-instrumentation (0.4.0.jlauer3)
4
+ activerecord-instrumentation (0.5.1)
5
5
  activerecord
6
6
  opentracing (~> 0.5)
7
7
 
8
8
  GEM
9
- remote: https://artifacts.dox.support/repository/gems/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.2.2)
12
- activesupport (= 6.0.2.2)
13
- activerecord (6.0.2.2)
14
- activemodel (= 6.0.2.2)
15
- activesupport (= 6.0.2.2)
16
- activesupport (6.0.2.2)
11
+ activemodel (6.1.4.4)
12
+ activesupport (= 6.1.4.4)
13
+ activerecord (6.1.4.4)
14
+ activemodel (= 6.1.4.4)
15
+ activesupport (= 6.1.4.4)
16
+ activesupport (6.1.4.4)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
22
  ast (2.4.0)
23
- concurrent-ruby (1.1.6)
23
+ concurrent-ruby (1.1.9)
24
24
  diff-lcs (1.3)
25
- dox-style (1.3.0)
26
- rubocop (~> 0.77)
27
- rubocop-performance (~> 1.5.1)
28
- rubocop-rails (~> 2.2.0)
29
- rubocop-rspec (~> 1.37.0)
30
- i18n (1.8.2)
25
+ i18n (1.8.11)
31
26
  concurrent-ruby (~> 1.0)
32
27
  jaro_winkler (1.5.4)
33
- minitest (5.14.0)
28
+ minitest (5.15.0)
34
29
  opentracing (0.5.0)
35
30
  opentracing_test_tracer (0.1.1)
36
31
  opentracing
37
32
  parallel (1.19.1)
38
33
  parser (2.7.1.1)
39
34
  ast (~> 2.4.0)
40
- rack (2.2.2)
41
35
  rainbow (3.0.0)
42
36
  rake (13.0.1)
43
37
  rdoc (6.2.1)
@@ -63,22 +57,16 @@ GEM
63
57
  rainbow (>= 2.2.2, < 4.0)
64
58
  ruby-progressbar (~> 1.7)
65
59
  unicode-display_width (>= 1.4.0, < 1.7)
66
- rubocop-performance (1.5.2)
67
- rubocop (>= 0.71.0)
68
- rubocop-rails (2.2.1)
69
- rack (>= 1.1)
70
- rubocop (>= 0.72.0)
71
60
  rubocop-rspec (1.37.1)
72
61
  rubocop (>= 0.68.1)
73
62
  ruby-progressbar (1.10.1)
74
63
  sdoc (1.1.0)
75
64
  rdoc (>= 5.0)
76
65
  sqlite3 (1.4.2)
77
- thread_safe (0.3.6)
78
- tzinfo (1.2.7)
79
- thread_safe (~> 0.1)
66
+ tzinfo (2.0.4)
67
+ concurrent-ruby (~> 1.0)
80
68
  unicode-display_width (1.6.1)
81
- zeitwerk (2.3.0)
69
+ zeitwerk (2.5.3)
82
70
 
83
71
  PLATFORMS
84
72
  ruby
@@ -86,7 +74,6 @@ PLATFORMS
86
74
  DEPENDENCIES
87
75
  activerecord-instrumentation!
88
76
  bundler (~> 1.17)
89
- dox-style
90
77
  opentracing_test_tracer (~> 0.1)
91
78
  rake (~> 13.0)
92
79
  rspec (~> 3.9.0)
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.17"
26
- spec.add_development_dependency "dox-style"
27
26
  spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
28
27
  spec.add_development_dependency "rake", "~> 13.0"
29
28
  spec.add_development_dependency "rspec", "~> 3.9.0"
@@ -8,6 +8,35 @@ module ActiveRecord
8
8
  SPAN_KIND = "client"
9
9
  DB_TYPE = "sql"
10
10
 
11
+ # Used to guess what type of query is running based on the first word of the query
12
+ #
13
+ # Categories are
14
+ # table: Run an action against a table changes the table metadata or configuration
15
+ # read: Read from the database
16
+ # write: Write or delete records to the database
17
+ # unknown: Can't tell the query action from the first word of the query
18
+ # not_found: First word of the query is not in this list
19
+ QUERY_CATEGORIES = {
20
+ alter: "table",
21
+ call: "unknown", # run a subquery
22
+ create: "table",
23
+ delete: "write",
24
+ drop: "table",
25
+ do: "read",
26
+ handler: "table", # table metadata
27
+ import: "write",
28
+ insert: "write",
29
+ load: "write", # covers LOAD XML and LOAD DATA queries
30
+ rename: "table",
31
+ replace: "write", # insert, on duplicate overwrite
32
+ select: "read",
33
+ table: "read", # similar to select
34
+ truncate: "table",
35
+ update: "write",
36
+ values: "unknown", # generates rows to use as a table but doesn't hit the database
37
+ with: "unknown" # sets up subqueries in preparation for other queries
38
+ }
39
+
11
40
  attr_reader :tracer, :sanitizer, :sql_logging_enabled
12
41
 
13
42
  def initialize(tracer, sanitizer: nil, sql_logging_enabled: true)
@@ -54,9 +83,22 @@ module ActiveRecord
54
83
  }.merge(db_statement(payload))
55
84
  end
56
85
 
86
+ # rubocop:disable Metrics/MethodLength
57
87
  def db_statement(payload)
58
- sql_logging_enabled ? { "db.statement" => sanitize_sql(payload.fetch(:sql).squish) } : {}
88
+ if sql_logging_enabled
89
+ query_sql = sanitize_sql(payload.fetch(:sql).squish)
90
+ first_word = query_sql.split.first.downcase
91
+
92
+ {
93
+ "db.statement" => query_sql,
94
+ "db.query_type" => first_word,
95
+ "db.query_category" => QUERY_CATEGORIES[first_word.to_sym] || "not_found"
96
+ }
97
+ else
98
+ {}
99
+ end
59
100
  end
101
+ # rubocop:enable Metrics/MethodLength
60
102
 
61
103
  def sanitize_sql(sql)
62
104
  sanitizer ? sanitizer.sanitize(sql) : sql
@@ -76,7 +118,9 @@ module ActiveRecord
76
118
  end
77
119
 
78
120
  def connection_config
79
- @connection_config ||= ActiveRecord::Base.connection_config
121
+ # Rails 6.2 will deprecate ActiveRecord::Base.connection_config
122
+ @connection_config ||=
123
+ ActiveRecord::Base.try(:connection_db_config)&.configuration_hash || ActiveRecord::Base.connection_config
80
124
  end
81
125
  end
82
126
  end
@@ -19,7 +19,7 @@ module ActiveRecord
19
19
 
20
20
  class << self
21
21
  def build_sanitizer(sanitizer_name)
22
- sanitizer_klass(sanitizer_name).build
22
+ sanitizer_klass(sanitizer_name).new
23
23
  end
24
24
 
25
25
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module OpenTracing
5
- VERSION = "0.4.0.jlauer3"
5
+ VERSION = "0.5.1"
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.4.0.jlauer3
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-28 00:00:00.000000000 Z
12
+ date: 2022-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.17'
28
- - !ruby/object:Gem::Dependency
29
- name: dox-style
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: opentracing_test_tracer
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -223,11 +209,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
209
  version: '0'
224
210
  required_rubygems_version: !ruby/object:Gem::Requirement
225
211
  requirements:
226
- - - ">"
212
+ - - ">="
227
213
  - !ruby/object:Gem::Version
228
- version: 1.3.1
214
+ version: '0'
229
215
  requirements: []
230
- rubygems_version: 3.1.2
216
+ rubygems_version: 3.2.32
231
217
  signing_key:
232
218
  specification_version: 4
233
219
  summary: ActiveRecord OpenTracing intrumenter