A novel optical scheme is proposed to perform path tracing in an all-optical packet-switched network. Prime-number-encoded tag is employed as the distinct network node or network link identifier. As the optical data packet traverses every network node, the path trace is recorded and updated optically, through prime number multiplication via an optical delay circuit encoder. Hence, all traversed network nodes along the path of a received optical data packet can be retrieved and identified at the destination node, via simple prime number factorization. Possible looping of optical data packets in the network can also be detected. The scheme can facilitate the connection management in an optical packet-switched network.