opentracing-instrumentation 0.1.1 → 0.1.2

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: 79f1742c93b198bb7928c48fd0331d0eb698d84c20380a82a607811b193972b4
4
- data.tar.gz: 9c849787447dc9a9e55ed146e68c6cc106eb3ce2e2ad753db21958747e5ba57a
3
+ metadata.gz: acb5d0dd01cab906babfd39d9ad99949eefcfa7f586c00883c0c9a606e66f642
4
+ data.tar.gz: 7051aa44a11889a29f33f853805734dc06efdc548e979fe83f8725a84d5f8b79
5
5
  SHA512:
6
- metadata.gz: d085afca97c026da18ffcaac48ce0c7906ea0de756f4fd563be3444941f43666f080e84c2f0e0c16502b9caa9445900e21161493bbd21f58bdce20ae4e7f825c
7
- data.tar.gz: df8544b857144ded2ad34ac802e63ae5e5b984ec40b17aed62002e164887dee0ab081f984ca1d5478e41d7e58c5d5a770e076c6f360861c30540662bec2f4807
6
+ metadata.gz: 784b8bb87a3a7e1b2ae054b32e3c3313d55809efcf567af1d72bd1d5a7f88e671450ea188e4d862bd5fd8bdc8cc8a8d29bcd4bcfd3ca6db41ee3aade85429a23
7
+ data.tar.gz: aff530e01d925b4dd77d587a37b48af25d57e51982ed25748621842b7c121422d7d3fe2cc35ebc2c5bd396708901c51927bc793dfaaa4fe2d0622a15dea33014
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -18,8 +18,8 @@ GIT
18
18
  PATH
19
19
  remote: .
20
20
  specs:
21
- opentracing-instrumentation (0.1.0)
22
- json (~> 2.0)
21
+ opentracing-instrumentation (0.1.1)
22
+ json
23
23
  opentracing (~> 0.5.0)
24
24
 
25
25
  GEM
@@ -83,7 +83,7 @@ PLATFORMS
83
83
 
84
84
  DEPENDENCIES
85
85
  bson (~> 4.0)
86
- bundler (~> 2.1.4)
86
+ bundler (= 2.1.4)
87
87
  faraday (~> 0.9.2)
88
88
  opentracing-instrumentation!
89
89
  pry-byebug (~> 3.8)
@@ -5,7 +5,15 @@ module OpenTracing
5
5
  # Rack tracing middlewares
6
6
  module Rack
7
7
  autoload :HttpTagger, 'opentracing/instrumentation/rack/http_tagger'
8
+ autoload :RegexpPathSanitazer,
9
+ 'opentracing/instrumentation/rack/regexp_path_sanitazer'
10
+ autoload :StaticCommandNameBuilder,
11
+ 'opentracing/instrumentation/rack/static_command_name_builder'
8
12
  autoload :TraceMiddleware, 'opentracing/instrumentation/rack/trace_middleware'
13
+ autoload :UnsafePathSanitazer,
14
+ 'opentracing/instrumentation/rack/unsafe_path_sanitazer'
15
+ autoload :UrlCommandNameBuilder,
16
+ 'opentracing/instrumentation/rack/url_command_name_builder'
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module OpenTracing
6
+ module Instrumentation
7
+ module Rack
8
+ # RegexpPathSanitazer return raw path
9
+ class RegexpPathSanitazer
10
+ DEFAULT_REPLACE_MAP = {
11
+ '/:object_id\1' => %r{/[0-9a-f]{24}(/|$)},
12
+ '/:sequence_id\1' => %r{/\d+(/|$)},
13
+ }.freeze
14
+
15
+ def initialize(
16
+ replace_map: DEFAULT_REPLACE_MAP
17
+ )
18
+ @replace_map = replace_map
19
+ end
20
+
21
+ def sanitaze_path(path)
22
+ @replace_map.each do |(target, regexp)|
23
+ path = path.gsub(regexp, target)
24
+ end
25
+ path
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTracing
4
+ module Instrumentation
5
+ module Rack
6
+ # StaticCommandNameBuilder build static command_name
7
+ class StaticCommandNameBuilder
8
+ DEFAULT_COMMAND_NAME = 'rack'
9
+
10
+ def initialize(
11
+ command_name: DEFAULT_COMMAND_NAME
12
+ )
13
+ @command_name = command_name
14
+ end
15
+
16
+ def build_command_name(_env)
17
+ @command_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,16 +7,18 @@ module OpenTracing
7
7
  module Rack
8
8
  # TraceMiddleware observer rack requests.
9
9
  class TraceMiddleware
10
+ DEFAULT_COMMAND_NAME_BUILDER = StaticCommandNameBuilder.new
11
+
10
12
  def initialize(
11
13
  app,
12
14
  logger: nil,
13
- command_name: 'rack',
15
+ command_name_builder: DEFAULT_COMMAND_NAME_BUILDER,
14
16
  http_tagger: HttpTagger.new,
15
17
  tracer: OpenTracing.global_tracer
16
18
  )
17
19
  @app = app
18
20
  @logger = logger
19
- @command_name = command_name
21
+ @command_name_builder = command_name_builder
20
22
  @http_tagger = http_tagger
21
23
  @tracer = tracer
22
24
  end
@@ -42,8 +44,9 @@ module OpenTracing
42
44
  def trace_request(env)
43
45
  extracted_ctx = tracer.extract(OpenTracing::FORMAT_RACK, env)
44
46
  logger&.info('Tracing context extracted') if extracted_ctx
47
+ command_name = @command_name_builder.build_command_name(env)
45
48
  tracer.start_active_span(
46
- @command_name,
49
+ command_name,
47
50
  child_of: extracted_ctx,
48
51
  tags: request_tags(env),
49
52
  ) do |scope|
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module OpenTracing
6
+ module Instrumentation
7
+ module Rack
8
+ # UnsafePathSanitazer return raw path
9
+ class UnsafePathSanitazer
10
+ def sanitaze_path(path)
11
+ path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module OpenTracing
6
+ module Instrumentation
7
+ module Rack
8
+ # UrlCommandNameBuilder build command name with request url
9
+ class UrlCommandNameBuilder
10
+ DEFAULT_COMMAND_PATTERN = \
11
+ 'rack(%<method>s %<schema>s://%<host>s:%<port>d%<path>s)'
12
+ DEFAULT_PORT = 80
13
+
14
+ def initialize(
15
+ command_pattern: DEFAULT_COMMAND_PATTERN,
16
+ path_sanitazer: RegexpPathSanitazer.new
17
+ )
18
+ @command_pattern = command_pattern
19
+ @path_sanitazer = path_sanitazer
20
+ end
21
+
22
+ def build_command_name(env)
23
+ format(@command_pattern, pattern_args(env))
24
+ end
25
+
26
+ private
27
+
28
+ def pattern_args(env)
29
+ path = env[::Rack::REQUEST_PATH]
30
+ sanitazed_path = @path_sanitazer.sanitaze_path(path)
31
+ {
32
+ schema: env[::Rack::RACK_URL_SCHEME],
33
+ method: env[::Rack::REQUEST_METHOD],
34
+ host: env[::Rack::HTTP_HOST],
35
+ port: env[::Rack::HTTP_PORT] || DEFAULT_PORT,
36
+ path: sanitazed_path,
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ 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.1
4
+ version: 0.1.2
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-20 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -212,7 +212,11 @@ files:
212
212
  - lib/opentracing/instrumentation/object_wrapper.rb
213
213
  - lib/opentracing/instrumentation/rack.rb
214
214
  - lib/opentracing/instrumentation/rack/http_tagger.rb
215
+ - lib/opentracing/instrumentation/rack/regexp_path_sanitazer.rb
216
+ - lib/opentracing/instrumentation/rack/static_command_name_builder.rb
215
217
  - lib/opentracing/instrumentation/rack/trace_middleware.rb
218
+ - lib/opentracing/instrumentation/rack/unsafe_path_sanitazer.rb
219
+ - lib/opentracing/instrumentation/rack/url_command_name_builder.rb
216
220
  - lib/opentracing/instrumentation/redis.rb
217
221
  - lib/opentracing/instrumentation/redis/config.rb
218
222
  - lib/opentracing/instrumentation/redis/span_builder.rb