instrument_all_the_things 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) 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/Gemfile +3 -1
  9. data/Gemfile.lock +44 -34
  10. data/README.md +1 -1
  11. data/Rakefile +5 -3
  12. data/instrument_all_the_things.gemspec +7 -6
  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 +2 -3
  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 +17 -13
  21. data/lib/instrument_all_the_things/testing/stat_tracker.rb +9 -8
  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 +25 -4
  25. data/vendor/cache/benchmark-ips-2.10.0.gem +0 -0
  26. data/vendor/cache/ddtrace-1.2.0.gem +0 -0
  27. data/vendor/cache/debase-ruby_core_source-0.10.16.gem +0 -0
  28. data/vendor/cache/diff-lcs-1.5.0.gem +0 -0
  29. data/vendor/cache/dogstatsd-ruby-5.5.0.gem +0 -0
  30. data/vendor/cache/ffi-1.15.5.gem +0 -0
  31. data/vendor/cache/json-2.6.2.gem +0 -0
  32. data/vendor/cache/libddprof-0.6.0.1.0.gem +0 -0
  33. data/vendor/cache/libddwaf-1.3.0.2.0-x86_64-darwin.gem +0 -0
  34. data/vendor/cache/libddwaf-1.3.0.2.0.gem +0 -0
  35. data/vendor/cache/msgpack-1.5.3.gem +0 -0
  36. data/vendor/cache/parallel-1.22.1.gem +0 -0
  37. data/vendor/cache/parser-3.1.2.0.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/rspec-3.11.0.gem +0 -0
  41. data/vendor/cache/rspec-core-3.11.0.gem +0 -0
  42. data/vendor/cache/rspec-expectations-3.11.0.gem +0 -0
  43. data/vendor/cache/rspec-mocks-3.11.1.gem +0 -0
  44. data/vendor/cache/rspec-support-3.11.0.gem +0 -0
  45. data/vendor/cache/rubocop-1.31.2.gem +0 -0
  46. data/vendor/cache/rubocop-ast-1.19.1.gem +0 -0
  47. data/vendor/cache/simplecov_json_formatter-0.1.4.gem +0 -0
  48. data/vendor/cache/unicode-display_width-2.2.0.gem +0 -0
  49. metadata +51 -44
  50. data/.drone.yml +0 -14
  51. data/vendor/cache/benchmark-ips-2.9.1.gem +0 -0
  52. data/vendor/cache/ddtrace-0.52.0.gem +0 -0
  53. data/vendor/cache/diff-lcs-1.4.4.gem +0 -0
  54. data/vendor/cache/dogstatsd-ruby-5.2.0.gem +0 -0
  55. data/vendor/cache/ffi-1.15.4.gem +0 -0
  56. data/vendor/cache/msgpack-1.4.2.gem +0 -0
  57. data/vendor/cache/parallel-1.21.0.gem +0 -0
  58. data/vendor/cache/parser-3.0.2.0.gem +0 -0
  59. data/vendor/cache/rainbow-3.0.0.gem +0 -0
  60. data/vendor/cache/regexp_parser-2.1.1.gem +0 -0
  61. data/vendor/cache/rspec-3.10.0.gem +0 -0
  62. data/vendor/cache/rspec-core-3.10.1.gem +0 -0
  63. data/vendor/cache/rspec-expectations-3.10.1.gem +0 -0
  64. data/vendor/cache/rspec-mocks-3.10.2.gem +0 -0
  65. data/vendor/cache/rspec-support-3.10.2.gem +0 -0
  66. data/vendor/cache/rubocop-1.21.0.gem +0 -0
  67. data/vendor/cache/rubocop-ast-1.11.0.gem +0 -0
  68. data/vendor/cache/simplecov_json_formatter-0.1.3.gem +0 -0
  69. data/vendor/cache/unicode-display_width-2.1.0.gem +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f94f90a7539a296a29d43cac30fe9766addbe951afd9d1b6334457e167ae9941
4
- data.tar.gz: 91827ee4e9ffb1da8eda1f630f322fa1d20e5ef7183d41352ce8f505405491a4
3
+ metadata.gz: a3a50b9bc4c51ea31e154997452b4690b59f2003a44ff0afa8ccd7fca8cb486f
4
+ data.tar.gz: 4ab7a859a0e6010506e81048ab5b5b432ed359cd53ad357b3f10b61350770f9e
5
5
  SHA512:
6
- metadata.gz: 50a2eeba0febe1f181402c216b42ad8ef91e976cc77acfc107acf78c57eab990cf4e250c16a94de934a23039a88b930c96dd370a59e980a0ccece378eff42f8d
7
- data.tar.gz: a18c47fd122cfc81c950aae89c8595013e451d361dfadeaf1aed56d7768d08835241d59d35b094ee340c75e51adfc7e8e1fcb7459ee75192bda5b66960b8e2bf
6
+ metadata.gz: f22311591588a7cf97f9b64441cda02438f4c23ee8a6100a124d8219935971da7753caed4b3ffd311cbddeb530625a9c2973a4772dfef253f0b0b817eab152a6
7
+ data.tar.gz: 54a7851c25d79b3ffcf596011c63cb101a83ee1fbf00d2f2acf6f49f5145d2eb67c6299b1c0b7c6ad60ef7d2bc99be64c0c515d2a6ed801c7443297c71c6847f
@@ -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
- 3.0.2
1
+ 3.1.2
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,67 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- instrument_all_the_things (1.1.1)
5
- ddtrace
6
- dogstatsd-ruby
4
+ instrument_all_the_things (2.0.0)
5
+ ddtrace (~> 1.2.0)
6
+ dogstatsd-ruby (~> 5.5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.2)
12
- benchmark-ips (2.9.1)
12
+ benchmark-ips (2.10.0)
13
13
  coderay (1.1.3)
14
- ddtrace (0.52.0)
15
- ffi (~> 1.0)
14
+ ddtrace (1.2.0)
15
+ debase-ruby_core_source (= 0.10.16)
16
+ libddprof (~> 0.6.0.1.0)
17
+ libddwaf (~> 1.3.0.2.0)
16
18
  msgpack
17
- diff-lcs (1.4.4)
19
+ debase-ruby_core_source (0.10.16)
20
+ diff-lcs (1.5.0)
18
21
  docile (1.4.0)
19
- dogstatsd-ruby (5.2.0)
20
- ffi (1.15.4)
22
+ dogstatsd-ruby (5.5.0)
23
+ ffi (1.15.5)
24
+ json (2.6.2)
25
+ libddprof (0.6.0.1.0)
26
+ libddwaf (1.3.0.2.0)
27
+ ffi (~> 1.0)
28
+ libddwaf (1.3.0.2.0-x86_64-darwin)
29
+ ffi (~> 1.0)
21
30
  method_source (1.0.0)
22
- msgpack (1.4.2)
23
- parallel (1.21.0)
24
- parser (3.0.2.0)
31
+ msgpack (1.5.3)
32
+ parallel (1.22.1)
33
+ parser (3.1.2.0)
25
34
  ast (~> 2.4.1)
26
35
  pry (0.14.1)
27
36
  coderay (~> 1.1)
28
37
  method_source (~> 1.0)
29
- rainbow (3.0.0)
38
+ rainbow (3.1.1)
30
39
  rake (10.5.0)
31
- regexp_parser (2.1.1)
40
+ regexp_parser (2.5.0)
32
41
  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)
42
+ rspec (3.11.0)
43
+ rspec-core (~> 3.11.0)
44
+ rspec-expectations (~> 3.11.0)
45
+ rspec-mocks (~> 3.11.0)
46
+ rspec-core (3.11.0)
47
+ rspec-support (~> 3.11.0)
48
+ rspec-expectations (3.11.0)
40
49
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.10.0)
42
- rspec-mocks (3.10.2)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-mocks (3.11.1)
43
52
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-support (3.10.2)
46
- rubocop (1.21.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-support (3.11.0)
55
+ rubocop (1.31.2)
56
+ json (~> 2.3)
47
57
  parallel (~> 1.10)
48
- parser (>= 3.0.0.0)
58
+ parser (>= 3.1.0.0)
49
59
  rainbow (>= 2.2.2, < 4.0)
50
60
  regexp_parser (>= 1.8, < 3.0)
51
- rexml
52
- rubocop-ast (>= 1.9.1, < 2.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.18.0, < 2.0)
53
63
  ruby-progressbar (~> 1.7)
54
64
  unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.11.0)
56
- parser (>= 3.0.1.1)
65
+ rubocop-ast (1.19.1)
66
+ parser (>= 3.1.1.0)
57
67
  ruby-progressbar (1.11.0)
58
68
  simplecov (0.21.2)
59
69
  docile (~> 1.1)
60
70
  simplecov-html (~> 0.11)
61
71
  simplecov_json_formatter (~> 0.1)
62
72
  simplecov-html (0.12.3)
63
- simplecov_json_formatter (0.1.3)
64
- unicode-display_width (2.1.0)
73
+ simplecov_json_formatter (0.1.4)
74
+ unicode-display_width (2.2.0)
65
75
 
66
76
  PLATFORMS
67
77
  ruby
@@ -78,4 +88,4 @@ DEPENDENCIES
78
88
  simplecov
79
89
 
80
90
  BUNDLED WITH
81
- 2.2.22
91
+ 2.3.12
data/README.md CHANGED
@@ -129,7 +129,7 @@ require 'instrument_all_the_things/testing/trace_tracker'
129
129
  require 'instrument_all_the_things/testing/rspec_matchers'
130
130
 
131
131
  Datadog.configure do |c|
132
- c.tracer transport_options: proc { |t|
132
+ c.tracing.transport_options = proc { |t|
133
133
  t.adapter :test, IATT::Testing::TraceTracker.new
134
134
  }
135
135
  end
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'
@@ -23,20 +23,21 @@ Gem::Specification.new do |spec|
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
25
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|Gemfile.lock)/}) }
27
27
  end
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 'dogstatsd-ruby'
33
+ spec.add_dependency 'ddtrace', '~> 1.2.0'
34
+ spec.add_dependency 'dogstatsd-ruby', '~> 5.5.0'
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) }
@@ -3,10 +3,9 @@
3
3
  module InstrumentAllTheThings
4
4
  module Instrumentors
5
5
  DEFAULT_TRACE_OPTIONS = {
6
- service: '',
7
6
  span_type: '',
8
7
  tags: {},
9
- span_name: 'method.execution'
8
+ span_name: 'method.execution',
10
9
  }.freeze
11
10
 
12
11
  TRACE_WRAPPER = proc do |opts, context|
@@ -23,7 +22,7 @@ module InstrumentAllTheThings
23
22
  passed_ops[:resource] ||= context.trace_name(klass)
24
23
  passed_ops[:tags] ||= {}
25
24
 
26
- InstrumentAllTheThings.tracer.trace(span_name, passed_ops) do
25
+ InstrumentAllTheThings.tracer.trace(span_name, **passed_ops) do
27
26
  next_blk.call(klass, actual_code)
28
27
  end
29
28
  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,14 +74,14 @@ 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
82
- Datadog.tracer&.writer&.worker&.flush_data
84
+ Datadog::Tracing.send(:tracer)&.writer&.worker&.flush_data
83
85
  end
84
86
 
85
87
  def emitted_spans(filtered_by: nil)
@@ -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 = '2.0.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
 
@@ -36,9 +36,7 @@ module InstrumentAllTheThings
36
36
  end
37
37
 
38
38
  def tracer
39
- return @tracer if defined?(@tracer)
40
-
41
- @tracer ||= Datadog.tracer
39
+ Datadog::Tracing
42
40
  end
43
41
 
44
42
  %i[
@@ -63,6 +61,29 @@ module InstrumentAllTheThings
63
61
  def self.included(other)
64
62
  other.include(Helpers)
65
63
  end
64
+
65
+ def self.tag_active_span(tag_name, tag_value)
66
+ tracer&.active_span&.set_tags(to_tracer_tags(tag_name => tag_value))
67
+ end
68
+
69
+ def self.to_tracer_tags(hsh, prefix = nil)
70
+ hsh.each_with_object({}) do |(hash_key, value), acc|
71
+ key = prefix ? "#{prefix}.#{hash_key}" : hash_key
72
+
73
+ case value
74
+ when Hash
75
+ acc.merge!(to_tracer_tags(value, key))
76
+ when Array
77
+ content = value.each_with_index.each_with_object({}) do |(item, index), reformed|
78
+ reformed[index] = item
79
+ end
80
+
81
+ acc.merge!(to_tracer_tags(content, key))
82
+ else
83
+ acc[key] = value
84
+ end
85
+ end
86
+ end
66
87
  end
67
88
 
68
89
  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
metadata CHANGED
@@ -1,37 +1,51 @@
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: 2.0.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: 2022-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddtrace
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dogstatsd-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.5.0
41
+ - !ruby/object:Gem::Dependency
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,9 +143,11 @@ 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"
@@ -175,34 +177,39 @@ files:
175
177
  - lib/instrument_all_the_things/version.rb
176
178
  - logo.jpg
177
179
  - vendor/cache/ast-2.4.2.gem
178
- - vendor/cache/benchmark-ips-2.9.1.gem
180
+ - vendor/cache/benchmark-ips-2.10.0.gem
179
181
  - 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/ddtrace-1.2.0.gem
183
+ - vendor/cache/debase-ruby_core_source-0.10.16.gem
184
+ - vendor/cache/diff-lcs-1.5.0.gem
182
185
  - vendor/cache/docile-1.4.0.gem
183
- - vendor/cache/dogstatsd-ruby-5.2.0.gem
184
- - vendor/cache/ffi-1.15.4.gem
186
+ - vendor/cache/dogstatsd-ruby-5.5.0.gem
187
+ - vendor/cache/ffi-1.15.5.gem
188
+ - vendor/cache/json-2.6.2.gem
189
+ - vendor/cache/libddprof-0.6.0.1.0.gem
190
+ - vendor/cache/libddwaf-1.3.0.2.0-x86_64-darwin.gem
191
+ - vendor/cache/libddwaf-1.3.0.2.0.gem
185
192
  - 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
193
+ - vendor/cache/msgpack-1.5.3.gem
194
+ - vendor/cache/parallel-1.22.1.gem
195
+ - vendor/cache/parser-3.1.2.0.gem
189
196
  - vendor/cache/pry-0.14.1.gem
190
- - vendor/cache/rainbow-3.0.0.gem
197
+ - vendor/cache/rainbow-3.1.1.gem
191
198
  - vendor/cache/rake-10.5.0.gem
192
- - vendor/cache/regexp_parser-2.1.1.gem
199
+ - vendor/cache/regexp_parser-2.5.0.gem
193
200
  - 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/rubocop-1.21.0.gem
200
- - vendor/cache/rubocop-ast-1.11.0.gem
201
+ - vendor/cache/rspec-3.11.0.gem
202
+ - vendor/cache/rspec-core-3.11.0.gem
203
+ - vendor/cache/rspec-expectations-3.11.0.gem
204
+ - vendor/cache/rspec-mocks-3.11.1.gem
205
+ - vendor/cache/rspec-support-3.11.0.gem
206
+ - vendor/cache/rubocop-1.31.2.gem
207
+ - vendor/cache/rubocop-ast-1.19.1.gem
201
208
  - vendor/cache/ruby-progressbar-1.11.0.gem
202
209
  - vendor/cache/simplecov-0.21.2.gem
203
210
  - vendor/cache/simplecov-html-0.12.3.gem
204
- - vendor/cache/simplecov_json_formatter-0.1.3.gem
205
- - vendor/cache/unicode-display_width-2.1.0.gem
211
+ - vendor/cache/simplecov_json_formatter-0.1.4.gem
212
+ - vendor/cache/unicode-display_width-2.2.0.gem
206
213
  homepage: https://github.com/GetTerminus/instrument-all-the-things
207
214
  licenses: []
208
215
  metadata:
@@ -217,14 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
224
  requirements:
218
225
  - - ">="
219
226
  - !ruby/object:Gem::Version
220
- version: '0'
227
+ version: 2.7.0
221
228
  required_rubygems_version: !ruby/object:Gem::Requirement
222
229
  requirements:
223
230
  - - ">="
224
231
  - !ruby/object:Gem::Version
225
232
  version: '0'
226
233
  requirements: []
227
- rubygems_version: 3.2.22
234
+ rubygems_version: 3.3.7
228
235
  signing_key:
229
236
  specification_version: 4
230
237
  summary: Make instrumentation with DataDog easy peasy
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