Class: OpenTracing::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/opentracing/reference.rb

Overview

:nodoc:

Constant Summary collapse

CHILD_OF =
'child_of'.freeze
FOLLOWS_FROM =
'follows_from'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, context) ⇒ Reference

Returns a new instance of Reference.



68
69
70
71
# File 'lib/opentracing/reference.rb', line 68

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

Instance Attribute Details

#contextSpanContext (readonly)

Returns the context of a span this reference is referencing.

Returns:

  • (SpanContext)

    the context of a span this reference is referencing



77
78
79
# File 'lib/opentracing/reference.rb', line 77

def context
  @context
end

#typeString (readonly)

Returns reference type.

Returns:

  • (String)

    reference type



74
75
76
# File 'lib/opentracing/reference.rb', line 74

def type
  @type
end

Class Method Details

.child_of(context) ⇒ Reference

Returns a ChildOf reference.

Examples:

root_span = OpenTracing.start_span('root operation')
child_span = OpenTracing.start_span('child operation', references: [
  OpenTracing::Reference.child_of(root_span)
])

Parameters:

  • 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 opentracing.io/documentation/pages/spec

Returns:



27
28
29
30
# File 'lib/opentracing/reference.rb', line 27

def self.child_of(context)
  context = context.context if context.is_a?(Span)
  Reference.new(CHILD_OF, context)
end

.follows_from(context) ⇒ Reference

Returns a FollowsFrom reference.

Examples:

context = OpenTracing.extract(OpenTracing::FORMAT_RACK, rack_env)
span = OpenTracing.start_span('following operation', references: [
  OpenTracing::Reference.follows_from(context)
])

Parameters:

  • 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 opentracing.io/documentation/pages/spec

Returns:



63
64
65
66
# File 'lib/opentracing/reference.rb', line 63

def self.follows_from(context)
  context = context.context if context.is_a?(Span)
  Reference.new(FOLLOWS_FROM, context)
end