Class: Jaeger::Client::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/jaeger/client/span.rb,
lib/jaeger/client/span/thrift_log_builder.rb,
lib/jaeger/client/span/thrift_tag_builder.rb

Defined Under Namespace

Classes: ThriftLogBuilder, ThriftTagBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, operation_name, reporter, start_time: Time.now, references: [], tags: {}) ⇒ Span

Creates a new Jaeger::Client::Span

Parameters:

  • context (SpanContext)

    the context of the span

  • operation_name (String)

    the operation name

  • reporter (#report)

    span reporter



20
21
22
23
24
25
26
27
28
# File 'lib/jaeger/client/span.rb', line 20

def initialize(context, operation_name, reporter, start_time: Time.now, references: [], tags: {})
  @context = context
  @operation_name = operation_name
  @reporter = reporter
  @start_time = start_time
  @references = references
  @tags = tags.map { |key, value| ThriftTagBuilder.build(key, value) }
  @logs = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def context
  @context
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def end_time
  @end_time
end

#logsObject (readonly)

Returns the value of attribute logs.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def logs
  @logs
end

#operation_nameObject

Returns the value of attribute operation_name.



9
10
11
# File 'lib/jaeger/client/span.rb', line 9

def operation_name
  @operation_name
end

#referencesObject (readonly)

Returns the value of attribute references.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def references
  @references
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def start_time
  @start_time
end

#tagsObject (readonly)

Returns the value of attribute tags.



11
12
13
# File 'lib/jaeger/client/span.rb', line 11

def tags
  @tags
end

Instance Method Details

#finish(end_time: Time.now) ⇒ Object

Parameters:

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

    custom end time, if not now



78
79
80
81
# File 'lib/jaeger/client/span.rb', line 78

def finish(end_time: Time.now)
  @end_time = end_time
  @reporter.report(self)
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



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

def get_baggage_item(key)
  nil
end

#log(*args) ⇒ Object

Deprecated.

Use #log_kv instead.

Add a log entry to this span



60
61
62
63
# File 'lib/jaeger/client/span.rb', line 60

def log(*args)
  warn 'Span#log is deprecated. Please use Span#log_kv instead.'
  log_kv(*args)
end

#log_kv(timestamp: Time.now, **fields) ⇒ Object

Add a log entry to this span

Parameters:

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

    time of the log

  • fields (Hash)

    Additional information to log



69
70
71
72
73
# File 'lib/jaeger/client/span.rb', line 69

def log_kv(timestamp: Time.now, **fields)
  # Using Thrift::Log to avoid unnecessary memory allocations
  @logs << ThriftLogBuilder.build(timestamp, 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



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

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



35
36
37
38
# File 'lib/jaeger/client/span.rb', line 35

def set_tag(key, value)
  # Using Thrift::Tag to avoid unnecessary memory allocations
  @tags << ThriftTagBuilder.build(key, value)
end