opentracing-instrumentation 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.drone.jsonnet +3 -3
  3. data/.gitlab-ci.yml +9 -9
  4. data/.rubocop.yml +6 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +4 -0
  7. data/GEM_VERSION +1 -1
  8. data/Gemfile +7 -7
  9. data/Gemfile.lock +29 -24
  10. data/lib/opentracing/instrumentation/bunny.rb +11 -11
  11. data/lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb +1 -1
  12. data/lib/opentracing/instrumentation/common.rb +2 -0
  13. data/lib/opentracing/instrumentation/common/error_writer.rb +7 -2
  14. data/lib/opentracing/instrumentation/common/operation_name_builder.rb +23 -0
  15. data/lib/opentracing/instrumentation/faraday/response_logger.rb +4 -4
  16. data/lib/opentracing/instrumentation/faraday/trace_middleware.rb +1 -1
  17. data/lib/opentracing/instrumentation/hutch.rb +6 -6
  18. data/lib/opentracing/instrumentation/mongo.rb +2 -0
  19. data/lib/opentracing/instrumentation/mongo/query_sanitazer.rb +18 -5
  20. data/lib/opentracing/instrumentation/mongo/sample_safety_argument_checker.rb +30 -0
  21. data/lib/opentracing/instrumentation/mongo/trace_subscriber.rb +5 -5
  22. data/lib/opentracing/instrumentation/rack/extract_middleware.rb +24 -5
  23. data/lib/opentracing/instrumentation/rack/http_tagger.rb +3 -3
  24. data/lib/opentracing/instrumentation/rack/trace_middleware.rb +5 -5
  25. data/lib/opentracing/instrumentation/redis/config.rb +5 -5
  26. data/lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb +4 -4
  27. data/lib/opentracing/instrumentation/sidekiq/client_middleware.rb +41 -18
  28. data/lib/opentracing/instrumentation/sidekiq/job_tagger.rb +7 -7
  29. data/lib/opentracing/instrumentation/sidekiq/server_middleware.rb +41 -15
  30. data/lib/opentracing/instrumentation/thrift.rb +13 -5
  31. data/lib/opentracing/instrumentation/thrift/traced_processor.rb +111 -0
  32. data/lib/opentracing/instrumentation/thrift/traced_processor_config.rb +37 -0
  33. data/lib/opentracing/instrumentation/thrift/traced_processor_operation_name_builder.rb +41 -0
  34. data/lib/opentracing/instrumentation/thrift/traced_processor_tags_builder.rb +30 -0
  35. data/lib/opentracing/instrumentation/thrift/traced_protocol.rb +31 -22
  36. data/lib/opentracing/instrumentation/thrift/traced_protocol_config.rb +7 -0
  37. data/lib/opentracing/instrumentation/thrift/traced_protocol_factory.rb +1 -0
  38. data/lib/opentracing/instrumentation/thrift/traced_protocol_operation_name_builder.rb +8 -2
  39. data/lib/opentracing/instrumentation/thrift/traced_protocol_tags_builder.rb +6 -2
  40. data/opentracing-instrumentation.gemspec +6 -4
  41. metadata +23 -16
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTracing
4
+ module Instrumentation
5
+ module Thrift
6
+ # Config of ThriftProcessor
7
+ class TracedProcessorConfig
8
+ # @return [OpenTracing::Tracer]
9
+ attr_accessor :tracer
10
+
11
+ # @return [Boolean] enabled wrap protocol into TracedProtocol
12
+ attr_accessor :trace_protocol
13
+
14
+ # @return [TracedProcessorOperationNameBuilder]
15
+ attr_accessor :operation_name_builder
16
+
17
+ # @return [TracedProcessorTagsBuilder]
18
+ attr_accessor :tags_builder
19
+
20
+ # @return [Common::ErrorWriter]
21
+ attr_accessor :error_writer
22
+
23
+ # @return [Logger] used for log errors. If nil (by default), then logging disabled,
24
+ attr_accessor :logger
25
+
26
+ def initialize
27
+ @tracer = OpenTracing.global_tracer
28
+ @trace_protocol = true
29
+ @operation_name_builder = TracedProcessorOperationNameBuilder.new
30
+ @tags_builder = TracedProcessorTagsBuilder.new
31
+ @error_writer = Common::ErrorWriter.new
32
+ @logger = nil
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTracing
4
+ module Instrumentation
5
+ module Thrift
6
+ # Thrift processor trace operation name builder
7
+ class TracedProcessorOperationNameBuilder
8
+ DEFAULT_OPERATION_NAME_TEMPALTE = \
9
+ 'thrift_processor(%<name>s)'
10
+
11
+ # @param operation_name_tempalte [String]
12
+ def initialize(
13
+ operation_name_template: DEFAULT_OPERATION_NAME_TEMPALTE
14
+ )
15
+ @operation_name_template = operation_name_template
16
+ end
17
+
18
+ # @param name [String] method name
19
+ # @param type [Integer] type of message
20
+ # @param seq_id [Integer] numberr of message
21
+ # @return [String] operation name
22
+ def build(name, type, seq_id)
23
+ format_args = build_format_args(name, type, seq_id)
24
+ format(operation_name_template, **format_args)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :operation_name_template
30
+
31
+ def build_format_args(name, type, seq_id)
32
+ {
33
+ name: name,
34
+ type: MESSAGE_TYPES[type],
35
+ seq_id: seq_id,
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTracing
4
+ module Instrumentation
5
+ module Thrift
6
+ # Tags builder for TracedProcessor
7
+ class TracedProcessorTagsBuilder < TracedProtocolTagsBuilder
8
+ DEFAULT_STATIC_TAGS = {
9
+ 'span.kind' => 'server',
10
+ 'component' => 'thrift',
11
+ }.freeze
12
+
13
+ def initialize(static_tags: DEFAULT_STATIC_TAGS)
14
+ super()
15
+ @static_tags = static_tags
16
+ end
17
+
18
+ def build_tags(protocol, name, type)
19
+ static_tags
20
+ .merge(build_protocol_tags(protocol))
21
+ .merge(build_message_tags(name, type))
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :static_tags
27
+ end
28
+ end
29
+ end
30
+ end
@@ -33,26 +33,32 @@ module OpenTracing
33
33
  super(protocol)
34
34
  @config = config.dup
35
35
  yield @config if block_given?
36
- @static_tags = config.tags_builder.build_static_tags(protocol)
36
+ @protocol_tags = config.tags_builder.build_protocol_tags(protocol)
37
+ end
38
+
39
+ def ==(other)
40
+ protocol == other.protocol &&
41
+ config == other.config &&
42
+ protocol_tags == other.protocol_tags
37
43
  end
38
44
 
39
45
  def write_message_begin(name, type, seqid)
40
- self.write_scope = \
41
- safe_start_active_span(WRITE_DIRECTION, name, type)
46
+ self.write_span = \
47
+ safe_start_span(WRITE_DIRECTION, name, type)
42
48
 
43
49
  # Call protocol instaed super, beacaus ProtocolDecorator do not
44
50
  # pass arguments to protocol.write_message_begin
45
51
  protocol.write_message_begin(name, type, seqid)
46
52
  rescue StandardError => e
47
- write_error(write_scope&.span, e)
48
- safe_close_span(write_scope)
53
+ write_error(write_span, e)
54
+ safe_close_span(write_span)
49
55
  raise e
50
56
  end
51
57
 
52
58
  def write_message_end
53
59
  super
54
60
  ensure
55
- safe_close_span(write_scope)
61
+ safe_close_span(write_span)
56
62
  end
57
63
 
58
64
  def read_message_begin
@@ -60,9 +66,9 @@ module OpenTracing
60
66
 
61
67
  name, type, rseqid = super
62
68
 
63
- self.read_scope = \
64
- safe_start_active_span(READ_DIRECTION, name, type,
65
- start_time: start_time)
69
+ self.read_span = \
70
+ safe_start_span(READ_DIRECTION, name, type,
71
+ start_time: start_time)
66
72
 
67
73
  [name, type, rseqid]
68
74
  end
@@ -70,25 +76,28 @@ module OpenTracing
70
76
  def read_message_end
71
77
  super
72
78
  ensure
73
- safe_close_span(read_scope)
79
+ safe_close_span(read_span)
74
80
  end
75
81
 
76
- private
82
+ protected
77
83
 
78
- attr_reader :static_tags
79
- attr_reader :protocol
84
+ attr_reader :protocol_tags,
85
+ :protocol,
86
+ :config
80
87
 
81
- def_delegators :@config,
88
+ private
89
+
90
+ def_delegators :config,
82
91
  :tracer,
83
92
  :tags_builder,
84
93
  :operation_name_builder,
85
94
  :error_writer,
86
95
  :logger
87
96
 
88
- attr_accessor :write_scope,
89
- :read_scope
97
+ attr_accessor :write_span,
98
+ :read_span
90
99
 
91
- def safe_start_active_span(
100
+ def safe_start_span(
92
101
  direction,
93
102
  name,
94
103
  type,
@@ -97,7 +106,7 @@ module OpenTracing
97
106
  operation_name = build_operation_name(direction, name, type)
98
107
  request_tags = build_tags(name, type)
99
108
 
100
- tracer.start_active_span(
109
+ tracer.start_span(
101
110
  operation_name,
102
111
  tags: request_tags,
103
112
  start_time: start_time,
@@ -106,10 +115,10 @@ module OpenTracing
106
115
  logger&.error(e)
107
116
  end
108
117
 
109
- def safe_close_span(scope)
110
- return if scope.nil?
118
+ def safe_close_span(span)
119
+ return if span.nil?
111
120
 
112
- scope.close
121
+ span.finish
113
122
  rescue StandardError => e
114
123
  logger&.error(e)
115
124
  end
@@ -131,7 +140,7 @@ module OpenTracing
131
140
  end
132
141
 
133
142
  def build_tags(name, type)
134
- static_tags
143
+ protocol_tags
135
144
  .merge(tags_builder.build_message_tags(name, type))
136
145
  .compact
137
146
  end
@@ -24,6 +24,13 @@ module OpenTracing
24
24
  @error_writer = error_writer
25
25
  @logger = logger
26
26
  end
27
+
28
+ def ==(other)
29
+ tracer == other.tracer &&
30
+ tags_builder == other.tags_builder &&
31
+ operation_name_builder == other.operation_name_builder &&
32
+ error_writer == other.error_writer
33
+ end
27
34
  end
28
35
  end
29
36
  end
@@ -29,6 +29,7 @@ module OpenTracing
29
29
  # run thrift_app
30
30
  class TracedProtocolFactory < ::Thrift::BaseProtocolFactory
31
31
  def initialize(protocol_factory, config: TracedProtocolConfig.new)
32
+ super()
32
33
  @protocol_factory = protocol_factory
33
34
  @config = config
34
35
  end
@@ -10,8 +10,6 @@ module OpenTracing
10
10
  DEFAULT_OPERATION_NAME_PATTERN = \
11
11
  'thrift(direction=%<direction>s, name=%<name>s, type=%<type>s)'
12
12
 
13
- attr_reader :operation_name_pattern
14
-
15
13
  # @param operation_name_pattern [String]
16
14
  def initialize(
17
15
  operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN
@@ -28,6 +26,14 @@ module OpenTracing
28
26
  format(operation_name_pattern, **format_args)
29
27
  end
30
28
 
29
+ def ==(other)
30
+ operation_name_pattern == other.operation_name_pattern
31
+ end
32
+
33
+ protected
34
+
35
+ attr_reader :operation_name_pattern
36
+
31
37
  private
32
38
 
33
39
  def build_format_args(direction, name, type)
@@ -17,7 +17,7 @@ module OpenTracing
17
17
  }.merge(error_tags(type))
18
18
  end
19
19
 
20
- def build_static_tags(protocol)
20
+ def build_protocol_tags(protocol)
21
21
  transport = protocol.trans
22
22
  {
23
23
  'thrift.protocol' => build_protocol_name(protocol),
@@ -25,9 +25,13 @@ module OpenTracing
25
25
  }
26
26
  end
27
27
 
28
+ def ==(other)
29
+ self.class == other.class
30
+ end
31
+
28
32
  private
29
33
 
30
- NAME_PATTER = /((?<service_name>\w+):)?(?<method>\w+)/.freeze
34
+ NAME_PATTER = /(?:(?<service_name>\w+):)?(?<method>\w+)/.freeze
31
35
  SERVICE_NAME_PART = 'service_name'
32
36
  METHOD_PART = 'method'
33
37
 
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ['lib']
26
26
 
27
+ spec.required_ruby_version = "> #{File.read('.ruby-version').strip}"
28
+
27
29
  spec.add_runtime_dependency 'json'
28
30
  spec.add_runtime_dependency 'opentracing', '~> 0.5.0'
29
31
 
@@ -37,9 +39,9 @@ Gem::Specification.new do |spec|
37
39
  spec.add_development_dependency 'rake', '~> 13.0'
38
40
  spec.add_development_dependency 'redis', '~> 3.3.5'
39
41
  spec.add_development_dependency 'rspec', '~> 3.0'
40
- spec.add_development_dependency 'rubocop', '~> 0.80.0'
41
- spec.add_development_dependency 'rubocop-performance', '~> 1.5.2'
42
- spec.add_development_dependency 'rubocop-rspec', '~> 1.38.1'
43
- spec.add_development_dependency 'rubocop-thread_safety', '~> 0.3.4'
42
+ spec.add_development_dependency 'rubocop', '~> 1.15.0'
43
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11.3'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
45
+ spec.add_development_dependency 'rubocop-thread_safety', '~> 0.4.2'
44
46
  spec.add_development_dependency 'thrift', '~> 0.11.0'
45
47
  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.14
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fedorenko Dmitrij
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-02 00:00:00.000000000 Z
11
+ date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -184,56 +184,56 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 0.80.0
187
+ version: 1.15.0
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 0.80.0
194
+ version: 1.15.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rubocop-performance
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 1.5.2
201
+ version: 1.11.3
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: 1.5.2
208
+ version: 1.11.3
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rubocop-rspec
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 1.38.1
215
+ version: 2.3.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 1.38.1
222
+ version: 2.3.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: rubocop-thread_safety
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 0.3.4
229
+ version: 0.4.2
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: 0.3.4
236
+ version: 0.4.2
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: thrift
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -261,6 +261,7 @@ files:
261
261
  - ".gitlab-ci.yml"
262
262
  - ".rubocop.yml"
263
263
  - ".ruby-version"
264
+ - CHANGELOG.md
264
265
  - GEM_VERSION
265
266
  - Gemfile
266
267
  - Gemfile.lock
@@ -284,6 +285,7 @@ files:
284
285
  - lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb
285
286
  - lib/opentracing/instrumentation/common.rb
286
287
  - lib/opentracing/instrumentation/common/error_writer.rb
288
+ - lib/opentracing/instrumentation/common/operation_name_builder.rb
287
289
  - lib/opentracing/instrumentation/faraday.rb
288
290
  - lib/opentracing/instrumentation/faraday/response_logger.rb
289
291
  - lib/opentracing/instrumentation/faraday/trace_middleware.rb
@@ -298,6 +300,7 @@ files:
298
300
  - lib/opentracing/instrumentation/mongo/direct_sanitazer.rb
299
301
  - lib/opentracing/instrumentation/mongo/operation_name_builder.rb
300
302
  - lib/opentracing/instrumentation/mongo/query_sanitazer.rb
303
+ - lib/opentracing/instrumentation/mongo/sample_safety_argument_checker.rb
301
304
  - lib/opentracing/instrumentation/mongo/trace_subscriber.rb
302
305
  - lib/opentracing/instrumentation/object_wrapper.rb
303
306
  - lib/opentracing/instrumentation/rack.rb
@@ -320,6 +323,10 @@ files:
320
323
  - lib/opentracing/instrumentation/sinatra.rb
321
324
  - lib/opentracing/instrumentation/sinatra/trace_middleware.rb
322
325
  - lib/opentracing/instrumentation/thrift.rb
326
+ - lib/opentracing/instrumentation/thrift/traced_processor.rb
327
+ - lib/opentracing/instrumentation/thrift/traced_processor_config.rb
328
+ - lib/opentracing/instrumentation/thrift/traced_processor_operation_name_builder.rb
329
+ - lib/opentracing/instrumentation/thrift/traced_processor_tags_builder.rb
323
330
  - lib/opentracing/instrumentation/thrift/traced_protocol.rb
324
331
  - lib/opentracing/instrumentation/thrift/traced_protocol_config.rb
325
332
  - lib/opentracing/instrumentation/thrift/traced_protocol_factory.rb
@@ -331,23 +338,23 @@ homepage: https://gitlab.com/c0va23/ruby-opentracing-instrumentation.
331
338
  licenses:
332
339
  - MIT
333
340
  metadata: {}
334
- post_install_message:
341
+ post_install_message:
335
342
  rdoc_options: []
336
343
  require_paths:
337
344
  - lib
338
345
  required_ruby_version: !ruby/object:Gem::Requirement
339
346
  requirements:
340
- - - ">="
347
+ - - ">"
341
348
  - !ruby/object:Gem::Version
342
- version: '0'
349
+ version: 2.5.0
343
350
  required_rubygems_version: !ruby/object:Gem::Requirement
344
351
  requirements:
345
352
  - - ">="
346
353
  - !ruby/object:Gem::Version
347
354
  version: '0'
348
355
  requirements: []
349
- rubygems_version: 3.1.2
350
- signing_key:
356
+ rubygems_version: 3.1.6
357
+ signing_key:
351
358
  specification_version: 4
352
359
  summary: OpenTracing instrumentation for popular ruby libraries
353
360
  test_files: []