instrument_all_the_things 1.0.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +46 -39
  7. data/Rakefile +5 -3
  8. data/instrument_all_the_things.gemspec +4 -3
  9. data/lib/instrument_all_the_things/clients/tracer/blackhole.rb +5 -6
  10. data/lib/instrument_all_the_things/context.rb +1 -1
  11. data/lib/instrument_all_the_things/helpers.rb +5 -2
  12. data/lib/instrument_all_the_things/instrumentors/gc_stats.rb +4 -4
  13. data/lib/instrument_all_the_things/instrumentors/tracing.rb +11 -9
  14. data/lib/instrument_all_the_things/method_instrumentor.rb +1 -1
  15. data/lib/instrument_all_the_things/method_proxy.rb +12 -4
  16. data/lib/instrument_all_the_things/testing/rspec_matchers.rb +16 -12
  17. data/lib/instrument_all_the_things/testing/stat_tracker.rb +13 -12
  18. data/lib/instrument_all_the_things/testing/trace_tracker.rb +1 -1
  19. data/lib/instrument_all_the_things/version.rb +1 -1
  20. data/lib/instrument_all_the_things.rb +30 -5
  21. data/vendor/cache/ast-2.4.2.gem +0 -0
  22. data/vendor/cache/benchmark-ips-2.9.1.gem +0 -0
  23. data/vendor/cache/coderay-1.1.3.gem +0 -0
  24. data/vendor/cache/ddtrace-0.52.0.gem +0 -0
  25. data/vendor/cache/diff-lcs-1.4.4.gem +0 -0
  26. data/vendor/cache/docile-1.4.0.gem +0 -0
  27. data/vendor/cache/dogstatsd-ruby-5.2.0.gem +0 -0
  28. data/vendor/cache/ffi-1.15.4.gem +0 -0
  29. data/vendor/cache/method_source-1.0.0.gem +0 -0
  30. data/vendor/cache/msgpack-1.4.2.gem +0 -0
  31. data/vendor/cache/parallel-1.21.0.gem +0 -0
  32. data/vendor/cache/parser-3.0.2.0.gem +0 -0
  33. data/vendor/cache/pry-0.14.1.gem +0 -0
  34. data/vendor/cache/regexp_parser-2.1.1.gem +0 -0
  35. data/vendor/cache/rexml-3.2.5.gem +0 -0
  36. data/vendor/cache/rspec-3.10.0.gem +0 -0
  37. data/vendor/cache/rspec-core-3.10.1.gem +0 -0
  38. data/vendor/cache/rspec-expectations-3.10.1.gem +0 -0
  39. data/vendor/cache/rspec-mocks-3.10.2.gem +0 -0
  40. data/vendor/cache/rspec-support-3.10.2.gem +0 -0
  41. data/vendor/cache/ruby-progressbar-1.11.0.gem +0 -0
  42. data/vendor/cache/simplecov-0.21.2.gem +0 -0
  43. data/vendor/cache/simplecov-html-0.12.3.gem +0 -0
  44. data/vendor/cache/simplecov_json_formatter-0.1.3.gem +0 -0
  45. data/vendor/cache/unicode-display_width-2.1.0.gem +0 -0
  46. metadata +48 -46
  47. data/vendor/cache/ast-2.4.0.gem +0 -0
  48. data/vendor/cache/benchmark-ips-2.7.2.gem +0 -0
  49. data/vendor/cache/coderay-1.1.2.gem +0 -0
  50. data/vendor/cache/ddtrace-0.34.0.gem +0 -0
  51. data/vendor/cache/diff-lcs-1.3.gem +0 -0
  52. data/vendor/cache/docile-1.3.2.gem +0 -0
  53. data/vendor/cache/dogstatsd-ruby-4.7.0.gem +0 -0
  54. data/vendor/cache/jaro_winkler-1.5.4.gem +0 -0
  55. data/vendor/cache/method_source-0.9.2.gem +0 -0
  56. data/vendor/cache/msgpack-1.3.3.gem +0 -0
  57. data/vendor/cache/parallel-1.19.1.gem +0 -0
  58. data/vendor/cache/parser-2.7.0.2.gem +0 -0
  59. data/vendor/cache/pry-0.12.2.gem +0 -0
  60. data/vendor/cache/rexml-3.2.4.gem +0 -0
  61. data/vendor/cache/rspec-3.9.0.gem +0 -0
  62. data/vendor/cache/rspec-core-3.9.1.gem +0 -0
  63. data/vendor/cache/rspec-expectations-3.9.0.gem +0 -0
  64. data/vendor/cache/rspec-mocks-3.9.1.gem +0 -0
  65. data/vendor/cache/rspec-support-3.9.2.gem +0 -0
  66. data/vendor/cache/rubocop-0.80.0.gem +0 -0
  67. data/vendor/cache/ruby-progressbar-1.10.1.gem +0 -0
  68. data/vendor/cache/simplecov-0.18.1.gem +0 -0
  69. data/vendor/cache/simplecov-html-0.11.0.gem +0 -0
  70. data/vendor/cache/unicode-display_width-1.6.1.gem +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8233c84f173a53f91f896e019fa3ad70cbf0834cc43b3291c341c633099cc13b
4
- data.tar.gz: 71cb7736c90caa59f66e7666eb20d8b3c0a71510c0e0dd2b740ee6f3397174d0
3
+ metadata.gz: 19a589699de098a3b92a317e37a7a901f6d3d90868fd889a41a1c7e04ebaa124
4
+ data.tar.gz: 2f7b79adb14a1ac4fcfc85f8993508d357d6bcd4caa63b9e1f482c95dcf9b85e
5
5
  SHA512:
6
- metadata.gz: 6614358e22371b877b9b79f63807906dcc08560a8585dcaeb985599ef889ef900c60a911ef15a1554749da0d84f0bcc92c4cffa4bd38b7b8ef5c3d0e8dbd3704
7
- data.tar.gz: 8a19bb27f82820e1bb8695355e6e8761c02e3237e0a33c441831a57969d21a7192c96e1ccf92c35fc008d03f075227d1306583ccdbaea352ea9e2dd6a365a063
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/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.1
1
+ 3.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 1.2.0
2
+
3
+ Remove unneeded kwargs option to support Ruby 3.0
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,60 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- instrument_all_the_things (1.0.4)
4
+ instrument_all_the_things (1.3.0)
5
5
  ddtrace
6
6
  dogstatsd-ruby
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.0)
12
- benchmark-ips (2.7.2)
13
- coderay (1.1.2)
14
- ddtrace (0.34.0)
11
+ ast (2.4.2)
12
+ benchmark-ips (2.9.1)
13
+ coderay (1.1.3)
14
+ ddtrace (0.52.0)
15
+ ffi (~> 1.0)
15
16
  msgpack
16
- diff-lcs (1.3)
17
- docile (1.3.2)
18
- dogstatsd-ruby (4.7.0)
19
- jaro_winkler (1.5.4)
20
- method_source (0.9.2)
21
- msgpack (1.3.3)
22
- parallel (1.19.1)
23
- parser (2.7.0.2)
24
- ast (~> 2.4.0)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
17
+ diff-lcs (1.4.4)
18
+ docile (1.4.0)
19
+ dogstatsd-ruby (5.2.0)
20
+ ffi (1.15.4)
21
+ method_source (1.0.0)
22
+ msgpack (1.4.2)
23
+ parallel (1.21.0)
24
+ parser (3.0.2.0)
25
+ ast (~> 2.4.1)
26
+ pry (0.14.1)
27
+ coderay (~> 1.1)
28
+ method_source (~> 1.0)
28
29
  rainbow (3.0.0)
29
30
  rake (10.5.0)
30
- rexml (3.2.4)
31
- rspec (3.9.0)
32
- rspec-core (~> 3.9.0)
33
- rspec-expectations (~> 3.9.0)
34
- rspec-mocks (~> 3.9.0)
35
- rspec-core (3.9.1)
36
- rspec-support (~> 3.9.1)
37
- rspec-expectations (3.9.0)
31
+ regexp_parser (2.1.1)
32
+ rexml (3.2.5)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
38
40
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.9.0)
40
- rspec-mocks (3.9.1)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.2)
41
43
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.9.0)
43
- rspec-support (3.9.2)
44
- rubocop (0.80.0)
45
- jaro_winkler (~> 1.5.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.2)
46
+ rubocop (1.22.0)
46
47
  parallel (~> 1.10)
47
- parser (>= 2.7.0.1)
48
+ parser (>= 3.0.0.0)
48
49
  rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
49
51
  rexml
52
+ rubocop-ast (>= 1.12.0, < 2.0)
50
53
  ruby-progressbar (~> 1.7)
51
- unicode-display_width (>= 1.4.0, < 1.7)
52
- ruby-progressbar (1.10.1)
53
- simplecov (0.18.1)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.12.0)
56
+ parser (>= 3.0.1.1)
57
+ ruby-progressbar (1.11.0)
58
+ simplecov (0.21.2)
54
59
  docile (~> 1.1)
55
- simplecov-html (~> 0.11.0)
56
- simplecov-html (0.11.0)
57
- unicode-display_width (1.6.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov_json_formatter (~> 0.1)
62
+ simplecov-html (0.12.3)
63
+ simplecov_json_formatter (0.1.3)
64
+ unicode-display_width (2.1.0)
58
65
 
59
66
  PLATFORMS
60
67
  ruby
@@ -71,4 +78,4 @@ DEPENDENCIES
71
78
  simplecov
72
79
 
73
80
  BUNDLED WITH
74
- 2.1.4
81
+ 2.2.22
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
@@ -50,6 +50,9 @@ module InstrumentAllTheThings
50
50
 
51
51
  def self.included(other_class)
52
52
  other_class.extend(ClassMethods)
53
+
54
+ InstrumentAllTheThings::MethodProxy.for_class(other_class)
55
+ InstrumentAllTheThings::MethodProxy.for_class(other_class.singleton_class)
53
56
  end
54
57
  end
55
58
  end
@@ -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,24 +6,26 @@ 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|
13
13
  opts = if opts == true
14
- DEFAULT_TRACE_OPTIONS
14
+ DEFAULT_TRACE_OPTIONS.dup
15
15
  else
16
16
  DEFAULT_TRACE_OPTIONS.merge(opts)
17
17
  end
18
18
 
19
+ span_name = opts.delete(:span_name)
20
+
19
21
  proc do |klass, next_blk, actual_code|
20
- InstrumentAllTheThings.tracer.trace(
21
- opts[:span_name],
22
- tags: context[:tags] || {},
23
- service: opts[:service],
24
- resource: opts[:resource] || context.trace_name(klass),
25
- span_type: opts[:span_type]
26
- ) { next_blk.call(klass, actual_code) }
22
+ passed_ops = opts.dup
23
+ passed_ops[:resource] ||= context.trace_name(klass)
24
+ passed_ops[:tags] ||= {}
25
+
26
+ InstrumentAllTheThings.tracer.trace(span_name, passed_ops) do
27
+ next_blk.call(klass, actual_code)
28
+ end
27
29
  end
28
30
  end
29
31
  end
@@ -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,23 +6,24 @@ 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
- define_method(meth) do |*args, **kwargs, &blk|
19
+ define_method(meth) do |*args, &blk|
20
+ opts = args.last.is_a?(Hash) ? args.last : {}
19
21
  @emitted_values[meth][args[0]] << {
20
- args: args[1..-1],
21
- tags: kwargs.fetch(:tags, []),
22
- kwargs: kwargs,
22
+ args: args[1..],
23
+ tags: opts.fetch(:tags, []),
23
24
  }
24
25
 
25
- super(*args, **kwargs, &blk)
26
+ super(*args, &blk)
26
27
  end
27
28
  end
28
29
 
@@ -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.0.4'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -23,13 +23,11 @@ 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
 
30
30
  def stat_reporter
31
- return @stat_reporter if defined?(@stat_reporter)
32
-
33
31
  @stat_reporter ||= Clients::StatReporter::DataDog.new(
34
32
  ENV.fetch('DATADOG_HOST', 'localhost'),
35
33
  ENV.fetch('DATADOG_PORT', 8125),
@@ -54,10 +52,10 @@ module InstrumentAllTheThings
54
52
  timing
55
53
  time
56
54
  ].each do |method_name|
57
- define_method(method_name) do |*args, **kwargs, &blk|
55
+ define_method(method_name) do |*args, &blk|
58
56
  return unless stat_reporter
59
57
 
60
- stat_reporter.public_send(method_name, *args, **kwargs, &blk)
58
+ stat_reporter.public_send(method_name, *args, &blk)
61
59
  end
62
60
  end
63
61
  end
@@ -65,6 +63,33 @@ module InstrumentAllTheThings
65
63
  def self.included(other)
66
64
  other.include(Helpers)
67
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
68
93
  end
69
94
 
70
95
  IATT = InstrumentAllTheThings unless defined?(IATT)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
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.0.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-08 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
  - - ">="
@@ -149,6 +149,7 @@ files:
149
149
  - ".rubocop.yml"
150
150
  - ".ruby-version"
151
151
  - ".travis.yml"
152
+ - CHANGELOG.md
152
153
  - Gemfile
153
154
  - Gemfile.lock
154
155
  - README.md
@@ -173,39 +174,40 @@ files:
173
174
  - lib/instrument_all_the_things/testing/trace_tracker.rb
174
175
  - lib/instrument_all_the_things/version.rb
175
176
  - logo.jpg
176
- - vendor/cache/ast-2.4.0.gem
177
- - vendor/cache/benchmark-ips-2.7.2.gem
178
- - vendor/cache/coderay-1.1.2.gem
179
- - vendor/cache/ddtrace-0.34.0.gem
180
- - vendor/cache/diff-lcs-1.3.gem
181
- - vendor/cache/docile-1.3.2.gem
182
- - vendor/cache/dogstatsd-ruby-4.7.0.gem
183
- - vendor/cache/jaro_winkler-1.5.4.gem
184
- - vendor/cache/method_source-0.9.2.gem
185
- - vendor/cache/msgpack-1.3.3.gem
186
- - vendor/cache/parallel-1.19.1.gem
187
- - vendor/cache/parser-2.7.0.2.gem
188
- - vendor/cache/pry-0.12.2.gem
177
+ - vendor/cache/ast-2.4.2.gem
178
+ - vendor/cache/benchmark-ips-2.9.1.gem
179
+ - vendor/cache/coderay-1.1.3.gem
180
+ - vendor/cache/ddtrace-0.52.0.gem
181
+ - vendor/cache/diff-lcs-1.4.4.gem
182
+ - vendor/cache/docile-1.4.0.gem
183
+ - vendor/cache/dogstatsd-ruby-5.2.0.gem
184
+ - vendor/cache/ffi-1.15.4.gem
185
+ - vendor/cache/method_source-1.0.0.gem
186
+ - vendor/cache/msgpack-1.4.2.gem
187
+ - vendor/cache/parallel-1.21.0.gem
188
+ - vendor/cache/parser-3.0.2.0.gem
189
+ - vendor/cache/pry-0.14.1.gem
189
190
  - vendor/cache/rainbow-3.0.0.gem
190
191
  - vendor/cache/rake-10.5.0.gem
191
- - vendor/cache/rexml-3.2.4.gem
192
- - vendor/cache/rspec-3.9.0.gem
193
- - vendor/cache/rspec-core-3.9.1.gem
194
- - vendor/cache/rspec-expectations-3.9.0.gem
195
- - vendor/cache/rspec-mocks-3.9.1.gem
196
- - vendor/cache/rspec-support-3.9.2.gem
197
- - vendor/cache/rubocop-0.80.0.gem
198
- - vendor/cache/ruby-progressbar-1.10.1.gem
199
- - vendor/cache/simplecov-0.18.1.gem
200
- - vendor/cache/simplecov-html-0.11.0.gem
201
- - vendor/cache/unicode-display_width-1.6.1.gem
192
+ - vendor/cache/regexp_parser-2.1.1.gem
193
+ - vendor/cache/rexml-3.2.5.gem
194
+ - vendor/cache/rspec-3.10.0.gem
195
+ - vendor/cache/rspec-core-3.10.1.gem
196
+ - vendor/cache/rspec-expectations-3.10.1.gem
197
+ - vendor/cache/rspec-mocks-3.10.2.gem
198
+ - vendor/cache/rspec-support-3.10.2.gem
199
+ - vendor/cache/ruby-progressbar-1.11.0.gem
200
+ - vendor/cache/simplecov-0.21.2.gem
201
+ - vendor/cache/simplecov-html-0.12.3.gem
202
+ - vendor/cache/simplecov_json_formatter-0.1.3.gem
203
+ - vendor/cache/unicode-display_width-2.1.0.gem
202
204
  homepage: https://github.com/GetTerminus/instrument-all-the-things
203
205
  licenses: []
204
206
  metadata:
205
207
  allowed_push_host: https://www.rubygems.org
206
208
  homepage_uri: https://github.com/GetTerminus/instrument-all-the-things
207
209
  source_code_uri: https://github.com/GetTerminus/instrument-all-the-things
208
- post_install_message:
210
+ post_install_message:
209
211
  rdoc_options: []
210
212
  require_paths:
211
213
  - lib
@@ -213,15 +215,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
215
  requirements:
214
216
  - - ">="
215
217
  - !ruby/object:Gem::Version
216
- version: '0'
218
+ version: 2.6.0
217
219
  required_rubygems_version: !ruby/object:Gem::Requirement
218
220
  requirements:
219
221
  - - ">="
220
222
  - !ruby/object:Gem::Version
221
223
  version: '0'
222
224
  requirements: []
223
- rubygems_version: 3.0.1
224
- signing_key:
225
+ rubygems_version: 3.2.22
226
+ signing_key:
225
227
  specification_version: 4
226
228
  summary: Make instrumentation with DataDog easy peasy
227
229
  test_files: []
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file