opentracing-instrumentation 0.1.8 → 0.1.13

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: b58db3616510f2c097cf2586f113a23c28c0ca8232c828f3577f64e09aecdcce
4
- data.tar.gz: 3a32e28eae0e9d698ac5f229453d981ac4ed01c3fc78533c89090615759030fc
3
+ metadata.gz: 6dd80093ca0c1a8cfc5b97e6c20e72440581970dee1941d97e77c9bb2c3ee449
4
+ data.tar.gz: ecf8fab0778ab5df7764a05495f84d2336a48c2ca382242727b26b9bd052e9dd
5
5
  SHA512:
6
- metadata.gz: e46ac60a7008279377c14229b7dc7e61cdd14afb63f340e45de25005f1c5259a122c90d35c7493ef5daed703e113dcdbba45ec1604bcb9129999904df7258d6f
7
- data.tar.gz: 442f72513f70e1323ed0a04b1a0e1c35e6d903593aadc11a9997b4da1bd395aedf9378065ce102ba703aa9cfdf8ece29a8ec13bf5703849367543a2ebdf5773b
6
+ metadata.gz: 03ca24d62c6c254e158bffabecc961dc7c945862f418f7324e6790538649d194c83a5373a9dacb28bcf4fc5153e0b298a3b65e04fbba69c3347297281e327a73
7
+ data.tar.gz: 5ec70cad41f48ab7f4c3f5875f8e743dd492d12fa13a583e1abfb5e1a64bd32278e0347b37d9844f4c0399a850037be235af63423983627e5fcfd461ef372622
@@ -1,5 +1,7 @@
1
1
  require:
2
2
  - rubocop-rspec
3
+ - rubocop-performance
4
+ - rubocop-thread_safety
3
5
 
4
6
  Layout/LineLength:
5
7
  Max: 100
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.13
@@ -18,7 +18,7 @@ GIT
18
18
  PATH
19
19
  remote: .
20
20
  specs:
21
- opentracing-instrumentation (0.1.8)
21
+ opentracing-instrumentation (0.1.13)
22
22
  json
23
23
  opentracing (~> 0.5.0)
24
24
 
@@ -58,7 +58,7 @@ GEM
58
58
  multipart-post (2.1.1)
59
59
  opentracing (0.5.0)
60
60
  parallel (1.19.1)
61
- parser (2.7.0.3)
61
+ parser (2.7.0.5)
62
62
  ast (~> 2.4.0)
63
63
  pry (0.12.2)
64
64
  coderay (~> 1.1.0)
@@ -84,7 +84,7 @@ GEM
84
84
  diff-lcs (>= 1.2.0, < 2.0)
85
85
  rspec-support (~> 3.9.0)
86
86
  rspec-support (3.9.2)
87
- rubocop (0.80.0)
87
+ rubocop (0.80.1)
88
88
  jaro_winkler (~> 1.5.1)
89
89
  parallel (~> 1.10)
90
90
  parser (>= 2.7.0.1)
@@ -92,8 +92,12 @@ GEM
92
92
  rexml
93
93
  ruby-progressbar (~> 1.7)
94
94
  unicode-display_width (>= 1.4.0, < 1.7)
95
+ rubocop-performance (1.5.2)
96
+ rubocop (>= 0.71.0)
95
97
  rubocop-rspec (1.38.1)
96
98
  rubocop (>= 0.68.1)
99
+ rubocop-thread_safety (0.3.4)
100
+ rubocop (>= 0.51.0)
97
101
  ruby-progressbar (1.10.1)
98
102
  thread_safe (0.3.6)
99
103
  thrift (0.11.0.0)
@@ -118,7 +122,9 @@ DEPENDENCIES
118
122
  redis (~> 3.3.5)
119
123
  rspec (~> 3.0)
120
124
  rubocop (~> 0.80.0)
125
+ rubocop-performance (~> 1.5.2)
121
126
  rubocop-rspec (~> 1.38.1)
127
+ rubocop-thread_safety (~> 0.3.4)
122
128
  test-tracer!
123
129
  thrift (~> 0.11.0)
124
130
  tracing-matchers!
@@ -5,6 +5,8 @@ module OpenTracing
5
5
  # Mongo driver instrumentation. Support mongo gem version 2.x.
6
6
  module Mongo
7
7
  autoload :DirectSanitazer, 'opentracing/instrumentation/mongo/direct_sanitazer'
8
+ autoload :OperationNameBuilder,
9
+ 'opentracing/instrumentation/mongo/operation_name_builder'
8
10
  autoload :TraceSubscriber, 'opentracing/instrumentation/mongo/trace_subscriber'
9
11
  autoload :QuerySanitazer, 'opentracing/instrumentation/mongo/query_sanitazer'
10
12
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTracing
4
+ module Instrumentation
5
+ module Mongo
6
+ # OperationNameBuilder for Mongo::TraceSubscriber
7
+ class OperationNameBuilder
8
+ DEFAULT_OPERATION_NAME_PATTERN = \
9
+ 'mongo(collection=%<database>s.%<collection>s, command=%<command>s)'
10
+
11
+ # @param operation_name_pattern [String]
12
+ def initialize(
13
+ operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN
14
+ )
15
+ @operation_name_pattern = operation_name_pattern
16
+ end
17
+
18
+ # @param event [Mongo::Monitoring::Event::CommandStarted]
19
+ # @return [String] formated command name
20
+ def build_operation_name(event)
21
+ format_args = build_format_args(event)
22
+ format(operation_name_pattern, **format_args)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :operation_name_pattern
28
+
29
+ COLLECTION = 'collection'
30
+
31
+ def build_format_args(event)
32
+ {
33
+ database: event.database_name,
34
+ collection: fetch_collection_name(event),
35
+ command: event.command_name,
36
+ }
37
+ end
38
+
39
+ def fetch_collection_name(event)
40
+ # On some command collection name into 'collection' field,
41
+ event.command[COLLECTION] || event.command[event.command_name]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -10,24 +10,22 @@ module OpenTracing
10
10
  class TraceSubscriber
11
11
  include Forwardable
12
12
 
13
- DEFAULT_OPERATION_NAME = 'mongo_command'
14
-
15
13
  def initialize(
16
14
  tracer: OpenTracing.global_tracer,
17
15
  scope_store: {},
18
- operation_name: DEFAULT_OPERATION_NAME,
16
+ operation_name_builder: OperationNameBuilder.new,
19
17
  sanitazer: QuerySanitazer.new
20
18
  )
21
19
  @tracer = tracer
22
20
  @monitor = Monitor.new
23
21
  @scope_store = scope_store
24
- @operation_name = operation_name
22
+ @operation_name_builder = operation_name_builder
25
23
  @sanitazer = sanitazer
26
24
  end
27
25
 
28
26
  def started(event)
29
27
  scope = tracer.start_active_span(
30
- operation_name,
28
+ build_operation_name(event),
31
29
  tags: base_tags(event).merge(mongo_tags(event)),
32
30
  )
33
31
 
@@ -48,9 +46,13 @@ module OpenTracing
48
46
  attr_reader :tracer
49
47
  attr_reader :scope_store
50
48
  attr_reader :monitor
51
- attr_reader :operation_name
49
+ attr_reader :operation_name_builder
52
50
  attr_reader :sanitazer
53
51
 
52
+ def build_operation_name(event)
53
+ operation_name_builder.build_operation_name(event)
54
+ end
55
+
54
56
  def base_tags(event)
55
57
  {
56
58
  'component' => 'db',
@@ -8,39 +8,49 @@ module OpenTracing
8
8
  # wrapped_object = OpenTracing::Instrumentation::ObjectWrapper.new(other_object)
9
9
  # wrapped_object.other_object_method
10
10
  class ObjectWrapper
11
- DEFAULT_COMMAND_NAME = 'method_call'
11
+ DEFAULT_OPERATOIN_NAME_PATTERN = \
12
+ 'object_call(%<class_name>s#%<method>s)'
12
13
 
13
14
  attr_reader :tracer,
14
- :command_name
15
+ :operation_name_pattern
15
16
 
16
17
  def initialize(
17
18
  object,
18
19
  tracer: OpenTracing.global_tracer,
19
- command_name: DEFAULT_COMMAND_NAME
20
+ operation_name_pattern: DEFAULT_OPERATOIN_NAME_PATTERN
20
21
  )
21
22
  @object = object
22
23
  @tracer = tracer
23
- @command_name = command_name
24
+ @operation_name_pattern = operation_name_pattern
24
25
  end
25
26
 
26
27
  # wrapped object
27
28
  attr_reader :object
28
29
 
29
30
  def respond_to_missing?(method_name, *)
30
- object.response_to?(method_name)
31
+ object.respond_to?(method_name)
31
32
  end
32
33
 
33
34
  def method_missing(method_name, *args)
34
35
  return super unless object.respond_to?(method_name)
35
36
 
37
+ operation_name = buid_operation_name(method_name)
36
38
  tags = build_tags(method_name)
37
- tracer.start_active_span(command_name, tags: tags) do |scope|
39
+ tracer.start_active_span(operation_name, tags: tags) do |scope|
38
40
  call_method(scope.span, method_name, *args)
39
41
  end
40
42
  end
41
43
 
42
44
  private
43
45
 
46
+ def buid_operation_name(method_name)
47
+ format(
48
+ operation_name_pattern,
49
+ class_name: class_name,
50
+ method: method_name,
51
+ )
52
+ end
53
+
44
54
  def call_method(span, method_name, *args)
45
55
  object.send(method_name, *args)
46
56
  rescue StandardError => e
@@ -48,9 +58,13 @@ module OpenTracing
48
58
  raise e
49
59
  end
50
60
 
61
+ def class_name
62
+ @class_name ||= object.class.to_s
63
+ end
64
+
51
65
  def build_tags(method)
52
66
  {
53
- 'object.class' => object.class.to_s,
67
+ 'object.class' => class_name,
54
68
  'object.method' => method.to_s,
55
69
  }
56
70
  end
@@ -7,27 +7,28 @@ module OpenTracing
7
7
  module Redis
8
8
  # Redis tracing mixin config
9
9
  class Config
10
- DEFAULT_SPAN_NAME = 'redis_command'
10
+ DEFAULT_OPERATION_NAME_PATTERN = \
11
+ 'redis(command=%<command>s)'
11
12
  # Safe by default
12
13
  DEFAULT_LOG_ARGS = false
13
14
  DEFAULT_LOG_REPLY = false
14
15
  DEFAULT_COMPONENT = 'kv'
15
16
 
16
17
  attr_accessor :tracer
17
- attr_accessor :span_name
18
+ attr_accessor :operation_name_pattern
18
19
  attr_accessor :log_args
19
20
  attr_accessor :log_reply
20
21
  attr_accessor :component
21
22
 
22
23
  def initialize(
23
24
  tracer: OpenTracing.global_tracer,
24
- span_name: DEFAULT_SPAN_NAME,
25
+ operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN,
25
26
  log_args: DEFAULT_LOG_ARGS,
26
27
  log_reply: DEFAULT_LOG_REPLY,
27
28
  component: DEFAULT_COMPONENT
28
29
  )
29
30
  @tracer = tracer
30
- @span_name = span_name
31
+ @operation_name_pattern = operation_name_pattern
31
32
  @log_args = log_args
32
33
  @log_reply = log_reply
33
34
  @component = component
@@ -19,7 +19,7 @@ module OpenTracing
19
19
 
20
20
  def_delegators :@config,
21
21
  :tracer,
22
- :span_name,
22
+ :operation_name_pattern,
23
23
  :component,
24
24
  :log_args,
25
25
  :log_reply
@@ -27,10 +27,11 @@ module OpenTracing
27
27
  def_delegators :@error_writer,
28
28
  :write_error
29
29
 
30
- def start_active_scope(connection_class, peer_addr)
30
+ def start_active_scope(command, connection_class, peer_addr)
31
+ operation_name = build_operation_name(command)
31
32
  tags = build_tags(connection_class, peer_addr)
32
33
  tracer.start_active_span(
33
- span_name,
34
+ operation_name,
34
35
  tags: tags,
35
36
  )
36
37
  end
@@ -79,6 +80,13 @@ module OpenTracing
79
80
  'redis.reply': JSON.dump(reply),
80
81
  )
81
82
  end
83
+
84
+ private
85
+
86
+ def build_operation_name(command)
87
+ command_name, * = command
88
+ format(operation_name_pattern, command: command_name)
89
+ end
82
90
  end
83
91
  end
84
92
  end
@@ -56,7 +56,7 @@ module OpenTracing
56
56
  :timeout=
57
57
 
58
58
  def write(command)
59
- scope = start_pipeline_scope
59
+ scope = start_pipeline_scope(command)
60
60
  connection.write(command).tap do
61
61
  span_builder.write_log_command(scope.span, command) if scope
62
62
  end
@@ -87,15 +87,20 @@ module OpenTracing
87
87
  "#{@host}:#{@port}"
88
88
  end
89
89
 
90
- def start_pipeline_scope
90
+ def start_pipeline_scope(command)
91
91
  if @pipeline_scope
92
92
  @pipeline_queue_size += 1
93
93
  return @pipeline_scope
94
94
  end
95
95
 
96
+ new_pipeline_scope(command)
97
+ end
98
+
99
+ def new_pipeline_scope(command)
96
100
  @pipeline_queue_size = 1
97
101
  @pipeline_scope =
98
102
  span_builder.start_active_scope(
103
+ command,
99
104
  connection.class,
100
105
  peer_addr,
101
106
  )
@@ -38,6 +38,8 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency 'redis', '~> 3.3.5'
39
39
  spec.add_development_dependency 'rspec', '~> 3.0'
40
40
  spec.add_development_dependency 'rubocop', '~> 0.80.0'
41
+ spec.add_development_dependency 'rubocop-performance', '~> 1.5.2'
41
42
  spec.add_development_dependency 'rubocop-rspec', '~> 1.38.1'
43
+ spec.add_development_dependency 'rubocop-thread_safety', '~> 0.3.4'
42
44
  spec.add_development_dependency 'thrift', '~> 0.11.0'
43
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentracing-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fedorenko Dmitrij
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-31 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: json
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: 0.80.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-performance
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.5.2
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.5.2
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: rubocop-rspec
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,20 @@ dependencies:
206
220
  - - "~>"
207
221
  - !ruby/object:Gem::Version
208
222
  version: 1.38.1
223
+ - !ruby/object:Gem::Dependency
224
+ name: rubocop-thread_safety
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.3.4
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.3.4
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: thrift
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +296,7 @@ files:
268
296
  - lib/opentracing/instrumentation/hutch/global_properties_builder.rb
269
297
  - lib/opentracing/instrumentation/mongo.rb
270
298
  - lib/opentracing/instrumentation/mongo/direct_sanitazer.rb
299
+ - lib/opentracing/instrumentation/mongo/operation_name_builder.rb
271
300
  - lib/opentracing/instrumentation/mongo/query_sanitazer.rb
272
301
  - lib/opentracing/instrumentation/mongo/trace_subscriber.rb
273
302
  - lib/opentracing/instrumentation/object_wrapper.rb