npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@respan/instrumentation-stagehand

v0.1.0

Published

Respan instrumentation plugin for Stagehand v4 browser agents (@browserbasehq/stagehand)

Downloads

406

Readme

@respan/instrumentation-stagehand

Respan tracing for Stagehand v4 (@browserbasehq/stagehand) browser agents.

npm install @respan/respan @respan/instrumentation-stagehand @browserbasehq/stagehand
import { localBrowser, Stagehand } from "@browserbasehq/stagehand";
import { Respan } from "@respan/respan";
import { StagehandInstrumentor } from "@respan/instrumentation-stagehand";

const respan = new Respan({ instrumentations: [new StagehandInstrumentor()] }); // RESPAN_API_KEY
await respan.initialize();

const browser = await localBrowser.launch();
const stagehand = await Stagehand.create({
  browser,
  model: { modelName: "openai/gpt-5.4-mini", apiKey: process.env.OPENAI_API_KEY },
});
const [page] = await browser.context.pages();
await page.goto("https://news.ycombinator.com");
await stagehand.act("click the 'new' link");
await stagehand.close();
await browser.close();
await respan.shutdown(); // short scripts: send spans before the process exits

Requires Stagehand 4.2 or later (v4's Stagehand.create API) and Node.js 22.18+. Stagehand v3 (new Stagehand() + init()) is not covered.

What is traced

stagehand.session        agent   Stagehand.create() ... close(): settings in; operations, failures, token totals out
├─ stagehand.act         task    instruction, options (variable names only), result, cache status, screenshot after the act
│  └─ stagehand.llm      chat    every inference: prompt, completion, model, tokens
├─ stagehand.extract     task    instruction, JSON schema, extracted data
├─ stagehand.observe     task    instruction, suggested actions with their selectors
└─ page.goto, locator.fill, page.screenshot, context.newPage, ...   tool
  • One trace per session. Every span of a Stagehand instance shares its trace, and its thread, session and trace-group identifiers default to the session id (the Browserbase session id when there is one). Values set with respan.propagateAttributes({ thread_identifier, group_identifier, ... }) win. customer_identifier and the other propagated fields reach every span. Customer metadata is exported as one flat respan.metadata.<key> attribute per key, the shape Respan ingestion reads.
  • LLM calls. Stagehand v4 runs its inference inside its Chrome extension.
    • With a client model (model: { generate }) every inference comes back to your process, so each one is a full chat span: messages (with images), response format or tools, completion, and tokens. Pass clientModelName so Respan knows which model it was and can price it. A client model is also how you route Stagehand through the Respan gateway or any OpenAI-compatible endpoint, since v4's built-in models take no base URL.
    • With a built-in model (model: { modelName, apiKey }), Stagehand only reports each operation's token totals. Each operation then gets one content-free chat span with those tokens and the model name, so usage and cost still show up.
  • Concurrent operations. Operations running at once on one session (for example extract on two pages) keep their own LLM calls. Stagehand gives the callback no operation id, so the prompt is matched against each running operation's instruction; two identical instructions running at the same time on one session cannot be told apart.
  • Screenshots. After each act, the page is captured as a JPEG and attached to the act span's output. Respan stores it as log media and shows it in the log view. That is one extra screenshot round trip per act (bounded to a few seconds); captureScreenshots: false skips it. page.screenshot() calls show their image too.
  • Secrets. Values passed as variables to act / observe are replaced by their %name% placeholder in every span of the session, including errors. Text typed with locator.fill / locator.type / page.type is exported as [redacted] when the target field is a credential (a password input, or a name, id or autocomplete that says password, token, one-time code, card number, and so on). The page is asked for the field's attributes, since selectors from observe() say nothing about the field. When the field cannot be identified, the text is redacted.
  • Errors. Failed operations and browser actions are error spans with Type: message. An act that Stagehand reports as unsuccessful is an error span too.
  • No duplicate spans. Stagehand's own OpenTelemetry RPC spans stay out of Respan exports, and provider instrumentations (for example the OpenAI one) are suppressed inside a client model's generate, since the chat span already carries that call.

Options

| Option | Default | Effect | |---|---|---| | captureContent | true | false keeps span structure, timings, models, operation names and token counts but drops instructions, prompts, completions, results, page URLs, typed text and exception messages (only the exception type is kept). RESPAN_TRACE_CONTENT=false or TRACELOOP_TRACE_CONTENT=false do the same. | | captureScreenshots | true | false skips the screenshot after each act and replaces images in prompts with a size placeholder. | | clientModelName | none | The model a client model's generate calls, reported on its chat spans. | | stagehandModule | imported | The @browserbasehq/stagehand module to patch, when your app loads a different copy than this package would import. |

Not yet covered

  • Session replay (a browser recording synced to the timeline). See docs/GAPS.md.
  • Stagehand v3 and the Browserbase-hosted API mode.
  • experimentalBatch() callbacks run inside the extension and are not traced beyond their own operations.