instrument_all_the_things 1.1.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yaml +21 -0
  3. data/.github/workflows/test.yaml +31 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-yml +91 -0
  6. data/.rubocop.yml +4 -0
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +7 -0
  9. data/Gemfile +3 -1
  10. data/Gemfile.lock +49 -42
  11. data/Rakefile +5 -3
  12. data/instrument_all_the_things.gemspec +5 -4
  13. data/lib/instrument_all_the_things/clients/tracer/blackhole.rb +5 -6
  14. data/lib/instrument_all_the_things/context.rb +1 -1
  15. data/lib/instrument_all_the_things/helpers.rb +2 -2
  16. data/lib/instrument_all_the_things/instrumentors/gc_stats.rb +4 -4
  17. data/lib/instrument_all_the_things/instrumentors/tracing.rb +1 -1
  18. data/lib/instrument_all_the_things/method_instrumentor.rb +1 -1
  19. data/lib/instrument_all_the_things/method_proxy.rb +12 -4
  20. data/lib/instrument_all_the_things/testing/rspec_matchers.rb +16 -12
  21. data/lib/instrument_all_the_things/testing/stat_tracker.rb +13 -12
  22. data/lib/instrument_all_the_things/testing/trace_tracker.rb +1 -1
  23. data/lib/instrument_all_the_things/version.rb +1 -1
  24. data/lib/instrument_all_the_things.rb +30 -5
  25. data/vendor/cache/ast-2.4.2.gem +0 -0
  26. data/vendor/cache/benchmark-ips-2.10.0.gem +0 -0
  27. data/vendor/cache/coderay-1.1.3.gem +0 -0
  28. data/vendor/cache/ddtrace-0.54.2.gem +0 -0
  29. data/vendor/cache/debase-ruby_core_source-0.10.14.gem +0 -0
  30. data/vendor/cache/diff-lcs-1.5.0.gem +0 -0
  31. data/vendor/cache/docile-1.4.0.gem +0 -0
  32. data/vendor/cache/dogstatsd-ruby-5.5.0.gem +0 -0
  33. data/vendor/cache/method_source-1.0.0.gem +0 -0
  34. data/vendor/cache/msgpack-1.5.2.gem +0 -0
  35. data/vendor/cache/parallel-1.22.1.gem +0 -0
  36. data/vendor/cache/parser-3.1.2.0.gem +0 -0
  37. data/vendor/cache/pry-0.14.1.gem +0 -0
  38. data/vendor/cache/rainbow-3.1.1.gem +0 -0
  39. data/vendor/cache/regexp_parser-2.5.0.gem +0 -0
  40. data/vendor/cache/rexml-3.2.5.gem +0 -0
  41. data/vendor/cache/rspec-3.11.0.gem +0 -0
  42. data/vendor/cache/rspec-core-3.11.0.gem +0 -0
  43. data/vendor/cache/rspec-expectations-3.11.0.gem +0 -0
  44. data/vendor/cache/rspec-mocks-3.11.1.gem +0 -0
  45. data/vendor/cache/rspec-support-3.11.0.gem +0 -0
  46. data/vendor/cache/rubocop-1.30.1.gem +0 -0
  47. data/vendor/cache/rubocop-ast-1.18.0.gem +0 -0
  48. data/vendor/cache/ruby-progressbar-1.11.0.gem +0 -0
  49. data/vendor/cache/simplecov-0.21.2.gem +0 -0
  50. data/vendor/cache/simplecov-html-0.12.3.gem +0 -0
  51. data/vendor/cache/simplecov_json_formatter-0.1.4.gem +0 -0
  52. data/vendor/cache/unicode-display_width-2.1.0.gem +0 -0
  53. metadata +56 -50
  54. data/.drone.yml +0 -14
  55. data/vendor/cache/ast-2.4.0.gem +0 -0
  56. data/vendor/cache/benchmark-ips-2.7.2.gem +0 -0
  57. data/vendor/cache/coderay-1.1.2.gem +0 -0
  58. data/vendor/cache/ddtrace-0.34.2.gem +0 -0
  59. data/vendor/cache/diff-lcs-1.3.gem +0 -0
  60. data/vendor/cache/docile-1.3.2.gem +0 -0
  61. data/vendor/cache/dogstatsd-ruby-4.7.0.gem +0 -0
  62. data/vendor/cache/jaro_winkler-1.5.4.gem +0 -0
  63. data/vendor/cache/method_source-0.9.2.gem +0 -0
  64. data/vendor/cache/msgpack-1.3.3.gem +0 -0
  65. data/vendor/cache/parallel-1.19.1.gem +0 -0
  66. data/vendor/cache/parser-2.7.0.2.gem +0 -0
  67. data/vendor/cache/pry-0.12.2.gem +0 -0
  68. data/vendor/cache/rainbow-3.0.0.gem +0 -0
  69. data/vendor/cache/rexml-3.2.4.gem +0 -0
  70. data/vendor/cache/rspec-3.9.0.gem +0 -0
  71. data/vendor/cache/rspec-core-3.9.1.gem +0 -0
  72. data/vendor/cache/rspec-expectations-3.9.0.gem +0 -0
  73. data/vendor/cache/rspec-mocks-3.9.1.gem +0 -0
  74. data/vendor/cache/rspec-support-3.9.2.gem +0 -0
  75. data/vendor/cache/rubocop-0.80.0.gem +0 -0
  76. data/vendor/cache/ruby-progressbar-1.10.1.gem +0 -0
  77. data/vendor/cache/simplecov-0.18.1.gem +0 -0
  78. data/vendor/cache/simplecov-html-0.11.0.gem +0 -0
  79. 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: cec4e44eca4faaa307a125d4bf90f55059ab93ba947fd2febb6f3b7cde27aee7
4
- data.tar.gz: 849f7d9a971efc7329c8d4b998770935c7b4d0a91f53c6e27a447a5a1828dbc6
3
+ metadata.gz: 5fc79ef6d04b8966c22b1d9158f2f1449f9334ae6b4b02c1b64bed6469fe6b32
4
+ data.tar.gz: 9f6d5c20142cf0d9dad511b7b5c6f343ba6cb3ad6287235e4088fd50fea064be
5
5
  SHA512:
6
- metadata.gz: 67cd0dd88165297532c4c88eabca252d3302c51c67d38f6a4de75761936945dc5021b9b145897a39d0da02899501a1d893314fdfabba3a10129fbd5164cd1315
7
- data.tar.gz: 66309b014384610db04fccc8171b94c261bad0ada11f4014fe44a010e7e13fed444219b07d8e1345de6b2f95ce179944e12d5a042cd335cf90b177a8eb1a482b
6
+ metadata.gz: d3f3fa2403610b3d04e52187fa2ee1bc66d1e432d335ba0726e043a44cf32a1a40562f9d32fe3cf93326a40dd38c1e7065b07eac079a8b99122e9d77bc7a2449
7
+ data.tar.gz: 11c5567e0254aebcf3520a41c0bd8584e51145a7b7fe37fdfda35f669c3946b916a934bee3338da40b057a59102cc27dcda9b32469a84fb7c3bdac3419cbcc70
@@ -0,0 +1,21 @@
1
+ name: 'Lint'
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ run-rubocop:
7
+ name: Lint code
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ rubyVersion: ["2.7.6"]
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.rubyVersion }}
18
+ bundler-cache: true
19
+ cache-version: "${{ matrix.rubyVersion }}-0"
20
+ - name: Run RuboCop
21
+ run: bundle exec rubocop
@@ -0,0 +1,31 @@
1
+ name: Test
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ run-tests:
7
+ name: Test code
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - 3.1.2
14
+ - 3.0.4
15
+ - 2.7.6
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ cache-version: ${{ matrix.ruby }}-0
23
+ - name: Run RSpec
24
+ env:
25
+ CI: true
26
+ run: bundle exec rspec
27
+ - name: Coveralls
28
+ uses: coverallsapp/github-action@v1.1.2
29
+ continue-on-error: true
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
  .DS_Store
13
13
  .vscode
14
+
15
+ instrument_all_the_things*.gem
@@ -0,0 +1,91 @@
1
+ AllCops:
2
+ Exclude:
3
+ - Makefile
4
+ - vendor/**/*
5
+ - bin/**/*
6
+
7
+ Layout/EndOfLine:
8
+ Enabled: false
9
+
10
+ Style/DateTime:
11
+ Enabled: false
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Lint/Debugger:
17
+ Enabled: true
18
+
19
+ Style/FrozenStringLiteralComment:
20
+ Enabled: true
21
+ EnforcedStyle: always
22
+
23
+ Style/TrailingCommaInHashLiteral:
24
+ Enabled: true
25
+ EnforcedStyleForMultiline: comma
26
+
27
+ Style/TrailingCommaInArrayLiteral:
28
+ Enabled: true
29
+ EnforcedStyleForMultiline: comma
30
+
31
+ Style/TrailingCommaInArguments:
32
+ Enabled: true
33
+ EnforcedStyleForMultiline: comma
34
+
35
+ Lint/UnusedMethodArgument:
36
+ AllowUnusedKeywordArguments: true
37
+
38
+ Layout/LineLength:
39
+ Enabled: true
40
+ Max: 280
41
+ IgnoreCopDirectives: true
42
+ IgnoredPatterns: ['\A#', '\A\s*sig { .* }\Z']
43
+ Exclude:
44
+ - '**/*_pb.rb'
45
+
46
+ Metrics/AbcSize:
47
+ Enabled: true
48
+ Max: 48
49
+
50
+ Metrics/CyclomaticComplexity:
51
+ Max: 9
52
+
53
+ Metrics/MethodLength:
54
+ Enabled: true
55
+ Max: 32
56
+
57
+ Layout/ParameterAlignment:
58
+ Enabled: true
59
+ EnforcedStyle: with_fixed_indentation
60
+
61
+ Naming/MethodParameterName:
62
+ Enabled: true
63
+ AllowedNames: ['io', 'id', 'to', 'by', 'on', 'in', 'at', '_'] # Defaults + _
64
+
65
+ Layout/MultilineMethodCallIndentation:
66
+ Enabled: true
67
+ EnforcedStyle: indented
68
+
69
+ Style/ParallelAssignment:
70
+ Enabled: true
71
+
72
+ Metrics/ClassLength:
73
+ Max: 240
74
+
75
+ Metrics/BlockLength:
76
+ Max: 30
77
+ Exclude:
78
+ - spec/**/*.rb
79
+ - '**/*_pb.rb'
80
+
81
+ Metrics/ParameterLists:
82
+ Max: 6
83
+
84
+ Lint/AmbiguousBlockAssociation:
85
+ Exclude:
86
+ - spec/**/*.rb
87
+
88
+ Style/BlockDelimiters:
89
+ Enabled: true
90
+ Exclude:
91
+ - spec/**/*
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.7
2
6
  Exclude:
3
7
  - Makefile
4
8
  - vendor/**/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.1
1
+ 2.7.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # 1.3.1
2
+
3
+ Lock to compatible versions of ddtrace. We'll need to cut a new version of this for ddtrace >= 1.
4
+
5
+ # 1.2.0
6
+
7
+ 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.1.1)
5
- ddtrace
4
+ instrument_all_the_things (1.3.0)
5
+ ddtrace (< 1)
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.2)
11
+ ast (2.4.2)
12
+ benchmark-ips (2.10.0)
13
+ coderay (1.1.3)
14
+ ddtrace (0.54.2)
15
+ debase-ruby_core_source (<= 0.10.14)
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)
28
- rainbow (3.0.0)
17
+ debase-ruby_core_source (0.10.14)
18
+ diff-lcs (1.5.0)
19
+ docile (1.4.0)
20
+ dogstatsd-ruby (5.5.0)
21
+ method_source (1.0.0)
22
+ msgpack (1.5.2)
23
+ parallel (1.22.1)
24
+ parser (3.1.2.0)
25
+ ast (~> 2.4.1)
26
+ pry (0.14.1)
27
+ coderay (~> 1.1)
28
+ method_source (~> 1.0)
29
+ rainbow (3.1.1)
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.5.0)
32
+ rexml (3.2.5)
33
+ rspec (3.11.0)
34
+ rspec-core (~> 3.11.0)
35
+ rspec-expectations (~> 3.11.0)
36
+ rspec-mocks (~> 3.11.0)
37
+ rspec-core (3.11.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-expectations (3.11.0)
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.11.0)
42
+ rspec-mocks (3.11.1)
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.11.0)
45
+ rspec-support (3.11.0)
46
+ rubocop (1.30.1)
46
47
  parallel (~> 1.10)
47
- parser (>= 2.7.0.1)
48
+ parser (>= 3.1.0.0)
48
49
  rainbow (>= 2.2.2, < 4.0)
49
- rexml
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.18.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.18.0)
56
+ parser (>= 3.1.1.0)
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.4)
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.3.12
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 = Gem::Requirement.new('>= 2.7.0')
31
32
 
32
- spec.add_dependency 'ddtrace'
33
+ spec.add_dependency 'ddtrace', '< 1'
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,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.1.1'
4
+ VERSION = '1.3.1'
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
Binary file
Binary file
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrument_all_the_things
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.3.1
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-20 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddtrace
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dogstatsd-ruby
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -25,13 +39,13 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: dogstatsd-ruby
42
+ name: benchmark-ips
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :runtime
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -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
  - - ">="
@@ -143,12 +143,15 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".drone.yml"
146
+ - ".github/workflows/lint.yaml"
147
+ - ".github/workflows/test.yaml"
147
148
  - ".gitignore"
148
149
  - ".rspec"
150
+ - ".rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-yml"
149
151
  - ".rubocop.yml"
150
152
  - ".ruby-version"
151
153
  - ".travis.yml"
154
+ - CHANGELOG.md
152
155
  - Gemfile
153
156
  - Gemfile.lock
154
157
  - README.md
@@ -173,39 +176,42 @@ files:
173
176
  - lib/instrument_all_the_things/testing/trace_tracker.rb
174
177
  - lib/instrument_all_the_things/version.rb
175
178
  - 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.2.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
189
- - vendor/cache/rainbow-3.0.0.gem
179
+ - vendor/cache/ast-2.4.2.gem
180
+ - vendor/cache/benchmark-ips-2.10.0.gem
181
+ - vendor/cache/coderay-1.1.3.gem
182
+ - vendor/cache/ddtrace-0.54.2.gem
183
+ - vendor/cache/debase-ruby_core_source-0.10.14.gem
184
+ - vendor/cache/diff-lcs-1.5.0.gem
185
+ - vendor/cache/docile-1.4.0.gem
186
+ - vendor/cache/dogstatsd-ruby-5.5.0.gem
187
+ - vendor/cache/method_source-1.0.0.gem
188
+ - vendor/cache/msgpack-1.5.2.gem
189
+ - vendor/cache/parallel-1.22.1.gem
190
+ - vendor/cache/parser-3.1.2.0.gem
191
+ - vendor/cache/pry-0.14.1.gem
192
+ - vendor/cache/rainbow-3.1.1.gem
190
193
  - 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
194
+ - vendor/cache/regexp_parser-2.5.0.gem
195
+ - vendor/cache/rexml-3.2.5.gem
196
+ - vendor/cache/rspec-3.11.0.gem
197
+ - vendor/cache/rspec-core-3.11.0.gem
198
+ - vendor/cache/rspec-expectations-3.11.0.gem
199
+ - vendor/cache/rspec-mocks-3.11.1.gem
200
+ - vendor/cache/rspec-support-3.11.0.gem
201
+ - vendor/cache/rubocop-1.30.1.gem
202
+ - vendor/cache/rubocop-ast-1.18.0.gem
203
+ - vendor/cache/ruby-progressbar-1.11.0.gem
204
+ - vendor/cache/simplecov-0.21.2.gem
205
+ - vendor/cache/simplecov-html-0.12.3.gem
206
+ - vendor/cache/simplecov_json_formatter-0.1.4.gem
207
+ - vendor/cache/unicode-display_width-2.1.0.gem
202
208
  homepage: https://github.com/GetTerminus/instrument-all-the-things
203
209
  licenses: []
204
210
  metadata:
205
211
  allowed_push_host: https://www.rubygems.org
206
212
  homepage_uri: https://github.com/GetTerminus/instrument-all-the-things
207
213
  source_code_uri: https://github.com/GetTerminus/instrument-all-the-things
208
- post_install_message:
214
+ post_install_message:
209
215
  rdoc_options: []
210
216
  require_paths:
211
217
  - lib
@@ -213,15 +219,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
219
  requirements:
214
220
  - - ">="
215
221
  - !ruby/object:Gem::Version
216
- version: '0'
222
+ version: 2.7.0
217
223
  required_rubygems_version: !ruby/object:Gem::Requirement
218
224
  requirements:
219
225
  - - ">="
220
226
  - !ruby/object:Gem::Version
221
227
  version: '0'
222
228
  requirements: []
223
- rubygems_version: 3.0.6
224
- signing_key:
229
+ rubygems_version: 3.1.6
230
+ signing_key:
225
231
  specification_version: 4
226
232
  summary: Make instrumentation with DataDog easy peasy
227
233
  test_files: []
data/.drone.yml DELETED
@@ -1,14 +0,0 @@
1
- kind: pipeline
2
- name: default
3
-
4
- steps:
5
- - name: test-ruby
6
- image: getterminus/ruby-ci-image:2.6-je-20190205
7
- group: bundler
8
- volumes:
9
- - name: bundledir
10
- path: /usr/local/bundle
11
- commands:
12
- - bundle check --path=/usr/local/bundle || bundle --local --path=/usr/local/bundle
13
- - bundle exec rspec
14
-
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
Binary file