Observability for Stagehand
Overview
Stagehand is an AI Browser Automation Framework developed by Browserbase.
Laminar provides native integration with Stagehand, allowing you to trace your Stagehand code with just a few lines of code.
Laminar observability captures:
- Full recording of a browser window while the code is running
- Execution steps, such as,
act
,extract
,observe
andagent
calls. - LLM cost of the execution steps
- Latency of the execution steps and LLM calls
Quickstart
Below is an example of a simple Stagehand script. Highlighted lines are the ones that are required to trace Stagehand with Laminar.
Step-by-step guide
Start with Stagehand Browser quickstart
Choose “Yes” when prompted to start with a quickstart app and follow other instructions.
Finally go to the newly created directory and install dependencies.
Install Laminar
Initialize Laminar
First, we need to initialize Laminar at the start of your application and pass the Stagehand module to instrumentModules
.
Finalizing Stagehand traces
If you run Stagehand in a standalone script, in order to flush queued Stagehand traces, make sure to call stagehand.close()
and Laminar.flush()
.
Example of a Stagehand trace
You can see entire session recording of a browser window while the code was running, along with execution steps, such as act
and extract
. You can also see LLM cost of the entire execution and of each execution step. For LLM spans you can see the prompt, the response and the model name.
An example trace for page.act('go to Laminar blogs page')