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

@reaatech/agent-budget-otel-bridge

v0.1.0

Published

OpenTelemetry cost exporter bridge for agent-budget-controller

Readme

@reaatech/agent-budget-otel-bridge

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

OpenTelemetry span-to-spend bridge that converts GenAI spans into budget-tracked spend entries in real time. Drop it into any OTel-instrumented agent and every LLM call is automatically recorded against your budgets — no manual record() calls needed.

Installation

npm install @reaatech/agent-budget-otel-bridge
# or
pnpm add @reaatech/agent-budget-otel-bridge

Feature Overview

  • Automatic spend recording — every GenAI span becomes a SpendEntry pushed to the BudgetController
  • OTel GenAI attribute extraction — reads gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.request.model, gen_ai.system, llm.cost.total_usd
  • Custom scope extraction — supply your own scopeExtractor to map spans to budget scopes
  • Default scope extractor — reads budget.scope_type and budget.scope_key from span attributes
  • Non-blocking — span processing is fire-and-forget; the bridge never adds latency to your agent
  • Optional peer dependency@opentelemetry/api is optional; the bridge works with any OTel-compatible span data

Quick Start

import { SpanListener } from '@reaatech/agent-budget-otel-bridge';
import { BudgetController } from '@reaatech/agent-budget-engine';
import { SpendStore } from '@reaatech/agent-budget-spend-tracker';
import { BudgetScope } from '@reaatech/agent-budget-types';

const store = new SpendStore();
const controller = new BudgetController({ spendTracker: store });

const listener = new SpanListener({ controller });

// When an OTel span ends, feed it to the listener
function onSpanEnd(span: ReadableSpan) {
  listener.onSpanEnd(span.attributes);
}

With an OTel Span Processor

import { SpanListener } from '@reaatech/agent-budget-otel-bridge';
import { NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';

const listener = new SpanListener({ controller });
const provider = new NodeTracerProvider();

provider.addSpanProcessor({
  onEnd(span) {
    listener.onSpanEnd(span.attributes);
  },
  forceFlush: () => Promise.resolve(),
  shutdown: () => Promise.resolve(),
});

API Reference

SpanListener

| Method | Description | | ----------------------------------- | ---------------------------------------------------------------------------------------------- | | onSpanEnd(attributes, overrides?) | Process span attributes and record a spend entry. Returns true if a spend entry was created. |

Constructor

new SpanListener(options: {
  controller: BudgetController;
  scopeExtractor?: (attributes: Record<string, unknown>) => {
    scopeType: BudgetScope;
    scopeKey: string;
  } | null;
})

The default scopeExtractor reads these span attributes:

| Attribute | Description | | ------------------- | ------------------------------------------- | | budget.scope_type | "task", "user", "session", or "org" | | budget.scope_key | The scope identifier (e.g., "user-42") |

The listener extracts these standard GenAI OTel attributes:

| Attribute | Used For | | ---------------------------- | --------------------- | | gen_ai.usage.input_tokens | Token count | | gen_ai.usage.output_tokens | Token count | | gen_ai.request.model | Model ID | | gen_ai.system | Provider name mapping | | llm.cost.total_usd | Recorded cost |

Usage Patterns

Span Attribute Overrides

listener.onSpanEnd(span.attributes, {
  cost: 0.15,
  modelId: 'claude-sonnet-4',
});

Integration with OpenTelemetry SDK

import { SpanListener } from '@reaatech/agent-budget-otel-bridge';
import { BudgetController } from '@reaatech/agent-budget-engine';
import { SpendStore } from '@reaatech/agent-budget-spend-tracker';
import { NodeTracerProvider, BatchSpanProcessor } from '@opentelemetry/sdk-trace-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

const store = new SpendStore();
const controller = new BudgetController({ spendTracker: store });
const listener = new SpanListener({ controller });

await controller.defineBudget({
  scopeType: BudgetScope.User,
  scopeKey: 'user-42',
  limit: 10.0,
  policy: { softCap: 0.8, hardCap: 1.0 },
});

const provider = new NodeTracerProvider();
provider.addSpanProcessor(new BatchSpanProcessor(new OTLPTraceExporter()));
provider.addSpanProcessor({
  onEnd: (span) => listener.onSpanEnd(span.attributes),
  forceFlush: () => Promise.resolve(),
  shutdown: () => Promise.resolve(),
});
provider.register();

Creating a Custom Scope Extractor

const listener = new SpanListener({
  controller,
  scopeExtractor: (attributes) => {
    const userId = attributes['myapp.user_id'] as string;
    const orgId = attributes['myapp.org_id'] as string;

    if (userId) {
      return { scopeType: BudgetScope.User, scopeKey: userId };
    }
    if (orgId) {
      return { scopeType: BudgetScope.Org, scopeKey: orgId };
    }
    return null;
  },
});

Related Packages

License

MIT