Class: AppPerfRpm::Tracing::Span

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

Direct Known Subclasses

ManagedSpan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, operation_name, collector, opts = {}) ⇒ Span

Returns a new instance of Span.



9
10
11
12
13
14
15
16
17
# File 'lib/app_perf_rpm/tracing/span.rb', line 9

def initialize(context, operation_name, collector, opts = {})
  @context = context
  @operation_name = operation_name
  @collector = collector
  @start_time = opts[:start_time] || AppPerfRpm.now
  @end_time = nil
  @tags = opts[:tags] || {}
  @log_entries = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/app_perf_rpm/tracing/span.rb', line 8

def context
  @context
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



8
9
10
# File 'lib/app_perf_rpm/tracing/span.rb', line 8

def end_time
  @end_time
end

#log_entriesObject (readonly)

Returns the value of attribute log_entries.



8
9
10
# File 'lib/app_perf_rpm/tracing/span.rb', line 8

def log_entries
  @log_entries
end

#operation_nameObject

Returns the value of attribute operation_name.



6
7
8
# File 'lib/app_perf_rpm/tracing/span.rb', line 6

def operation_name
  @operation_name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



8
9
10
# File 'lib/app_perf_rpm/tracing/span.rb', line 8

def start_time
  @start_time
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/app_perf_rpm/tracing/span.rb', line 8

def tags
  @tags
end

Instance Method Details

#add_tags(tags) ⇒ Object



23
24
25
26
27
# File 'lib/app_perf_rpm/tracing/span.rb', line 23

def add_tags(tags)
  tags.each_pair do |key, value|
    set_tag(key, value)
  end
end

#exit(opts = {}) ⇒ Object



63
64
65
# File 'lib/app_perf_rpm/tracing/span.rb', line 63

def exit(opts = {})
  @end_time = opts[:end_time] || AppPerfRpm.now
end

#finish(opts = {}) ⇒ Object



67
68
69
# File 'lib/app_perf_rpm/tracing/span.rb', line 67

def finish(opts = {})
  @collector.send_span(self, @end_time || opts[:end_time] || AppPerfRpm.now)
end

#get_baggage_item(key) ⇒ Object



33
34
35
# File 'lib/app_perf_rpm/tracing/span.rb', line 33

def get_baggage_item(key)
  @context.get_baggage_item(key)
end

#log(opts = {}, *_, fields) ⇒ Object

Original definition for ruby 2+ was this: def log(opts = { :event => nil, :timestamp => AppPerfRpm.now }, **fields) but this doesn’t work in 1.9.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/app_perf_rpm/tracing/span.rb', line 40

def log(opts = {}, *_, fields)
  entry = {
    "event" => opts[:event] || nil,
    "timestamp" => opts[:timestamp] || AppPerfRpm.now,
  }

  entry["fields"] = fields
  @log_entries << entry

  nil
end

#log_error(exception, opts = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/app_perf_rpm/tracing/span.rb', line 52

def log_error(exception, opts = {})
  log(
    event: "error",
    timestamp: opts[:timestamp] || AppPerfRpm.now,
    message: exception.message,
    error_class: exception.class.to_s,
    backtrace: AppPerfRpm::Backtrace.clean(exception.backtrace),
    source: AppPerfRpm::Backtrace.source_extract(backtrace: exception.backtrace)
  )
end

#set_baggage_item(key, value) ⇒ Object



29
30
31
# File 'lib/app_perf_rpm/tracing/span.rb', line 29

def set_baggage_item(key, value)
  @context.set_baggage_item(key, value)
end

#set_tag(key, value) ⇒ Object



19
20
21
# File 'lib/app_perf_rpm/tracing/span.rb', line 19

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