Class: NewRelic::TelemetrySdk::Span
- Inherits:
-
Object
- Object
- NewRelic::TelemetrySdk::Span
show all
- Includes:
- Logger
- Defined in:
- lib/newrelic/telemetry_sdk/span.rb
Overview
This class represents a timed operation that is part of a distributed trace. This operation will be represented as a Span in the New Relic UI.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
#clear_already_logged, #log_error, #log_once, logger, #logger, logger=, #logger=
Constructor Details
#initialize(id: Util.generate_guid(16), trace_id: Util.generate_guid(32), start_time: Util.current_time, duration_ms: nil, name: nil, parent_id: nil, service_name: nil, custom_attributes: nil) ⇒ Span
Returns a new instance of Span.
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 45
def initialize id: Util.generate_guid(16),
trace_id: Util.generate_guid(32),
start_time: Util.current_time,
duration_ms: nil,
name: nil,
parent_id: nil,
service_name: nil,
custom_attributes: nil
@id = id
@trace_id = trace_id
@start_time = start_time
@duration_ms = duration_ms
@name = name
@parent_id = parent_id
@service_name = service_name
@custom_attributes = custom_attributes
end
|
Instance Attribute Details
#custom_attributes ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def custom_attributes
@custom_attributes
end
|
#duration_ms ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def duration_ms
@duration_ms
end
|
#id ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def id
@id
end
|
#name ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def name
@name
end
|
#parent_id ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def parent_id
@parent_id
end
|
#service_name ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def service_name
@service_name
end
|
#start_time ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def start_time
@start_time
end
|
#trace_id ⇒ Object
15
16
17
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 15
def trace_id
@trace_id
end
|
Instance Method Details
#finish(end_time: Util.current_time) ⇒ Object
Mark the operation represented by this Span as finished and calculate is duration.
70
71
72
73
74
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 70
def finish end_time: Util.current_time
@duration_ms = Util.time_to_ms(end_time - @start_time)
rescue => e
log_error "Encountered error finishing span", e
end
|
#to_h ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/newrelic/telemetry_sdk/span.rb', line 76
def to_h
data = {
:id => @id,
:'trace.id' => @trace_id,
:timestamp => Util.time_to_ms(@start_time),
:attributes => {
:'duration.ms' => @duration_ms,
:name => @name,
:'parent.id' => @parent_id,
:'service.name' => @service_name
}
}
data[:attributes].merge! @custom_attributes if @custom_attributes
data
rescue => e
log_error "Encountered error converting span to hash", e
end
|