Breadcrumb
SDKsTypeScript SDK

Tracing

Traces

A trace wraps a top-level operation. Call bc.trace() with a name and an async function:

await bc.trace("my-workflow", async (root) => {
  root.set({ input: "user question" });

  const result = await doWork();

  root.set({ output: result });
});

Spans

Spans represent individual steps inside a trace. Nest them to build a call tree:

await bc.trace("my-workflow", async (root) => {
  const result = await bc.span(
    "generate",
    async (span) => {
      const text = await callModel(prompt);

      span.set({
        input: prompt,
        output: text,
        model: "claude-sonnet-4-5",
        provider: "anthropic",
      });

      return text;
    },
    { type: "llm" }
  );

  root.set({ output: result });
});

Span data

Set metadata on a span with span.set():

FieldTypeDescription
inputstringInput text or prompt
outputstringOutput text or completion
modelstringModel name
providerstringProvider name
inputTokensnumberInput token count
outputTokensnumberOutput token count
costnumberCost in dollars
metadataRecord<string, unknown>Custom key-value data

Span types

Pass a type in the options to categorize spans:

bc.span("step", fn, { type: "llm" });
bc.span("step", fn, { type: "tool" });
bc.span("step", fn, { type: "retrieval" });
bc.span("step", fn, { type: "default" });

On this page