Class: Skywalking::Tracing::ContextManager

Inherits:
Object
  • Object
show all
Defined in:
lib/skywalking/tracing/span_context.rb

Class Method Summary collapse

Class Method Details

.current_contextObject



195
196
197
198
199
200
201
202
# File 'lib/skywalking/tracing/span_context.rb', line 195

def current_context
  spans_ret = spans
  if spans_ret.any?
    spans.last.context
  else
    SpanContext.new
  end
end

.new_entry_span(operation:, carrier: nil, inherit: nil, &block) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/skywalking/tracing/span_context.rb', line 216

def new_entry_span(operation:, carrier: nil, inherit: nil, &block)
  context = current_context
  span = context.new_entry_span(operation, carrier: carrier, inherit: inherit)
  span&.start

  begin
    yield span if block_given?
  ensure
    span&.stop?
  end
end

.new_exit_span(operation:, peer: nil, component: nil, inherit: nil, &block) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
# File 'lib/skywalking/tracing/span_context.rb', line 204

def new_exit_span(operation:, peer: nil, component: nil, inherit: nil, &block)
  context = current_context
  span = context.new_exit_span(operation, peer, component: component, inherit: inherit)
  span&.start

  begin
    yield span if block_given?
  ensure
    span&.stop?
  end
end

.new_local_span(operation:, &block) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/skywalking/tracing/span_context.rb', line 228

def new_local_span(operation:, &block)
  context = current_context
  span = context.new_local_span(operation)
  span&.start

  begin
    yield span if block_given?
  ensure
    span&.stop?
  end
end

.reset_spansObject



191
192
193
# File 'lib/skywalking/tracing/span_context.rb', line 191

def reset_spans
  Thread.current[:spans] = []
end

.spansObject



180
181
182
# File 'lib/skywalking/tracing/span_context.rb', line 180

def spans
  Thread.current[:spans] ||= []
end

.spans_dupObject



184
185
186
187
188
189
# File 'lib/skywalking/tracing/span_context.rb', line 184

def spans_dup
  spans_dup = spans.dup
  Thread.current[:spans] = spans_dup

  spans_dup
end