opentracing 0.3.0 → 0.3.1

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: 1aa24a8243b5906145ca38a2a509066fa09024aa
4
- data.tar.gz: 42cac5a5c026b285037f94d5e2f27c3d80512e58
3
+ metadata.gz: 61ca714ff9464163db6bb5a8a868c2047c107980
4
+ data.tar.gz: 8c796e19b4a5ce768e24e4479260a55de79c5c95
5
5
  SHA512:
6
- metadata.gz: 5889805e61bec036ddde3905e451c263efd7648d3e0ff342e6a09d6e871301379e1e4e8f290fc4ce7cb06035de486059133af2a1ee8b8f48f97d074f4fe4b0ee
7
- data.tar.gz: 9159f82bae1df53113dff8ff34d28f096bb43dc51b557f65beffa0b83ff660e832dcae5b9a3d7b4a23002201d1a4ab950605786b02fa385b5a98bd0886c374ea
6
+ metadata.gz: 79a42b7afe696afe3d476e778de5dc71889dea2b24e49206bd2201e7245b470fea039c3ce0510bcabc9dff46f90879fd5eeba237cb50b6a3beddc487848b78e0
7
+ data.tar.gz: 5ffb674ee8757cff0944129872bf8929f6987430adc2380a6b54e865482a41d93355d342a9bd3fea249f15d7217e657a1b3094a63594978b60b1294b51eb260d
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.1
4
+ - 2.3.4
5
+ - 2.4.1
6
+ - jruby-9.1.8.0
5
7
  before_install: gem install bundler -v 1.13.6
8
+ script: JRUBY_OPTS="--debug" bundle exec rake test
data/README.md CHANGED
@@ -75,16 +75,30 @@ span.finish
75
75
 
76
76
  ### Serializing to the wire
77
77
 
78
+ Using `Net::HTTP`:
78
79
  ```ruby
79
80
  client = Net::HTTP.new("http://myservice")
80
81
  req = Net::HTTP::Post.new("/")
81
82
 
82
83
  span = OpenTracing.start_span("my_span")
83
- OpenTracing.inject(span.context, OpenTracing::FORMAT_RACK, env)
84
+ OpenTracing.inject(span.context, OpenTracing::FORMAT_RACK, req)
84
85
  res = client.request(req)
85
86
  #...
86
87
  ```
87
88
 
89
+ Using Faraday middleware:
90
+ ```ruby
91
+ class TraceMiddleware < Faraday::Middleware
92
+ def call(env)
93
+ span = OpenTracing.start_span("my_span")
94
+ OpenTracing.inject(span.context, OpenTracing::FORMAT_RACK, env)
95
+ @app.call(env).on_complete do
96
+ span.finish
97
+ end
98
+ end
99
+ end
100
+ ```
101
+
88
102
  ### Deserializing from the wire
89
103
 
90
104
  The OpenTracing Ruby gem provides a specific Rack header extraction format,
@@ -2,6 +2,7 @@ require "forwardable"
2
2
  require "opentracing/version"
3
3
  require "opentracing/span_context"
4
4
  require "opentracing/span"
5
+ require "opentracing/reference"
5
6
  require "opentracing/tracer"
6
7
 
7
8
  module OpenTracing
@@ -30,8 +31,8 @@ module OpenTracing
30
31
 
31
32
  class << self
32
33
  extend Forwardable
33
- # Global tracer to be used when OpenTracing.start_span is called
34
+ # Global tracer to be used when OpenTracing.start_span, inject or extract is called
34
35
  attr_accessor :global_tracer
35
- def_delegator :global_tracer, :start_span
36
+ def_delegators :global_tracer, :start_span, :inject, :extract
36
37
  end
37
38
  end
@@ -0,0 +1,88 @@
1
+ module OpenTracing
2
+ class Reference
3
+ CHILD_OF = 'child_of'.freeze
4
+ FOLLOWS_FROM = 'follows_from'.freeze
5
+
6
+ # @param context [SpanContext, Span] child_of context refers to a
7
+ # parent Span that caused *and* somehow depends upon the new child Span.
8
+ # Often (but not always), the parent Span cannot finish until the child
9
+ # Span does.
10
+ #
11
+ # An timing diagram for a child Span that is blocked on the new Span:
12
+ #
13
+ # [-Parent Span----------]
14
+ # [-Child Span----]
15
+ #
16
+ # See http://opentracing.io/documentation/pages/spec
17
+ #
18
+ # @return [Reference] a ChildOf reference
19
+ #
20
+ # @example
21
+ # root_span = OpenTracing.start_span('root operation')
22
+ # child_span = OpenTracing.start_span('child operation', references: [
23
+ # OpenTracing::Reference.child_of(root_span)
24
+ # ])
25
+ #
26
+ def self.child_of(context)
27
+ if context.is_a?(Span)
28
+ context = context.context
29
+ end
30
+
31
+ Reference.new(CHILD_OF, context)
32
+ end
33
+
34
+ # @param context [SpanContext, Span] follows_from context refers to a
35
+ # parent Span that does not depend in any way on the result of the new
36
+ # child Span. For instance, one might use FollowsFrom Span to describe
37
+ # pipeline stages separated by queues, or a fire-and-forget cache insert
38
+ # at the tail end of a web request.
39
+ #
40
+ # A FollowsFrom Span is part of the same logical trace as the new Span:
41
+ # i.e., the new Span is somehow caused by the work of its FollowsFrom
42
+ # Span.
43
+ #
44
+ # All of the following could be valid timing diagrams for children that
45
+ # "FollowFrom" a parent:
46
+ #
47
+ # [-Parent Span--] [-Child Span-]
48
+ #
49
+ # [-Parent Span--]
50
+ # [-Child Span-]
51
+ #
52
+ # [-Parent Span-]
53
+ # [-Child Span-]
54
+ #
55
+ # See http://opentracing.io/documentation/pages/spec
56
+ #
57
+ # @return [Reference] a FollowsFrom reference
58
+ #
59
+ # @example
60
+ # context = OpenTracing.extract(OpenTracing::FORMAT_RACK, rack_env)
61
+ # span = OpenTracing.start_span('following operation', references: [
62
+ # OpenTracing::Reference.follows_from(context)
63
+ # ])
64
+ #
65
+ def self.follows_from(context)
66
+ if context.is_a?(Span)
67
+ context = context.context
68
+ end
69
+
70
+ Reference.new(FOLLOWS_FROM, context)
71
+ end
72
+
73
+ def initialize(type, context)
74
+ @type = type
75
+ @context = context
76
+ end
77
+
78
+ # Return [String] reference type
79
+ def type
80
+ @type
81
+ end
82
+
83
+ # @return [SpanContext] the context of a span this reference is referencing
84
+ def context
85
+ @context
86
+ end
87
+ end
88
+ end
@@ -1,27 +1,23 @@
1
1
  module OpenTracing
2
- # Span represents an OpenTracer Span
2
+ # Span represents an OpenTracing Span
3
3
  #
4
4
  # See http://www.opentracing.io for more information.
5
5
  class Span
6
6
  NOOP_INSTANCE = Span.new.freeze
7
7
 
8
8
  # Set the name of the operation
9
+ #
10
+ # @param [String] name
9
11
  def operation_name=(name)
10
12
  end
11
13
 
12
14
  # Span Context
15
+ #
16
+ # @return [SpanContext]
13
17
  def context
14
18
  SpanContext::NOOP_INSTANCE
15
19
  end
16
20
 
17
- # Creates a new {Span}
18
- #
19
- # @param tracer [Tracer] the tracer that created this span
20
- # @param context [SpanContext] the context of the span
21
- # @return [Span] a new Span
22
- def initialize(tracer:, context:)
23
- end
24
-
25
21
  # Set a tag value on this span
26
22
  # @param key [String] the key of the tag
27
23
  # @param value [String, Numeric, Boolean] the value of the tag. If it's not
@@ -39,7 +35,7 @@ module OpenTracing
39
35
 
40
36
  # Get a baggage item
41
37
  # @param key [String] the key of the baggage item
42
- # @return Value of the baggage item
38
+ # @return [String] value of the baggage item
43
39
  def get_baggage_item(key)
44
40
  nil
45
41
  end
@@ -1,17 +1,25 @@
1
1
  module OpenTracing
2
2
  class Tracer
3
- # TODO(bhs): Support FollowsFrom and multiple references
4
-
5
3
  # Starts a new span.
6
4
  #
7
5
  # @param operation_name [String] The operation name for the Span
8
- # @param child_of [SpanContext] SpanContext that acts as a parent to
6
+ #
7
+ # @param child_of [SpanContext, Span] SpanContext that acts as a parent to
9
8
  # the newly-started Span. If a Span instance is provided, its
10
- # .span_context is automatically substituted.
9
+ # context is automatically substituted. See [Reference] for more
10
+ # information.
11
+ #
12
+ # If specified, the `references` paramater must be omitted.
13
+ #
14
+ # @param references [Array<Reference>] An array of reference
15
+ # objects that identify one or more parent SpanContexts.
16
+ #
11
17
  # @param start_time [Time] When the Span started, if not now
18
+ #
12
19
  # @param tags [Hash] Tags to assign to the Span at start time
20
+ #
13
21
  # @return [Span] The newly-started Span
14
- def start_span(operation_name, child_of: nil, start_time: Time.now, tags: nil)
22
+ def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil)
15
23
  Span::NOOP_INSTANCE
16
24
  end
17
25
 
@@ -33,7 +41,7 @@ module OpenTracing
33
41
  #
34
42
  # @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
35
43
  # @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
36
- # @return [SpanContext] the extracted SpanContext or nil if none could be found
44
+ # @return [SpanContext, nil] the extracted SpanContext or nil if none could be found
37
45
  def extract(format, carrier)
38
46
  case format
39
47
  when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK
@@ -1,3 +1,3 @@
1
1
  module OpenTracing
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ngauthier
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-02-16 00:00:00.000000000 Z
13
+ date: 2017-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -101,6 +101,7 @@ files:
101
101
  - bin/setup
102
102
  - lib/opentracing.rb
103
103
  - lib/opentracing/carrier.rb
104
+ - lib/opentracing/reference.rb
104
105
  - lib/opentracing/span.rb
105
106
  - lib/opentracing/span_context.rb
106
107
  - lib/opentracing/tracer.rb