class Sentry::Span
Constants
- STATUS_MAP
Attributes
data[R]
description[R]
op[R]
parent_span_id[R]
sampled[R]
span_id[R]
span_recorder[RW]
start_timestamp[R]
status[R]
timestamp[R]
trace_id[R]
transaction[RW]
Public Class Methods
new( description: nil, op: nil, status: nil, trace_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil )
click to toggle source
# File lib/sentry/span.rb, line 24 def initialize( description: nil, op: nil, status: nil, trace_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil ) @trace_id = trace_id || SecureRandom.uuid.delete("-") @span_id = SecureRandom.hex(8) @parent_span_id = parent_span_id @sampled = sampled @start_timestamp = start_timestamp || Sentry.utc_now.to_f @timestamp = timestamp @description = description @op = op @status = status @data = {} @tags = {} end
Public Instance Methods
deep_dup()
click to toggle source
# File lib/sentry/span.rb, line 109 def deep_dup dup end
finish()
click to toggle source
# File lib/sentry/span.rb, line 47 def finish # already finished return if @timestamp @timestamp = Sentry.utc_now.to_f self end
get_trace_context()
click to toggle source
# File lib/sentry/span.rb, line 77 def get_trace_context { trace_id: @trace_id, span_id: @span_id, parent_span_id: @parent_span_id, description: @description, op: @op, status: @status } end
set_data(key, value)
click to toggle source
# File lib/sentry/span.rb, line 142 def set_data(key, value) @data[key] = value end
set_description(description)
click to toggle source
# File lib/sentry/span.rb, line 117 def set_description(description) @description = description end
set_http_status(status_code)
click to toggle source
# File lib/sentry/span.rb, line 129 def set_http_status(status_code) status_code = status_code.to_i set_data("status_code", status_code) status = if status_code >= 200 && status_code < 299 "ok" else STATUS_MAP[status_code] end set_status(status) end
set_op(op)
click to toggle source
# File lib/sentry/span.rb, line 113 def set_op(op) @op = op end
set_status(status)
click to toggle source
# File lib/sentry/span.rb, line 121 def set_status(status) @status = status end
set_tag(key, value)
click to toggle source
# File lib/sentry/span.rb, line 146 def set_tag(key, value) @tags[key] = value end
set_timestamp(timestamp)
click to toggle source
# File lib/sentry/span.rb, line 125 def set_timestamp(timestamp) @timestamp = timestamp end
start_child(**options)
click to toggle source
# File lib/sentry/span.rb, line 88 def start_child(**options) options = options.dup.merge(trace_id: @trace_id, parent_span_id: @span_id, sampled: @sampled) new_span = Span.new(**options) new_span.transaction = transaction new_span.span_recorder = span_recorder if span_recorder span_recorder.add(new_span) end new_span end
to_hash()
click to toggle source
# File lib/sentry/span.rb, line 62 def to_hash { trace_id: @trace_id, span_id: @span_id, parent_span_id: @parent_span_id, start_timestamp: @start_timestamp, timestamp: @timestamp, description: @description, op: @op, status: @status, tags: @tags, data: @data } end
to_sentry_trace()
click to toggle source
# File lib/sentry/span.rb, line 55 def to_sentry_trace sampled_flag = "" sampled_flag = @sampled ? 1 : 0 unless @sampled.nil? "#{@trace_id}-#{@span_id}-#{sampled_flag}" end
with_child_span(**options) { |child_span| ... }
click to toggle source
# File lib/sentry/span.rb, line 101 def with_child_span(**options, &block) child_span = start_child(**options) yield(child_span) child_span.finish end