Class: Zipkin::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin/span.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, operation_name, collector, start_time: Time.now, tags: {}) ⇒ Span

Creates a new Zipkin::Span

Parameters:

  • context (SpanContext)

    the context of the span

  • operation_name (String)

    the operation name

  • collector (Collector)

    the span collector



14
15
16
17
18
19
20
# File 'lib/zipkin/span.rb', line 14

def initialize(context, operation_name, collector, start_time: Time.now, tags: {})
  @context = context
  @operation_name = operation_name
  @collector = collector
  @start_time = start_time
  @tags = tags
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/zipkin/span.rb', line 5

def context
  @context
end

#operation_nameObject

Returns the value of attribute operation_name.



3
4
5
# File 'lib/zipkin/span.rb', line 3

def operation_name
  @operation_name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



5
6
7
# File 'lib/zipkin/span.rb', line 5

def start_time
  @start_time
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/zipkin/span.rb', line 5

def tags
  @tags
end

Instance Method Details

#finish(end_time: Time.now) ⇒ Object

Finish the Zipkin::Span

Parameters:

  • end_time (Time) (defaults to: Time.now)

    custom end time, if not now



60
61
62
# File 'lib/zipkin/span.rb', line 60

def finish(end_time: Time.now)
  @collector.send_span(self, end_time)
end

#get_baggage_item(key) ⇒ Object

Get a baggage item

Parameters:

  • key (String)

    the key of the baggage item

Returns:

  • Value of the baggage item



44
45
46
# File 'lib/zipkin/span.rb', line 44

def get_baggage_item(key)
  nil
end

#log(event: nil, timestamp: Time.now, **fields) ⇒ Object

Add a log entry to this span

Parameters:

  • event (String) (defaults to: nil)

    event name for the log

  • timestamp (Time) (defaults to: Time.now)

    time of the log

  • fields (Hash)

    Additional information to log



53
54
55
# File 'lib/zipkin/span.rb', line 53

def log(event: nil, timestamp: Time.now, **fields)
  nil
end

#set_baggage_item(key, value) ⇒ Object

Set a baggage item on the span

Parameters:

  • key (String)

    the key of the baggage item

  • value (String)

    the value of the baggage item



35
36
37
# File 'lib/zipkin/span.rb', line 35

def set_baggage_item(key, value)
  self
end

#set_tag(key, value) ⇒ Object

Set a tag value on this span

a String, Numeric, or Boolean it will be encoded with to_s

Parameters:

  • key (String)

    the key of the tag

  • value (String, Numeric, Boolean)

    the value of the tag. If it’s not



27
28
29
# File 'lib/zipkin/span.rb', line 27

def set_tag(key, value)
  @tags = @tags.merge(key => value)
end