Class: Sentry::Span
Direct Known Subclasses
Constant Summary collapse
- STATUS_MAP =
{ 400 => "invalid_argument", 401 => "unauthenticated", 403 => "permission_denied", 404 => "not_found", 409 => "already_exists", 429 => "resource_exhausted", 499 => "cancelled", 500 => "internal_error", 501 => "unimplemented", 503 => "unavailable", 504 => "deadline_exceeded" }
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#parent_span_id ⇒ Object
readonly
Returns the value of attribute parent_span_id.
-
#sampled ⇒ Object
readonly
Returns the value of attribute sampled.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#span_recorder ⇒ Object
Returns the value of attribute span_recorder.
-
#start_timestamp ⇒ Object
readonly
Returns the value of attribute start_timestamp.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #deep_dup ⇒ Object
- #finish ⇒ Object
- #get_trace_context ⇒ Object
-
#initialize(description: nil, op: nil, status: nil, trace_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil) ⇒ Span
constructor
A new instance of Span.
- #set_data(key, value) ⇒ Object
- #set_description(description) ⇒ Object
- #set_http_status(status_code) ⇒ Object
- #set_op(op) ⇒ Object
- #set_status(status) ⇒ Object
- #set_tag(key, value) ⇒ Object
- #set_timestamp(timestamp) ⇒ Object
- #start_child(**options) ⇒ Object
- #to_hash ⇒ Object
- #to_sentry_trace ⇒ Object
- #with_child_span(**options) {|child_span| ... } ⇒ Object
Constructor Details
#initialize(description: nil, op: nil, status: nil, trace_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil) ⇒ Span
Returns a new instance of Span.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 = || Sentry.utc_now.to_f @timestamp = @description = description @op = op @status = status @data = {} @tags = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def data @data end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def description @description end |
#op ⇒ Object (readonly)
Returns the value of attribute op.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def op @op end |
#parent_span_id ⇒ Object (readonly)
Returns the value of attribute parent_span_id.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def parent_span_id @parent_span_id end |
#sampled ⇒ Object (readonly)
Returns the value of attribute sampled.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def sampled @sampled end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def span_id @span_id end |
#span_recorder ⇒ Object
Returns the value of attribute span_recorder.
22 23 24 |
# File 'lib/sentry/span.rb', line 22 def span_recorder @span_recorder end |
#start_timestamp ⇒ Object (readonly)
Returns the value of attribute start_timestamp.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def @start_timestamp end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def @tags end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def @timestamp end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
21 22 23 |
# File 'lib/sentry/span.rb', line 21 def trace_id @trace_id end |
Instance Method Details
#deep_dup ⇒ Object
92 93 94 |
# File 'lib/sentry/span.rb', line 92 def deep_dup dup end |
#finish ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/sentry/span.rb', line 38 def finish # already finished return if @timestamp @timestamp = Sentry.utc_now.to_f self end |
#get_trace_context ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sentry/span.rb', line 68 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) ⇒ Object
125 126 127 |
# File 'lib/sentry/span.rb', line 125 def set_data(key, value) @data[key] = value end |
#set_description(description) ⇒ Object
100 101 102 |
# File 'lib/sentry/span.rb', line 100 def set_description(description) @description = description end |
#set_http_status(status_code) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sentry/span.rb', line 112 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) ⇒ Object
96 97 98 |
# File 'lib/sentry/span.rb', line 96 def set_op(op) @op = op end |
#set_status(status) ⇒ Object
104 105 106 |
# File 'lib/sentry/span.rb', line 104 def set_status(status) @status = status end |
#set_tag(key, value) ⇒ Object
129 130 131 |
# File 'lib/sentry/span.rb', line 129 def set_tag(key, value) @tags[key] = value end |
#set_timestamp(timestamp) ⇒ Object
108 109 110 |
# File 'lib/sentry/span.rb', line 108 def () @timestamp = end |
#start_child(**options) ⇒ Object
79 80 81 82 |
# File 'lib/sentry/span.rb', line 79 def start_child(**) = .dup.merge(trace_id: @trace_id, parent_span_id: @span_id, sampled: @sampled) Span.new(**) end |
#to_hash ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sentry/span.rb', line 53 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 ⇒ Object
46 47 48 49 50 51 |
# File 'lib/sentry/span.rb', line 46 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| ... } ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/sentry/span.rb', line 84 def with_child_span(**, &block) child_span = start_child(**) yield(child_span) child_span.finish end |