opentracing-instrumentation 0.1.8 → 0.1.9

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: 69f4f1cfeeac35ba9ae9136f6da987d5d0fe6fc389983b48a931a80a384293ec
4
+ data.tar.gz: 70418b1cd88602c5792b6e196211706b692cc4dfdc45de25ac296069171fa5a1
5
5
  SHA512:
6
- metadata.gz: e46ac60a7008279377c14229b7dc7e61cdd14afb63f340e45de25005f1c5259a122c90d35c7493ef5daed703e113dcdbba45ec1604bcb9129999904df7258d6f
7
- data.tar.gz: 442f72513f70e1323ed0a04b1a0e1c35e6d903593aadc11a9997b4da1bd395aedf9378065ce102ba703aa9cfdf8ece29a8ec13bf5703849367543a2ebdf5773b
6
+ metadata.gz: 115e8567b8dc553d0a5b566bfd51b433f74137402dd80903daac6afcf59c548bdff1f3534033d2cfc99cd138ce9d4a977648971aca3349235d973d1380d60312
7
+ data.tar.gz: f41a753d755fb5e1fc409b7394c51877288ad410dc91bfa5141d1caa2100f94abe09c926a27bb3f71ccb11136514908e71c81b3d409f552510a2f1b981991070
data/.rubocop.yml CHANGED
@@ -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
data/GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
data/Gemfile.lock CHANGED
@@ -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.9)
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!
@@ -10,24 +10,25 @@ module OpenTracing
10
10
  class TraceSubscriber
11
11
  include Forwardable
12
12
 
13
- DEFAULT_OPERATION_NAME = 'mongo_command'
13
+ DEFAULT_OPERATION_NAME_PATTERN = \
14
+ 'mongo(collection=%<database>s.%<collection>s, command=%<command>s)'
14
15
 
15
16
  def initialize(
16
17
  tracer: OpenTracing.global_tracer,
17
18
  scope_store: {},
18
- operation_name: DEFAULT_OPERATION_NAME,
19
+ operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN,
19
20
  sanitazer: QuerySanitazer.new
20
21
  )
21
22
  @tracer = tracer
22
23
  @monitor = Monitor.new
23
24
  @scope_store = scope_store
24
- @operation_name = operation_name
25
+ @operation_name_pattern = operation_name_pattern
25
26
  @sanitazer = sanitazer
26
27
  end
27
28
 
28
29
  def started(event)
29
30
  scope = tracer.start_active_span(
30
- operation_name,
31
+ build_operation_name(event),
31
32
  tags: base_tags(event).merge(mongo_tags(event)),
32
33
  )
33
34
 
@@ -48,9 +49,20 @@ module OpenTracing
48
49
  attr_reader :tracer
49
50
  attr_reader :scope_store
50
51
  attr_reader :monitor
51
- attr_reader :operation_name
52
+ attr_reader :operation_name_pattern
52
53
  attr_reader :sanitazer
53
54
 
55
+ def build_operation_name(event)
56
+ command_name = event.command_name
57
+ collection_name = event.command[command_name]
58
+ format(
59
+ operation_name_pattern,
60
+ database: event.database_name,
61
+ collection: collection_name,
62
+ command: command_name,
63
+ )
64
+ end
65
+
54
66
  def base_tags(event)
55
67
  {
56
68
  'component' => 'db',
@@ -8,19 +8,20 @@ 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
@@ -33,14 +34,23 @@ module OpenTracing
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.9
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