class Sentry::Span
def deep_dup
def deep_dup dup end
def finish(end_timestamp: nil)
-
(self)
-
def finish(end_timestamp: nil) @timestamp = end_timestamp || @timestamp || Sentry.utc_now.to_f self end
def get_trace_context
-
(Hash)
-
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
def initialize(
def initialize( transaction:, description: nil, op: nil, status: nil, trace_id: nil, span_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil ) @trace_id = trace_id || SecureRandom.uuid.delete("-") @span_id = 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 @transaction = transaction @op = op @status = status @data = {} @tags = {} end
def set_data(key, value)
-
value
(Object
) -- -
key
(String, Symbol
) --
def set_data(key, value) @data[key] = value end
def set_description(description)
-
description
(String
) -- description of the span.
def set_description(description) @description = description end
def set_http_status(status_code)
-
status_code
(String
) -- example: "500".
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
def set_op(op)
-
op
(String
) -- operation of the span.
def set_op(op) @op = op end
def set_status(status)
-
satus
(String
) -- status of the span.
def set_status(status) @status = status end
def set_tag(key, value)
-
value
(String
) -- -
key
(String, Symbol
) --
def set_tag(key, value) @tags[key] = value end
def set_timestamp(timestamp)
-
timestamp
(Float
) -- finished time in float format (most precise).
def set_timestamp(timestamp) @timestamp = timestamp end
def start_child(**attributes)
-
attributes
(Hash
) -- the attributes for the child span.
def start_child(**attributes) attributes = attributes.dup.merge(transaction: @transaction, trace_id: @trace_id, parent_span_id: @span_id, sampled: @sampled) new_span = Span.new(**attributes) new_span.span_recorder = span_recorder if span_recorder span_recorder.add(new_span) end new_span end
def to_baggage
-
(String, nil)
-
def to_baggage transaction.get_baggage&.serialize end
def to_hash
-
(Hash)
-
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
def to_sentry_trace
-
(String)
-
def to_sentry_trace sampled_flag = "" sampled_flag = @sampled ? 1 : 0 unless @sampled.nil? "#{@trace_id}-#{@span_id}-#{sampled_flag}" end
def with_child_span(**attributes, &block)
- Yieldparam: child_span -
Parameters:
-
block
(Proc
) -- the action to be recorded in the child span. -
attributes
(Hash
) -- the attributes for the child span.
def with_child_span(**attributes, &block) child_span = start_child(**attributes) yield(child_span) child_span.finish rescue child_span.set_http_status(500) child_span.finish raise end