File: reference.rb

package info (click to toggle)
ruby-opentracing 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 160 kB
  • sloc: ruby: 158; makefile: 4; sh: 4
file content (79 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module OpenTracing
  #:nodoc:
  class Reference
    CHILD_OF = 'child_of'.freeze
    FOLLOWS_FROM = 'follows_from'.freeze

    # @param context [SpanContext, Span] child_of context refers to a
    #   parent Span that caused *and* somehow depends upon the new child Span.
    #   Often (but not always), the parent Span cannot finish until the child
    #   Span does.
    #
    #   An timing diagram for a child Span that is blocked on the new Span:
    #
    #     [-Parent Span----------]
    #          [-Child Span----]
    #
    #   See http://opentracing.io/documentation/pages/spec
    #
    # @return [Reference] a ChildOf reference
    #
    # @example
    #   root_span = OpenTracing.start_span('root operation')
    #   child_span = OpenTracing.start_span('child operation', references: [
    #     OpenTracing::Reference.child_of(root_span)
    #   ])
    #
    def self.child_of(context)
      context = context.context if context.is_a?(Span)
      Reference.new(CHILD_OF, context)
    end

    # @param context [SpanContext, Span] follows_from context refers to a
    #   parent Span that does not depend in any way on the result of the new
    #   child Span. For instance, one might use FollowsFrom Span to describe
    #   pipeline stages separated by queues, or a fire-and-forget cache insert
    #   at the tail end of a web request.
    #
    #   A FollowsFrom Span is part of the same logical trace as the new Span:
    #   i.e., the new Span is somehow caused by the work of its FollowsFrom
    #   Span.
    #
    #   All of the following could be valid timing diagrams for children that
    #   "FollowFrom" a parent:
    #
    #     [-Parent Span--]  [-Child Span-]
    #
    #     [-Parent Span--]
    #      [-Child Span-]
    #
    #     [-Parent Span-]
    #                [-Child Span-]
    #
    #   See http://opentracing.io/documentation/pages/spec
    #
    # @return [Reference] a FollowsFrom reference
    #
    # @example
    #   context = OpenTracing.extract(OpenTracing::FORMAT_RACK, rack_env)
    #   span = OpenTracing.start_span('following operation', references: [
    #     OpenTracing::Reference.follows_from(context)
    #   ])
    #
    def self.follows_from(context)
      context = context.context if context.is_a?(Span)
      Reference.new(FOLLOWS_FROM, context)
    end

    def initialize(type, context)
      @type = type
      @context = context
    end

    # @return [String] reference type
    attr_reader :type

    # @return [SpanContext] the context of a span this reference is referencing
    attr_reader :context
  end
end