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-braintrust

v0.2.0

Published

Respan instrumentation plugin for Braintrust TypeScript tracing

Readme

@respan/instrumentation-braintrust

Translate real Braintrust TypeScript logger and span activity into the active Respan OpenTelemetry pipeline. Supports Braintrust 3.9.0 and later; validated with 3.9.0 and 3.37.2 on Node.js 24.

import { Respan } from "@respan/respan";
import { BraintrustInstrumentor } from "@respan/instrumentation-braintrust";
import { initLogger } from "braintrust";

const instrumentor = new BraintrustInstrumentor();
const respan = new Respan({ instrumentations: [instrumentor] });
await respan.initialize();

const logger = initLogger({
  projectName: "my-project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
await logger.traced(
  async (span) => {
    span.log({ input: { city: "Kyoto" } });
    const result = { city: "Kyoto", temperature: 21 };
    span.log({ output: result });
    return result;
  },
  { name: "lookup-weather", type: "tool" },
);

await logger.flush();
await instrumentor.flush();
await respan.flush();
await instrumentor.deactivate();
await respan.shutdown();

The bridge replaces the global Braintrust background logger while active, so native rows are sent through Respan instead of the Braintrust log destination. Braintrust can still contact its configured service for login and project metadata. Configure Braintrust normally for an application; the mapped examples use a loopback service and fixture keys, with no hosted Braintrust requests.

logger.log, logger.startSpan, logger.traced, child spans, span.log, span.setAttributes, span.end, and Braintrust provider wrappers retain their native return values, errors, promises, stream objects and controllers. Updates merge across flushes. A span is exported only when native metrics include its end time. Flush does not invent completion for an unfinished native span.

The real OTel sampler runs before the bridge captures payloads. traceContent: false, either RESPAN_TRACE_CONTENT=false or TRACELOOP_TRACE_CONTENT=false, Traceloop context denial, tracing suppression at admission, and observed parent content denial prevent payload capture. Denial stays in effect for that span. DROP and RECORD_ONLY skip bridge-owned lazy row resolution. Native Braintrust may still copy application data as part of its own unmodified logging behavior. Late attributes, events and status text on the actual recording span are guarded.

const instrumentor = new BraintrustInstrumentor({ traceContent: false });
console.log(instrumentor.isActive()); // method, available after activation

Canonical JSON preserves full native inputs, outputs, multimodal message parts, tool definitions and tool-call IDs, vectors, zero/false/empty/null values, metadata, scores, tags and explicit usage. Native IDs remain in respan.metadata for correlation; OTel generates its own IDs and retains native parent links. Provider/model names and total tokens are never inferred. Workflow, agent and task spans carry common fields; tool execution input uses {name, arguments}. Optional indexed message attributes follow complete canonical fields so default OTel attribute limits do not remove full input, output, tools or usage.

Braintrust's OpenAI wrapper currently logs embedding length rather than vector values. The bridge preserves that native output; full vectors are captured when supplied through the native span API. Wrapper model metadata may arrive after native span construction and therefore after sampling. Initial native metadata is available to the sampler when supplied in startSpan/traced arguments. Feedback and remote update rows without a local native span lifecycle do not create new spans. Multiple instrumentor owners share one bridge, final deactivation drains in-flight spans, and foreign logger/prototype overrides are preserved.

includeBraintrustRawMetadata: true additionally retains the original native span_attributes inside canonical metadata. The existing exportRecord and exportRecords APIs remain available for explicit imported rows; normal native applications should use Braintrust's logger/span APIs.

Braintrust's official @braintrust/otel integration sends OTel spans to Braintrust and shares context. This package handles the opposite producer path: native Braintrust spans into Respan.