instrument_all_the_things 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dca7567b1c5a509b2a0eb588455b908357715bf2e57b67cf68b8049fdbd38bed
4
- data.tar.gz: 9404629cf4dc69252676f30742d5c4537342892258ece7d49ef72bc179125012
3
+ metadata.gz: 5092de92a898d3f15edde6f9379bdcbab22131323822744a5c3adbdc8868a922
4
+ data.tar.gz: 6e167a14df06cf6afc2f438dbdb4bd5d6d329a1d0299da62773e6a1fc36e60ef
5
5
  SHA512:
6
- metadata.gz: 4d3018c4507be010ab4179ea09ba52c9842d7bb53dc105d9cc50bd8e2a7df58ce04c920b802a126d52ca51b4a20929def3ff11fe56b0bf643468bdb41c34b790
7
- data.tar.gz: ab74f79b671305aabe0411cba5b25e67345ae22484034078d05b785755517ec0eafd5eb2870cbac9aed1541e283eef35fc8cd3f6508f1a345f584f13da83e506
6
+ metadata.gz: 552a49f66410a04d109fc9e722fa8e8739e117c3989be7b77e77b4e203c3c249af221a08309c048f91f3e733d8abbd7694d9f301d899f61db4483bd1bc746e70
7
+ data.tar.gz: 2b32646bd335b455d952169bbafd4439c8e9ee41117dd7ff5027749369103161e478f027657156cdb909cb30ebb4ea6b69e68a7979936fd0f48f82a73d759f6c
@@ -3,7 +3,8 @@ AllCops:
3
3
  - Makefile
4
4
  - vendor/**/*
5
5
  - bin/**/*
6
-
6
+ - '**/*_pb.rb'
7
+
7
8
  Layout/EndOfLine:
8
9
  Enabled: false
9
10
 
@@ -40,8 +41,6 @@ Layout/LineLength:
40
41
  Max: 280
41
42
  IgnoreCopDirectives: true
42
43
  AllowedPatterns: ['\A#', '\A\s*sig { .* }\Z']
43
- Exclude:
44
- - '**/*_pb.rb'
45
44
 
46
45
  Metrics/AbcSize:
47
46
  Enabled: true
@@ -76,7 +75,6 @@ Metrics/BlockLength:
76
75
  Max: 30
77
76
  Exclude:
78
77
  - spec/**/*.rb
79
- - '**/*_pb.rb'
80
78
 
81
79
  Metrics/ParameterLists:
82
80
  Max: 6
data/README.md CHANGED
@@ -44,28 +44,6 @@ class Foo
44
44
  end
45
45
  end
46
46
  ```
47
- ### Garbage Collection Stats
48
- _Configuration Key `gc_stats`_
49
-
50
- Collects the difference between the specified keys during the execution of the method.
51
-
52
- Stat diffs are added to the active trace span as a tag, and a stat is emitted with the following format
53
-
54
- `klass_name.(instance|class)_methods.(stat_name)_change`
55
-
56
- #### Description of default stats
57
- _GC Stats are not thread local, if your app is multi threaded other threads may be contributing to these stats_
58
- | Option | Description
59
- | ----- | ----
60
- | total_allocated_pages | Total number of memory pages owned by this ruby process. Mature processes tend to see a slowdown in page allocations
61
- | total_allocated_objects | Total number of objects which have not been garbage collected yet
62
- | count | Total number of GC runs during this method's exuection
63
-
64
- #### Options
65
- | Option | Description | Default
66
- | ----- | ---- | -----
67
- | diffed_stats | Stats to diff and record | [:total_allocated_pages, :total_allocated_objects, :count]
68
-
69
47
  ### Error Logging
70
48
  _Configuration Key `log_errors`_
71
49
 
@@ -129,8 +107,9 @@ require 'instrument_all_the_things/testing/trace_tracker'
129
107
  require 'instrument_all_the_things/testing/rspec_matchers'
130
108
 
131
109
  Datadog.configure do |c|
132
- c.tracing.transport_options = proc { |t|
133
- t.adapter :test, IATT::Testing::TraceTracker.new
110
+ c.tracing.test_mode.enabled = true
111
+ c.tracing.test_mode.writer_options = {
112
+ transport: InstrumentAllTheThings::Testing::TraceTracker.tracker
134
113
  }
135
114
  end
136
115
 
@@ -166,10 +145,6 @@ some awesome rspec helpers like so:
166
145
  it 'traces' do
167
146
  expect {
168
147
  klass.new.foo
169
-
170
- # Datadog writes trace to the wire and to the test harness asynchronously
171
- # This helper is provided to force the flush before expectations are stated
172
- flush_traces
173
148
  }.to change{
174
149
  emitted_spans(
175
150
  filtered_by: {resource: 'KlassName.foo'}
@@ -348,7 +323,6 @@ Calculating -------------------------------------
348
323
  the_works 7.404k (±12.9%) i/s - 36.936k in 5.100630s
349
324
  only_trace 27.968k (±12.7%) i/s - 139.209k in 5.061907s
350
325
  only_error_logging 638.098k (± 4.6%) i/s - 3.231M in 5.075275s
351
- only_gc_stats 12.930k (±13.2%) i/s - 63.865k in 5.070874s
352
326
  only_execution_counts 9.847k (±11.1%) i/s - 49.088k in 5.073475s
353
327
  ```
354
328
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['lib']
31
31
  spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
32
32
 
33
- spec.add_dependency 'ddtrace', '~> 1.0'
33
+ spec.add_dependency 'datadog', '~> 2.0'
34
34
  spec.add_dependency 'dogstatsd-ruby', '~> 5.0'
35
35
 
36
36
  spec.add_development_dependency 'benchmark-ips'
@@ -2,5 +2,4 @@
2
2
 
3
3
  require_relative './tracing'
4
4
  require_relative './error_logging'
5
- require_relative './gc_stats'
6
5
  require_relative './execution_count_and_timing'
@@ -21,6 +21,7 @@ module InstrumentAllTheThings
21
21
  passed_ops = opts.dup
22
22
  passed_ops[:resource] ||= context.trace_name(klass)
23
23
  passed_ops[:tags] ||= {}
24
+ passed_ops[:type] = passed_ops.delete(:span_type)
24
25
 
25
26
  InstrumentAllTheThings.tracer.trace(span_name, **passed_ops) do
26
27
  next_blk.call(klass, actual_code)
@@ -5,9 +5,6 @@ require_relative './instrumentors/all'
5
5
  module InstrumentAllTheThings
6
6
  class MethodInstrumentor
7
7
  WRAPPERS = {
8
- # Note that the order of these hash keys are applied top to bottom, with the first inserted key
9
- # being the inner most wrapper
10
- gc_stats: Instrumentors::GC_STATS_WRAPPER,
11
8
  error_logging: Instrumentors::ERROR_LOGGING_WRAPPER,
12
9
  execution_counts_and_timing: Instrumentors::EXECUTION_COUNT_AND_TIMING_WRAPPER,
13
10
  trace: Instrumentors::TRACE_WRAPPER,
@@ -15,7 +12,6 @@ module InstrumentAllTheThings
15
12
 
16
13
  DEFAULT_OPTIONS = {
17
14
  trace: true,
18
- gc_stats: false,
19
15
  error_logging: true,
20
16
  execution_counts_and_timing: false,
21
17
  }.freeze
@@ -28,6 +28,10 @@ module InstrumentAllTheThings
28
28
  extend Instrumentor
29
29
  end
30
30
 
31
+ # attaching to the original to_s
32
+ method = klass.method(:to_s)
33
+ mod.define_singleton_method(:to_s, &method)
34
+
31
35
  mod._iatt_built_for = klass
32
36
 
33
37
  mod
@@ -80,10 +80,6 @@ module InstrumentAllTheThings
80
80
  stats.inject(0) { |l, n| l + n[:args][0] }
81
81
  end
82
82
 
83
- def flush_traces
84
- Datadog::Tracing.send(:tracer)&.writer&.worker&.flush_data
85
- end
86
-
87
83
  def emitted_spans(filtered_by: nil)
88
84
  sleep 0.01
89
85
  traces = InstrumentAllTheThings::Testing::TraceTracker.tracker.traces.map(&:dup)
@@ -1,15 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'datadog/tracing/transport/io/client'
4
+
3
5
  module InstrumentAllTheThings
4
6
  module Testing
5
- class TraceTracker
7
+ class TraceTracker < Datadog::Tracing::Transport::IO::Client
6
8
  attr_reader :traces
7
9
 
8
10
  def self.tracker
9
- @tracker ||= new
11
+ @tracker ||= new(
12
+ StringIO.new,
13
+ Datadog::Core::Encoding::JSONEncoder,
14
+ )
10
15
  end
11
16
 
12
- def initialize
17
+ def initialize(...)
18
+ super
13
19
  reset!
14
20
  end
15
21
 
@@ -17,8 +23,9 @@ module InstrumentAllTheThings
17
23
  @traces = []
18
24
  end
19
25
 
20
- def <<(val)
21
- @traces.concat(MessagePack.load(val[:body]).flatten)
26
+ def write_data(_, val)
27
+ body = JSON.parse(val)
28
+ @traces.concat(body.fetch('traces', []).flatten)
22
29
  end
23
30
  end
24
31
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ddtrace'
3
+ require 'datadog'
4
4
 
5
5
  # https://github.com/DataDog/dd-trace-rb/blob/master/docs/UpgradeGuide.md#between-threads
6
6
  class Thread
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstrumentAllTheThings
4
- VERSION = '4.0.0'
4
+ VERSION = '5.0.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ddtrace'
3
+ require 'datadog'
4
4
 
5
5
  require 'instrument_all_the_things/version'
6
6
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrument_all_the_things
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.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: 2024-02-12 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ddtrace
14
+ name: datadog
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '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: '1.0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dogstatsd-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -166,7 +166,6 @@ files:
166
166
  - lib/instrument_all_the_things/instrumentors/all.rb
167
167
  - lib/instrument_all_the_things/instrumentors/error_logging.rb
168
168
  - lib/instrument_all_the_things/instrumentors/execution_count_and_timing.rb
169
- - lib/instrument_all_the_things/instrumentors/gc_stats.rb
170
169
  - lib/instrument_all_the_things/instrumentors/tracing.rb
171
170
  - lib/instrument_all_the_things/method_instrumentor.rb
172
171
  - lib/instrument_all_the_things/method_proxy.rb
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module InstrumentAllTheThings
4
- module Instrumentors
5
- DEFAULT_GC_STATS_OPTIONS = {
6
- diffed_stats: %i[
7
- total_allocated_pages
8
- total_allocated_objects
9
- count
10
- ].freeze,
11
- }.freeze
12
-
13
- # This is to make it easier to spec since other
14
- # gems may call this
15
- GC_STAT_GETTER = -> { GC.stat }
16
-
17
- GC_STATS_WRAPPER = lambda do |opts, context|
18
- opts = if opts == true
19
- DEFAULT_GC_STATS_OPTIONS
20
- else
21
- DEFAULT_GC_STATS_OPTIONS.merge(opts)
22
- end
23
-
24
- report_value = proc do |klass, stat_name, value|
25
- InstrumentAllTheThings.stat_reporter.histogram(
26
- context.stats_name(klass) + ".#{stat_name}_change",
27
- value,
28
- )
29
- end
30
-
31
- lambda do |klass, next_blk, actual_code|
32
- starting_values = GC_STAT_GETTER.call.slice(*opts[:diffed_stats])
33
- next_blk.call(klass, actual_code).tap do
34
- new_values = GC_STAT_GETTER.call.slice(*opts[:diffed_stats])
35
-
36
- diff = new_values.merge(starting_values) do |_, new_value, starting_value|
37
- new_value - starting_value
38
- end
39
-
40
- if (span = InstrumentAllTheThings.tracer.active_span)
41
- span.set_tags(IATT.to_tracer_tags(diff, 'gc_stats'))
42
- end
43
-
44
- diff.each { |s, v| report_value.call(klass, s, v) }
45
- end
46
- end
47
- end
48
- end
49
- end