Class: AllStak::Modules::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/allstak/modules/tracing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace_id:, span_id:, parent_span_id:, operation:, description:, service:, environment:, tags:, start_time_millis:, on_finish:, release: "", sampled: true) ⇒ Span

Returns a new instance of Span.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/allstak/modules/tracing.rb', line 172

def initialize(trace_id:, span_id:, parent_span_id:, operation:, description:,
               service:, environment:, tags:, start_time_millis:, on_finish:,
               release: "", sampled: true)
  @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 = tags.dup
  @start_time_millis = start_time_millis
  @end_time_millis = nil
  @status = "ok"
  @finished = false
  @sampled = sampled
  @on_finish = on_finish
end

Instance Attribute Details

#span_idObject (readonly)

Returns the value of attribute span_id.



170
171
172
# File 'lib/allstak/modules/tracing.rb', line 170

def span_id
  @span_id
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



170
171
172
# File 'lib/allstak/modules/tracing.rb', line 170

def trace_id
  @trace_id
end

Instance Method Details

#finish(status = "ok") ⇒ Object



210
211
212
213
214
215
216
# File 'lib/allstak/modules/tracing.rb', line 210

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

Returns:

  • (Boolean)


206
207
208
# File 'lib/allstak/modules/tracing.rb', line 206

def finished?
  @finished
end

#sampled?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/allstak/modules/tracing.rb', line 192

def sampled?
  @sampled
end

#set_description(description) ⇒ Object



201
202
203
204
# File 'lib/allstak/modules/tracing.rb', line 201

def set_description(description)
  @description = description
  self
end

#set_tag(key, value) ⇒ Object



196
197
198
199
# File 'lib/allstak/modules/tracing.rb', line 196

def set_tag(key, value)
  @tags[key.to_s] = value.to_s
  self
end

#to_hObject



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/allstak/modules/tracing.rb', line 218

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