module Traces::Backend::Test::Interface

def trace(name, resource: nil, attributes: nil, &block)

@parameter attributes [Hash] Metadata for the recorded span.
@parameter resource [String] The context in which the trace operation is occuring.
@parameter name [String] A useful name/annotation for the recorded span.
Trace the given block of code and validate the interface usage.
def trace(name, resource: nil, attributes: nil, &block)
	unless block_given?
		raise ArgumentError, "No block given!"
	end
	
	unless name.is_a?(String)
		raise ArgumentError, "Invalid name (must be String): #{name.inspect}!"
	end
	
	# It should be convertable:
	resource &&= resource.to_s
	
	context = Context.nested(Fiber.current.traces_backend_context)
	
	span = Span.new(context)
	
	# Ensure the attributes are valid and follow the requirements:
	attributes&.each do |key, value|
		span[key] = value
	end
	
	Fiber.current.traces_backend_context = context
	
	if block.arity.zero?
		yield
	else
		yield span
	end
end