opentracing-instrumentation 0.1.9 → 0.1.14

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: 69f4f1cfeeac35ba9ae9136f6da987d5d0fe6fc389983b48a931a80a384293ec
4
- data.tar.gz: 70418b1cd88602c5792b6e196211706b692cc4dfdc45de25ac296069171fa5a1
3
+ metadata.gz: 0deff013f5e114188fd45e5babe206deb828806074e5d5cdb64d2d0bd12039b9
4
+ data.tar.gz: b9db37bc148a276e95f6b9b843c8524ac0fcb81b9a136aa9e95532f7d18f9d25
5
5
  SHA512:
6
- metadata.gz: 115e8567b8dc553d0a5b566bfd51b433f74137402dd80903daac6afcf59c548bdff1f3534033d2cfc99cd138ce9d4a977648971aca3349235d973d1380d60312
7
- data.tar.gz: f41a753d755fb5e1fc409b7394c51877288ad410dc91bfa5141d1caa2100f94abe09c926a27bb3f71ccb11136514908e71c81b3d409f552510a2f1b981991070
6
+ metadata.gz: 7dac1db7d02ba70d447d2db46f28b31a2549e2d9636a9ead1013940af8e9338d5d75dfa6ce86a6d71b8eabbc26f17119be80b1110a9b0ccc3be8013f237b78a9
7
+ data.tar.gz: c604dfdd5b4f0e77f7bb5c29cc3a2c11e77540e6d8c69b901509af2f89c48575d6ff57cdc44d97e4f52ad4815a842684a16a723bfa874daa4ec9735fbc043e11
data/GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.14
data/Gemfile.lock CHANGED
@@ -18,7 +18,7 @@ GIT
18
18
  PATH
19
19
  remote: .
20
20
  specs:
21
- opentracing-instrumentation (0.1.9)
21
+ opentracing-instrumentation (0.1.14)
22
22
  json
23
23
  opentracing (~> 0.5.0)
24
24
 
@@ -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,19 +10,16 @@ module OpenTracing
10
10
  class TraceSubscriber
11
11
  include Forwardable
12
12
 
13
- DEFAULT_OPERATION_NAME_PATTERN = \
14
- 'mongo(collection=%<database>s.%<collection>s, command=%<command>s)'
15
-
16
13
  def initialize(
17
14
  tracer: OpenTracing.global_tracer,
18
15
  scope_store: {},
19
- operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN,
16
+ operation_name_builder: OperationNameBuilder.new,
20
17
  sanitazer: QuerySanitazer.new
21
18
  )
22
19
  @tracer = tracer
23
20
  @monitor = Monitor.new
24
21
  @scope_store = scope_store
25
- @operation_name_pattern = operation_name_pattern
22
+ @operation_name_builder = operation_name_builder
26
23
  @sanitazer = sanitazer
27
24
  end
28
25
 
@@ -49,18 +46,11 @@ module OpenTracing
49
46
  attr_reader :tracer
50
47
  attr_reader :scope_store
51
48
  attr_reader :monitor
52
- attr_reader :operation_name_pattern
49
+ attr_reader :operation_name_builder
53
50
  attr_reader :sanitazer
54
51
 
55
52
  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
- )
53
+ operation_name_builder.build_operation_name(event)
64
54
  end
65
55
 
66
56
  def base_tags(event)
@@ -28,7 +28,7 @@ module OpenTracing
28
28
  attr_reader :object
29
29
 
30
30
  def respond_to_missing?(method_name, *)
31
- object.response_to?(method_name)
31
+ object.respond_to?(method_name)
32
32
  end
33
33
 
34
34
  def method_missing(method_name, *args)
@@ -4,6 +4,8 @@ module OpenTracing
4
4
  module Instrumentation
5
5
  # Rack tracing middlewares
6
6
  module Rack
7
+ autoload :ExtractMiddleware,
8
+ 'opentracing/instrumentation/rack/extract_middleware'
7
9
  autoload :HttpTagger, 'opentracing/instrumentation/rack/http_tagger'
8
10
  autoload :RegexpHostSanitazer,
9
11
  'opentracing/instrumentation/rack/regexp_host_sanitazer'
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module OpenTracing
6
+ module Instrumentation
7
+ module Rack
8
+ # ExtractMiddleware extract trace context and push it to scope manager.
9
+ class ExtractMiddleware
10
+ # @private
11
+ class FakeSpan
12
+ attr_reader :context
13
+
14
+ def initialize(context)
15
+ @context = context
16
+ end
17
+ end
18
+
19
+ # @param app [RackApp] inner rack application
20
+ # @param tracer [OpenTracing::Tracer]
21
+ def initialize(app, tracer: OpenTracing.global_tracer)
22
+ @app = app
23
+ @tracer = tracer
24
+ end
25
+
26
+ # @param env [Hash<String, String>] rack env
27
+ def call(env)
28
+ span_context = @tracer.extract(OpenTracing::FORMAT_RACK, env)
29
+ return @app.call unless span_context
30
+
31
+ with_scope(span_context) do
32
+ @app.call(env)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def with_scope(span_context)
39
+ fake_span = FakeSpan.new(span_context)
40
+ scope = @tracer.scope_manager.activate(fake_span, finish_on_close: false)
41
+
42
+ yield
43
+ ensure
44
+ scope.close
45
+ end
46
+ end
47
+ end
48
+ end
49
+ 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.9
4
+ version: 0.1.14
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-04-01 00:00:00.000000000 Z
11
+ date: 2020-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -296,10 +296,12 @@ files:
296
296
  - lib/opentracing/instrumentation/hutch/global_properties_builder.rb
297
297
  - lib/opentracing/instrumentation/mongo.rb
298
298
  - lib/opentracing/instrumentation/mongo/direct_sanitazer.rb
299
+ - lib/opentracing/instrumentation/mongo/operation_name_builder.rb
299
300
  - lib/opentracing/instrumentation/mongo/query_sanitazer.rb
300
301
  - lib/opentracing/instrumentation/mongo/trace_subscriber.rb
301
302
  - lib/opentracing/instrumentation/object_wrapper.rb
302
303
  - lib/opentracing/instrumentation/rack.rb
304
+ - lib/opentracing/instrumentation/rack/extract_middleware.rb
303
305
  - lib/opentracing/instrumentation/rack/http_tagger.rb
304
306
  - lib/opentracing/instrumentation/rack/regexp_host_sanitazer.rb
305
307
  - lib/opentracing/instrumentation/rack/regexp_path_sanitazer.rb