instrument_all_the_things 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bcc57ca40a267c78c39c37d55711d1ca2ca33637c115b293e9f679b5950b6e7
4
- data.tar.gz: 720d12fbd72e5c7bb7b82f9088c882037cc6c2ba675f3f7c097bfcfdb03771e5
3
+ metadata.gz: ac64a9b7acfa4de004260992b1c4f664587345e692a6f08f9798442b0568619d
4
+ data.tar.gz: 6bd26e6ea3186c4ca0883a4a2971dc2980f0c71409f6654a5da1ab183539b372
5
5
  SHA512:
6
- metadata.gz: 2a99e6d00c90458e247bb4a018d2abd23774aec7d2c660bdad9e0e6e22dc9b29058e2d605f4dd0fa126084bb2163721fb1e2e8670b1521c488718d3e1d225010
7
- data.tar.gz: 9e9ea9639a45dd1f766882bb2ae355a4e9029a388a9421849d681389d8595de5f7cf81ac38f7648add79b4db7582320bc33ccdf057cc352e6634b6ee8c392dad
6
+ metadata.gz: 97d28f7d5a86fbaf0cc1a9792ad26d39cc2a34ddc9bbbba9c82d413f19b785136af1319dc27f1a44c72f494b701fcf11003743edae6276c30a0ec100da054de8
7
+ data.tar.gz: d78092b9f1ad421ba8674ad830821558399dd471117f4fe1efda3905ef0dc472e421c4105288790582d76f15d60f8881a3da6554050ff69f50ae1a071e46fc19
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .DS_Store
13
+ .vscode
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- instrument_all_the_things (1.0.2)
4
+ instrument_all_the_things (1.0.3)
5
5
  ddtrace
6
6
  dogstatsd-ruby
7
7
 
@@ -11,7 +11,7 @@ GEM
11
11
  ast (2.4.0)
12
12
  benchmark-ips (2.7.2)
13
13
  coderay (1.1.2)
14
- ddtrace (0.33.0)
14
+ ddtrace (0.33.1)
15
15
  msgpack
16
16
  diff-lcs (1.3)
17
17
  docile (1.3.2)
@@ -33,7 +33,7 @@ module InstrumentAllTheThings
33
33
  @stat_reporter ||= Clients::StatReporter::DataDog.new(
34
34
  ENV.fetch('DATADOG_HOST', 'localhost'),
35
35
  ENV.fetch('DATADOG_PORT', 8125),
36
- namespace: stat_namespace
36
+ namespace: stat_namespace,
37
37
  )
38
38
  end
39
39
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstrumentAllTheThings
4
- Context = Struct.new(:method_name, :instance, keyword_init: true) do
4
+ Context = Struct.new(:method_name, :instance, :tags, keyword_init: true) do
5
5
  def stats_name(klass_or_instance)
6
6
  @stats_name ||= [
7
7
  class_name(klass_or_instance),
@@ -2,17 +2,18 @@
2
2
 
3
3
  module InstrumentAllTheThings
4
4
  module Instrumentors
5
- DEFAULT_EXECUTION_COUNT_AND_TIMING_OPTIONS = { }.freeze
5
+ DEFAULT_EXECUTION_COUNT_AND_TIMING_OPTIONS = {}.freeze
6
6
 
7
- EXECUTION_COUNT_AND_TIMING_WRAPPER = proc do |opts, context|
7
+ EXECUTION_COUNT_AND_TIMING_WRAPPER = proc do |_opts, context|
8
8
  proc do |klass, next_blk, actual_code|
9
- InstrumentAllTheThings.increment("#{context.stats_name(klass)}.executed")
9
+ context.tags ||= []
10
10
 
11
- InstrumentAllTheThings.time("#{context.stats_name(klass)}.duration") do
11
+ InstrumentAllTheThings.increment("#{context.stats_name(klass)}.executed", { tags: context.tags })
12
+ InstrumentAllTheThings.time("#{context.stats_name(klass)}.duration", { tags: context.tags }) do
12
13
  next_blk.call(klass, actual_code)
13
14
  end
14
- rescue
15
- InstrumentAllTheThings.increment("#{context.stats_name(klass)}.errored")
15
+ rescue StandardError
16
+ InstrumentAllTheThings.increment("#{context.stats_name(klass)}.errored", { tags: context.tags })
16
17
  raise
17
18
  end
18
19
  end
@@ -19,7 +19,7 @@ module InstrumentAllTheThings
19
19
  proc do |klass, next_blk, actual_code|
20
20
  InstrumentAllTheThings.tracer.trace(
21
21
  opts[:span_name],
22
- tags: opts[:tags],
22
+ tags: context[:tags] || {},
23
23
  service: opts[:service],
24
24
  resource: opts[:resource] || context.trace_name(klass),
25
25
  span_type: opts[:span_type]
@@ -40,10 +40,30 @@ module InstrumentAllTheThings
40
40
  @_iatt_built_for = val
41
41
  end
42
42
 
43
+ def set_context_tags(klass, settings, *args, **kwargs) # rubocop:disable Lint/UnusedMethodArgument
44
+ return unless settings.is_a?(Hash) && settings[:trace].is_a?(Hash) && settings[:trace][:tags]
45
+
46
+ settings[:context][:tags] = settings[:trace][:tags].map do |tag|
47
+ if tag.is_a?(Proc)
48
+ if tag.arity == 1
49
+ tag.call(eval(tag.parameters[0][1].to_s))
50
+ else
51
+ klass.instance_exec(&tag)
52
+ end
53
+ else
54
+ tag
55
+ end
56
+ rescue StandardError
57
+ nil
58
+ end.compact
59
+ end
60
+
43
61
  def wrap_implementation(method_name, settings)
44
62
  wrap = MethodInstrumentor.new(**settings)
63
+ set_tags = method(:set_context_tags)
45
64
 
46
65
  define_method(method_name) do |*args, **kwargs, &blk|
66
+ set_tags.call(self, settings, args, kwargs)
47
67
  wrap.invoke(klass: is_a?(Class) ? self : self.class) do
48
68
  super(*args, **kwargs, &blk)
49
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstrumentAllTheThings
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddtrace
@@ -176,7 +176,7 @@ files:
176
176
  - vendor/cache/ast-2.4.0.gem
177
177
  - vendor/cache/benchmark-ips-2.7.2.gem
178
178
  - vendor/cache/coderay-1.1.2.gem
179
- - vendor/cache/ddtrace-0.33.0.gem
179
+ - vendor/cache/ddtrace-0.33.1.gem
180
180
  - vendor/cache/diff-lcs-1.3.gem
181
181
  - vendor/cache/docile-1.3.2.gem
182
182
  - vendor/cache/dogstatsd-ruby-4.7.0.gem
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubygems_version: 3.1.2
223
+ rubygems_version: 3.0.1
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: Make instrumentation with DataDog easy peasy