I think you must be referring to Hamlet's plan to put on the play, "The Mousetrap" in front of Claudius to see if he can see any signs of guilt. It's the nearest thing I can think of to Hamlet actually spying on anyone - though he is spied on - at least, observed - himself by Polonius earlier in the scene, sort of.
Hamlet decides to put on the play to trap Claudius, and watch him in the audience, to see his reaction:
Hum, I have heard
That guilty creatures, sitting at a play,
Have by the very cunning of the scene
Been struck so to the soul that presently
They have proclaim'd their malefactions.
Though the play scene itself doesn't actually occur in Act 2: only Hamlet's idea and his revelation of the plan in his soliloquy right at the end of Act 2, Scene 2.
Do post again if this isn't what you mean - or you need further help.