test-tracer 1.1.4 → 1.2.0

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
  SHA1:
3
- metadata.gz: c710e73d40fc548607c8c7bd3f64fca63c51d4bf
4
- data.tar.gz: 73cefdc49a1b223ac4550eeb60cbaef22c1022d3
3
+ metadata.gz: 5aec92aa1df0c6211be3ea74a19b890a0d5eaa54
4
+ data.tar.gz: 0ca806b78e8a2dbb8212677855aabb5a3c44c7f8
5
5
  SHA512:
6
- metadata.gz: 6fc2cace5ee65ab2e6d92705247ba4fc8e3a7be02729162a68b46a24a5841d615e4ce46b3a85a62b4a94d775c1d6059fe5a528eda82e245e2fcfb148e31fb03a
7
- data.tar.gz: 589a369924d5c35a7180e41a07fc3c3dfbccc2016bb45cfb14ebe89bbfd84a687bc3d5eb4f518c8ec70295f80e8839c4c0ec58ec1ae5863bf08b4fae1d1bc6dd
6
+ metadata.gz: feb91c2c9de9ee123e6f93dde5b66bb2e7b7440c85a00433f5f21ccdd7c5de98ad9a71754c519c94b6ff4839ac96a4f6f2619f04393bcfc84c7453e4813dfb76
7
+ data.tar.gz: 7ddb95a3bf3870bb2700f37aeed719940c54456d24ff48511e0f574e0f907757b636d1b737be5c291f40f2677e3f0f3ede010ee7fedf9d9d3234bf90fda4a25f
data/README.md CHANGED
@@ -28,6 +28,9 @@ In addition to OT compatible methods `Test::Tracer` provides the following metho
28
28
  1. `spans` returns all spans, including those in progress.
29
29
  2. `finished_spans` returns only finished spans.
30
30
 
31
+ The tracer plays nicely with other wrapping tracers until your wrapped span, and span context implements `wrapped`
32
+ method. The method must return the wrapped item. You can customize the behaviour by implementing `Test::Wrapped::Extractor` and setting `wrapped_span_extractor` and/or `wrapped_span_context_extractor`.
33
+
31
34
  ### Usage
32
35
 
33
36
  ```ruby
@@ -1,10 +1,11 @@
1
1
  require 'opentracing'
2
2
 
3
- require_relative 'type_check'
3
+ require 'test/type_check'
4
4
  require 'test/id_provider'
5
5
  require 'test/span_context'
6
6
  require 'test/span'
7
7
  require 'test/propagation'
8
+ require 'test/wrapped'
8
9
 
9
10
  module Test
10
11
  class Tracer < OpenTracing::Tracer
@@ -13,8 +14,12 @@ module Test
13
14
  attr_reader :spans, :finished_spans
14
15
  attr_reader :injectors, :extractors
15
16
 
17
+ attr_accessor :wrapped_span_extractor
18
+ attr_accessor :wrapped_span_context_extractor
19
+
16
20
  attr_accessor :logger
17
21
 
22
+
18
23
  def initialize(logger: nil)
19
24
  @logger = logger
20
25
 
@@ -26,6 +31,10 @@ module Test
26
31
 
27
32
  register_codec(OpenTracing::FORMAT_TEXT_MAP, Propagation::TextMapCodec.new)
28
33
  register_codec(OpenTracing::FORMAT_RACK, Propagation::RackCodec.new)
34
+
35
+ default_extractor = Wrapped::DefaultExtractor.new
36
+ @wrapped_span_extractor = default_extractor
37
+ @wrapped_span_context_extractor = default_extractor
29
38
  end
30
39
 
31
40
  def register_injector(format, injector)
@@ -52,7 +61,7 @@ module Test
52
61
 
53
62
  # OT complaiant
54
63
  def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil)
55
- Type! child_of, ::Test::Span, ::Test::SpanContext, NilClass
64
+ child_of = extract_span(child_of) || extract_span_context(child_of)
56
65
 
57
66
  parent_context = child_of && child_of.respond_to?(:context) ? child_of.context : child_of
58
67
  new_context = parent_context ? ::Test::SpanContext.child_of(parent_context) : ::Test::SpanContext.root
@@ -68,8 +77,8 @@ module Test
68
77
 
69
78
  # OT complaiant
70
79
  def inject(span_context, format, carrier)
71
- Type! span_context, ::Test::SpanContext, NilClass
72
80
  NotNull! format
81
+ span_context = extract_span_context(span_context)
73
82
 
74
83
  return unless carrier
75
84
 
@@ -105,5 +114,21 @@ module Test
105
114
  def log(severity, message)
106
115
  logger.log(severity, message) if logger
107
116
  end
117
+
118
+ def extract_span(span)
119
+ if Type?(span, ::Test::Span, NilClass)
120
+ span
121
+ else
122
+ wrapped_span_extractor.extract(span) if wrapped_span_extractor
123
+ end
124
+ end
125
+
126
+ def extract_span_context(span_context)
127
+ if Type?(span_context, ::Test::SpanContext, NilClass)
128
+ span_context
129
+ else
130
+ wrapped_span_context_extractor.extract(span_context) if wrapped_span_context_extractor
131
+ end
132
+ end
108
133
  end
109
134
  end
@@ -0,0 +1,2 @@
1
+ require "test/wrapped/extractor"
2
+ require "test/wrapped/default_extractor"
@@ -0,0 +1,9 @@
1
+ module Test
2
+ module Wrapped
3
+ class DefaultExtractor
4
+ def extract(wrapper)
5
+ wrapper.wrapped if wrapper.respond_to?(:wrapped)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Test
2
+ module Wrapped
3
+ module Extractor
4
+ # Extract a wrapped span or span context.
5
+ #
6
+ # @param wrapper
7
+ # @return [Span, SpanContext, nil] the extracted Span, SpanContext or nil if none could be found
8
+ def extract(wrapper)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "test-tracer"
7
- spec.version = "1.1.4"
7
+ spec.version = "1.2.0"
8
8
  spec.authors = ["iaintshine"]
9
9
  spec.email = ["bodziomista@gmail.com"]
10
10
 
@@ -13,6 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/iaintshine/ruby-test-tracer"
14
14
  spec.license = "Apache-2.0"
15
15
 
16
+ spec.required_ruby_version = ">= 2.2.0"
17
+
16
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
19
  f.match(%r{^(test|spec|features)/})
18
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iaintshine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing
@@ -94,6 +94,9 @@ files:
94
94
  - lib/test/span_context.rb
95
95
  - lib/test/tracer.rb
96
96
  - lib/test/type_check.rb
97
+ - lib/test/wrapped.rb
98
+ - lib/test/wrapped/default_extractor.rb
99
+ - lib/test/wrapped/extractor.rb
97
100
  - test-tracer.gemspec
98
101
  homepage: https://github.com/iaintshine/ruby-test-tracer
99
102
  licenses:
@@ -107,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
110
  requirements:
108
111
  - - ">="
109
112
  - !ruby/object:Gem::Version
110
- version: '0'
113
+ version: 2.2.0
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
116
  - - ">="