Class: Honeycomb::Span

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DeterministicSampler, PropagationSerializer, RollupFields
Defined in:
lib/honeycomb/span.rb

Overview

Represents a Honeycomb span, which wraps a Honeycomb event and adds specific tracing functionality

Constant Summary

Constants included from DeterministicSampler

DeterministicSampler::MAX_INT32

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RollupFields

#add_rollup_field, #rollup_fields

Methods included from DeterministicSampler

#should_sample

Methods included from HoneycombPropagation::MarshalTraceContext

clean_data, clean_string, encode_dataset, encode_trace_fields, parse_faraday_env, #to_trace_header, to_trace_header

Constructor Details

#initialize(trace:, builder:, context:, **options) ⇒ Span

Returns a new instance of Span.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/honeycomb/span.rb', line 24

def initialize(trace:,
               builder:,
               context:,
               **options)
  @id = generate_span_id
  @context = context
  @context.current_span = self
  @builder = builder
  @event = builder.event
  @trace = trace
  @children = []
  @sent = false
  @started = clock_time
  parse_options(**options)
  parse_hooks(**options)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/honeycomb/span.rb', line 22

def id
  @id
end

#traceObject (readonly)

Returns the value of attribute trace.



22
23
24
# File 'lib/honeycomb/span.rb', line 22

def trace
  @trace
end

Instance Method Details

#create_childObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/honeycomb/span.rb', line 65

def create_child
  self.class.new(trace: trace,
                 builder: builder,
                 context: context,
                 parent: self,
                 parent_id: id,
                 sample_hook: sample_hook,
                 presend_hook: presend_hook,
                 propagation_hook: propagation_hook).tap do |c|
    children << c
    @is_leaf = false
  end
end

#parse_hooks(sample_hook: nil, presend_hook: nil, propagation_hook: nil, **_options) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/honeycomb/span.rb', line 56

def parse_hooks(sample_hook: nil,
                presend_hook: nil,
                propagation_hook: nil,
                **_options)
  @presend_hook = presend_hook
  @sample_hook = sample_hook
  @propagation_hook = propagation_hook
end

#parse_options(parent: nil, parent_id: nil, is_root: parent_id.nil?, _sample_hook: nil, _presend_hook: nil, **_options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/honeycomb/span.rb', line 41

def parse_options(parent: nil,
                  parent_id: nil,
                  is_root: parent_id.nil?,
                  _sample_hook: nil,
                  _presend_hook: nil,
                  **_options)
  @parent = parent
  # parent_id should be removed in the next major version bump. It has been
  # replaced with passing the actual parent in. This is kept for backwards
  # compatability
  @parent_id = parent_id
  @is_root = is_root
  @is_leaf = true
end

#sendObject



79
80
81
82
83
# File 'lib/honeycomb/span.rb', line 79

def send
  return if sent?

  send_internal
end

#trace_headers(env) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/honeycomb/span.rb', line 85

def trace_headers(env)
  if propagation_hook
    propagation_hook.call(env, propagation_context)
  else
    {}
  end
end