instrument_all_the_things 1.2.0 → 1.3.0

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: f94f90a7539a296a29d43cac30fe9766addbe951afd9d1b6334457e167ae9941
4
- data.tar.gz: 91827ee4e9ffb1da8eda1f630f322fa1d20e5ef7183d41352ce8f505405491a4
3
+ metadata.gz: 19a589699de098a3b92a317e37a7a901f6d3d90868fd889a41a1c7e04ebaa124
4
+ data.tar.gz: 2f7b79adb14a1ac4fcfc85f8993508d357d6bcd4caa63b9e1f482c95dcf9b85e
5
5
  SHA512:
6
- metadata.gz: 50a2eeba0febe1f181402c216b42ad8ef91e976cc77acfc107acf78c57eab990cf4e250c16a94de934a23039a88b930c96dd370a59e980a0ccece378eff42f8d
7
- data.tar.gz: a18c47fd122cfc81c950aae89c8595013e451d361dfadeaf1aed56d7768d08835241d59d35b094ee340c75e51adfc7e8e1fcb7459ee75192bda5b66960b8e2bf
6
+ metadata.gz: 6403abcf56557ca5dcd873c3f7133d6947eab41a4a1854cc7d25d8e0b55879478691d5682fa27c54833fa4e750c4893230852bd4edc6c2ac9516f1c2d720fa8d
7
+ data.tar.gz: ced3427628d48fc19f064b93c2647d991e0fbe4eec76e9365d1b7184d171b4c86d06b5d1ad0ac037eee703cc3a0f1d16beea4b13b1c1cd39d7ae6b4ba12c4f32
data/.rubocop.yml CHANGED
@@ -1,4 +1,8 @@
1
+ inherit_from: https://raw.githubusercontent.com/GetTerminus/ruby_shared_configs/master/.rubocop.yml
2
+
3
+
1
4
  AllCops:
5
+ TargetRubyVersion: 2.6
2
6
  Exclude:
3
7
  - Makefile
4
8
  - vendor/**/*
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in instrument_all_the_things.gemspec
4
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- instrument_all_the_things (1.1.1)
4
+ instrument_all_the_things (1.3.0)
5
5
  ddtrace
6
6
  dogstatsd-ruby
7
7
 
@@ -43,16 +43,16 @@ GEM
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
44
  rspec-support (~> 3.10.0)
45
45
  rspec-support (3.10.2)
46
- rubocop (1.21.0)
46
+ rubocop (1.22.0)
47
47
  parallel (~> 1.10)
48
48
  parser (>= 3.0.0.0)
49
49
  rainbow (>= 2.2.2, < 4.0)
50
50
  regexp_parser (>= 1.8, < 3.0)
51
51
  rexml
52
- rubocop-ast (>= 1.9.1, < 2.0)
52
+ rubocop-ast (>= 1.12.0, < 2.0)
53
53
  ruby-progressbar (~> 1.7)
54
54
  unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.11.0)
55
+ rubocop-ast (1.12.0)
56
56
  parser (>= 3.0.1.1)
57
57
  ruby-progressbar (1.11.0)
58
58
  simplecov (0.21.2)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.description = 'Wrappers to make instrumentation of methods easy and pleasant to read'
15
15
  spec.homepage = 'https://github.com/GetTerminus/instrument-all-the-things'
16
16
 
17
- spec.metadata['allowed_push_host'] = "https://www.rubygems.org"
17
+ spec.metadata['allowed_push_host'] = 'https://www.rubygems.org'
18
18
 
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/GetTerminus/instrument-all-the-things'
@@ -28,15 +28,16 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
+ spec.required_ruby_version = '>= 2.6.0'
31
32
 
32
33
  spec.add_dependency 'ddtrace'
33
34
  spec.add_dependency 'dogstatsd-ruby'
34
35
 
36
+ spec.add_development_dependency 'benchmark-ips'
35
37
  spec.add_development_dependency 'bundler', '~> 2.0'
36
38
  spec.add_development_dependency 'pry'
37
39
  spec.add_development_dependency 'rake', '~> 10.0'
38
40
  spec.add_development_dependency 'rspec', '~> 3.0'
39
- spec.add_development_dependency 'simplecov'
40
41
  spec.add_development_dependency 'rubocop'
41
- spec.add_development_dependency 'benchmark-ips'
42
+ spec.add_development_dependency 'simplecov'
42
43
  end
@@ -1,20 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstrumentAllTheThings
2
4
  module Clients
3
5
  class Blackhole
4
6
  class Span
5
- def initialize
6
- end
7
+ def initialize; end
7
8
 
8
- def set_tag(name, value)
9
- end
9
+ def set_tag(name, value); end
10
10
  end
11
11
 
12
-
13
12
  def initialize
14
13
  reset!
15
14
  end
16
15
 
17
- def trace(name, options)
16
+ def trace(_name, _options)
18
17
  yield Span.new
19
18
  end
20
19
  end
@@ -5,7 +5,7 @@ module InstrumentAllTheThings
5
5
  def stats_name(klass_or_instance)
6
6
  @stats_name ||= [
7
7
  class_name(klass_or_instance),
8
- (instance ? 'instance' : 'class') + '_methods',
8
+ "#{instance ? 'instance' : 'class'}_methods",
9
9
  method_name,
10
10
  ].join('.')
11
11
  end
@@ -21,7 +21,7 @@ module InstrumentAllTheThings
21
21
 
22
22
  settings[:context] = Context.new(
23
23
  method_name: method_name,
24
- instance: false
24
+ instance: false,
25
25
  )
26
26
 
27
27
  InstrumentAllTheThings::MethodProxy
@@ -37,7 +37,7 @@ module InstrumentAllTheThings
37
37
 
38
38
  settings[:context] = Context.new(
39
39
  method_name: method_name,
40
- instance: true
40
+ instance: true,
41
41
  )
42
42
 
43
43
  InstrumentAllTheThings::MethodProxy
@@ -7,7 +7,7 @@ module InstrumentAllTheThings
7
7
  total_allocated_pages
8
8
  total_allocated_objects
9
9
  count
10
- ].freeze
10
+ ].freeze,
11
11
  }.freeze
12
12
 
13
13
  # This is to make it easier to spec since other
@@ -19,12 +19,12 @@ module InstrumentAllTheThings
19
19
  DEFAULT_GC_STATS_OPTIONS
20
20
  else
21
21
  DEFAULT_GC_STATS_OPTIONS.merge(opts)
22
- end
22
+ end
23
23
 
24
24
  report_value = proc do |klass, stat_name, value|
25
25
  InstrumentAllTheThings.stat_reporter.histogram(
26
26
  context.stats_name(klass) + ".#{stat_name}_change",
27
- value
27
+ value,
28
28
  )
29
29
  end
30
30
 
@@ -38,7 +38,7 @@ module InstrumentAllTheThings
38
38
  end
39
39
 
40
40
  if (span = InstrumentAllTheThings.tracer.active_span)
41
- span.set_tag('gc_stats', diff)
41
+ span.set_tags(IATT.to_tracer_tags(diff, 'gc_stats'))
42
42
  end
43
43
 
44
44
  diff.each { |s, v| report_value.call(klass, s, v) }
@@ -6,7 +6,7 @@ module InstrumentAllTheThings
6
6
  service: '',
7
7
  span_type: '',
8
8
  tags: {},
9
- span_name: 'method.execution'
9
+ span_name: 'method.execution',
10
10
  }.freeze
11
11
 
12
12
  TRACE_WRAPPER = proc do |opts, context|
@@ -17,7 +17,7 @@ module InstrumentAllTheThings
17
17
  trace: true,
18
18
  gc_stats: true,
19
19
  error_logging: true,
20
- execution_counts_and_timing: true
20
+ execution_counts_and_timing: true,
21
21
  }.freeze
22
22
 
23
23
  attr_accessor :options, :instrumentor
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
4
+
3
5
  require_relative './method_instrumentor'
4
6
 
5
7
  module InstrumentAllTheThings
@@ -22,9 +24,13 @@ module InstrumentAllTheThings
22
24
  end
23
25
 
24
26
  def self.construct_for_class(klass)
25
- Module.new do
27
+ mod = Module.new do
26
28
  extend Instrumentor
27
- end.tap { |m| m._iatt_built_for = klass }
29
+ end
30
+
31
+ mod._iatt_built_for = klass
32
+
33
+ mod
28
34
  end
29
35
 
30
36
  module Instrumentor
@@ -56,8 +62,8 @@ module InstrumentAllTheThings
56
62
  else
57
63
  tag
58
64
  end
59
- rescue StandardError
60
- nil
65
+ rescue StandardError
66
+ nil
61
67
  end.compact
62
68
  end
63
69
 
@@ -75,3 +81,5 @@ module InstrumentAllTheThings
75
81
  end
76
82
  end
77
83
  end
84
+
85
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
4
+
3
5
  module InstrumentAllTheThings
4
6
  module Testing
5
7
  module RSpecMatchers
6
8
  def histogram_value(counter_name)
7
9
  stats = InstrumentAllTheThings.stat_reporter.emitted_values[:histogram][counter_name]
8
- stats.inject(0){|l, n| l + n[:args][0] }
10
+ stats.inject(0) { |l, n| l + n[:args][0] }
9
11
  end
10
12
 
11
13
  def distribution_values(distribution_name, with_tags: nil)
@@ -13,11 +15,11 @@ module InstrumentAllTheThings
13
15
 
14
16
  if with_tags && !stats.empty?
15
17
  stats = stats.select do |s|
16
- with_tags.all?{|t| s[:tags].include?(t) }
18
+ with_tags.all? { |t| s[:tags].include?(t) }
17
19
  end
18
20
  end
19
21
 
20
- stats&.map{|i| i[:args] }&.map(&:first) || []
22
+ stats&.map { |i| i[:args] }&.map(&:first) || []
21
23
  end
22
24
 
23
25
  def histogram_values(histogram_name, with_tags: nil)
@@ -25,11 +27,11 @@ module InstrumentAllTheThings
25
27
 
26
28
  if with_tags && !stats.empty?
27
29
  stats = stats.select do |s|
28
- with_tags.all?{|t| s[:tags].include?(t) }
30
+ with_tags.all? { |t| s[:tags].include?(t) }
29
31
  end
30
32
  end
31
33
 
32
- stats&.map{|i| i[:args] }&.map(&:first) || []
34
+ stats&.map { |i| i[:args] }&.map(&:first) || []
33
35
  end
34
36
 
35
37
  def timing_values(timing_name, with_tags: nil)
@@ -37,11 +39,11 @@ module InstrumentAllTheThings
37
39
 
38
40
  if with_tags && !stats.empty?
39
41
  stats = stats.select do |s|
40
- with_tags.all?{|t| s[:tags].include?(t) }
42
+ with_tags.all? { |t| s[:tags].include?(t) }
41
43
  end
42
44
  end
43
45
 
44
- stats&.map{|i| i[:args] }&.map(&:first) || []
46
+ stats&.map { |i| i[:args] }&.map(&:first) || []
45
47
  end
46
48
 
47
49
  def set_value(counter_name, with_tags: nil)
@@ -49,11 +51,11 @@ module InstrumentAllTheThings
49
51
 
50
52
  if with_tags && !stats.empty?
51
53
  stats = stats.select do |s|
52
- with_tags.all?{|t| s[:tags].include?(t) }
54
+ with_tags.all? { |t| s[:tags].include?(t) }
53
55
  end
54
56
  end
55
57
 
56
- data = stats&.map{|i| i[:args] }&.map(&:first)
58
+ data = stats&.map { |i| i[:args] }&.map(&:first)
57
59
  data ? data.uniq.length : 0
58
60
  end
59
61
 
@@ -62,7 +64,7 @@ module InstrumentAllTheThings
62
64
 
63
65
  if with_tags && !stats.empty?
64
66
  stats = stats.select do |s|
65
- with_tags.all?{|t| s[:tags].include?(t) }
67
+ with_tags.all? { |t| s[:tags].include?(t) }
66
68
  end
67
69
  end
68
70
  stats.last&.fetch(:args)&.first
@@ -72,10 +74,10 @@ module InstrumentAllTheThings
72
74
  stats = InstrumentAllTheThings.stat_reporter.emitted_values[:count][counter_name]
73
75
  if with_tags && !stats.empty?
74
76
  stats = stats.select do |s|
75
- with_tags.all?{|t| s[:tags].include?(t) }
77
+ with_tags.all? { |t| s[:tags].include?(t) }
76
78
  end
77
79
  end
78
- stats.inject(0){|l, n| l + n[:args][0] }
80
+ stats.inject(0) { |l, n| l + n[:args][0] }
79
81
  end
80
82
 
81
83
  def flush_traces
@@ -95,3 +97,5 @@ module InstrumentAllTheThings
95
97
  end
96
98
  end
97
99
  end
100
+
101
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -6,19 +6,20 @@ module InstrumentAllTheThings
6
6
  module Testing
7
7
  class StatTracker < Clients::StatReporter::DataDog
8
8
  attr_reader :emitted_values
9
+
9
10
  %i[
10
- count
11
- distribution
12
- gauge
13
- histogram
14
- set
15
- time
16
- timing
11
+ count
12
+ distribution
13
+ gauge
14
+ histogram
15
+ set
16
+ time
17
+ timing
17
18
  ].each do |meth|
18
19
  define_method(meth) do |*args, &blk|
19
20
  opts = args.last.is_a?(Hash) ? args.last : {}
20
21
  @emitted_values[meth][args[0]] << {
21
- args: args[1..-1],
22
+ args: args[1..],
22
23
  tags: opts.fetch(:tags, []),
23
24
  }
24
25
 
@@ -18,7 +18,7 @@ module InstrumentAllTheThings
18
18
  end
19
19
 
20
20
  def <<(val)
21
- @traces = @traces.concat(MessagePack.load(val[:body]).flatten)
21
+ @traces.concat(MessagePack.load(val[:body]).flatten)
22
22
  end
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstrumentAllTheThings
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -23,7 +23,7 @@ module InstrumentAllTheThings
23
23
  App.logger
24
24
  else
25
25
  require 'logger'
26
- Logger.new(STDOUT)
26
+ Logger.new($stdout)
27
27
  end
28
28
  end
29
29
 
@@ -63,6 +63,33 @@ module InstrumentAllTheThings
63
63
  def self.included(other)
64
64
  other.include(Helpers)
65
65
  end
66
+
67
+ def self.tag_active_span(tag_name, tag_value)
68
+ tracer&.active_span&.set_tags(to_tracer_tags(tag_name => tag_value))
69
+ end
70
+
71
+ def self.tag_active_root_span(tag_name, tag_value)
72
+ tracer&.active_span&.set_tags(to_tracer_tags(tag_name => tag_value))
73
+ end
74
+
75
+ def self.to_tracer_tags(hsh, prefix = nil)
76
+ hsh.each_with_object({}) do |(hash_key, value), acc|
77
+ key = prefix ? "#{prefix}.#{hash_key}" : hash_key
78
+
79
+ case value
80
+ when Hash
81
+ acc.merge!(to_tracer_tags(value, key))
82
+ when Array
83
+ content = value.each_with_index.each_with_object({}) do |(item, index), reformed|
84
+ reformed[index] = item
85
+ end
86
+
87
+ acc.merge!(to_tracer_tags(content, key))
88
+ else
89
+ acc[key] = value
90
+ end
91
+ end
92
+ end
66
93
  end
67
94
 
68
95
  IATT = InstrumentAllTheThings unless defined?(IATT)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrument_all_the_things
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-20 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddtrace
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: benchmark-ips
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +108,6 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3.0'
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: benchmark-ips
126
+ name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -196,8 +196,6 @@ files:
196
196
  - vendor/cache/rspec-expectations-3.10.1.gem
197
197
  - vendor/cache/rspec-mocks-3.10.2.gem
198
198
  - vendor/cache/rspec-support-3.10.2.gem
199
- - vendor/cache/rubocop-1.21.0.gem
200
- - vendor/cache/rubocop-ast-1.11.0.gem
201
199
  - vendor/cache/ruby-progressbar-1.11.0.gem
202
200
  - vendor/cache/simplecov-0.21.2.gem
203
201
  - vendor/cache/simplecov-html-0.12.3.gem
@@ -217,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
215
  requirements:
218
216
  - - ">="
219
217
  - !ruby/object:Gem::Version
220
- version: '0'
218
+ version: 2.6.0
221
219
  required_rubygems_version: !ruby/object:Gem::Requirement
222
220
  requirements:
223
221
  - - ">="
Binary file
Binary file