Module: Traces::Backend::Test::Interface

Defined in:
lib/traces/backend/test.rb

Instance Method Summary collapse

Instance Method Details

#trace(name, attributes: nil, &block) ⇒ Object

Trace the given block of code and validate the interface usage.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/traces/backend/test.rb', line 60

def trace(name, attributes: nil, &block)
	unless name.is_a?(String)
		raise ArgumentError, "Invalid name!"
	end
	
	context = Context.nested(Fiber.current.traces_backend_context)
	Fiber.current.traces_backend_context = context
	
	if block.arity.zero?
		yield
	else
		span = Span.new(context)
		yield span
	end
end

#trace_context(span = nil) ⇒ Object

Get a trace context from the current execution scope.



83
84
85
86
87
88
89
# File 'lib/traces/backend/test.rb', line 83

def trace_context(span = nil)
	if span
		span.context
	else
		Fiber.current.traces_backend_context
	end
end

#trace_context=(context) ⇒ Object

Assign a trace context to the current execution scope.



77
78
79
# File 'lib/traces/backend/test.rb', line 77

def trace_context= context
	Fiber.current.traces_backend_context = context
end