Class: AllStak::Modules::Span
- Inherits:
-
Object
- Object
- AllStak::Modules::Span
- Defined in:
- lib/allstak/modules/tracing.rb
Instance Attribute Summary collapse
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #finish(status = "ok") ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(trace_id:, span_id:, parent_span_id:, operation:, description:, service:, environment:, tags:, start_time_millis:, on_finish:, release: "") ⇒ Span
constructor
A new instance of Span.
- #set_description(description) ⇒ Object
- #set_tag(key, value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(trace_id:, span_id:, parent_span_id:, operation:, description:, service:, environment:, tags:, start_time_millis:, on_finish:, release: "") ⇒ Span
Returns a new instance of Span.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/allstak/modules/tracing.rb', line 110 def initialize(trace_id:, span_id:, parent_span_id:, operation:, description:, service:, environment:, tags:, start_time_millis:, on_finish:, release: "") @trace_id = trace_id @span_id = span_id @parent_span_id = parent_span_id @operation = operation @description = description @service = service @environment = environment @release = release @tags = .dup @start_time_millis = start_time_millis @end_time_millis = nil @status = "ok" @finished = false @on_finish = on_finish end |
Instance Attribute Details
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
108 109 110 |
# File 'lib/allstak/modules/tracing.rb', line 108 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
108 109 110 |
# File 'lib/allstak/modules/tracing.rb', line 108 def trace_id @trace_id end |
Instance Method Details
#finish(status = "ok") ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/allstak/modules/tracing.rb', line 142 def finish(status = "ok") return if @finished @finished = true @status = Tracing::VALID_STATUSES.include?(status) ? status : "ok" @end_time_millis = (Time.now.to_f * 1000).to_i @on_finish.call(self) end |
#finished? ⇒ Boolean
138 139 140 |
# File 'lib/allstak/modules/tracing.rb', line 138 def finished? @finished end |
#set_description(description) ⇒ Object
133 134 135 136 |
# File 'lib/allstak/modules/tracing.rb', line 133 def set_description(description) @description = description self end |
#set_tag(key, value) ⇒ Object
128 129 130 131 |
# File 'lib/allstak/modules/tracing.rb', line 128 def set_tag(key, value) @tags[key.to_s] = value.to_s self end |
#to_h ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/allstak/modules/tracing.rb', line 150 def to_h end_ms = @end_time_millis || (Time.now.to_f * 1000).to_i { traceId: @trace_id, spanId: @span_id, parentSpanId: @parent_span_id, operation: @operation, description: @description, status: @status, durationMs: end_ms - @start_time_millis, startTimeMillis: @start_time_millis, endTimeMillis: end_ms, service: @service, environment: @environment, release: @release, tags: @tags } end |