@profitstone/pstone
v0.1.2
Published
Profit Stone Telemetry SDK for Node.js / TypeScript — OpenTelemetry instrumentation for AI apps
Maintainers
Readme
@profitstone/pstone
Profit Stone in-process Telemetry SDK for Node.js and TypeScript.
OpenTelemetry-based collection of LLM calls, sent to the Profit Stone SaaS Ingest API (same contract as the Python pstone package).
npm install @profitstone/pstone
# optional peers for auto-instrumentation:
npm install openai @anthropic-ai/sdkimport { pstone } from "@profitstone/pstone";
import OpenAI from "openai";
pstone.init(process.env.PSTONE_API_KEY!);
const client = new OpenAI();
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
});
await pstone.flushAsync();
await pstone.shutdownAsync();0.2.0 —
init/ OTLP protobuf export / OpenAI & Anthropic instrumentation (parity with Python MVP).
Requirements
- Node.js 18+
Environment
| Variable | Required | Description |
|----------|----------|-------------|
| PSTONE_API_KEY | recommended | Workspace API Key if omitted from init |
| PSTONE_INGEST_URL | optional | Ingest base URL (default https://api.profitstone.ai) |
| PSTONE_SERVICE_NAME | optional | OTel service.name (default pstone-app) |
Traces are sent to {PSTONE_INGEST_URL}/v1/ingest/traces with Authorization: Bearer <key> (OTLP/HTTP protobuf).
API
| Method | Purpose |
|--------|---------|
| pstone.init(apiKey?, options?) | Start tracer + optional auto-instrument |
| pstone.flush() / flushAsync() | Force export of pending spans |
| pstone.shutdown() / shutdownAsync() | Uninstrument + shut down provider |
| pstone.wrapOpenai(client) | Wrap one OpenAI client instance |
| pstone.wrapAnthropic(client) | Wrap one Anthropic client instance |
init options
| Option | Default | Description |
|--------|---------|-------------|
| ingestUrl | env / SaaS default | Ingest base URL |
| serviceName | pstone-app | Resource service.name |
| captureContent | true | Include prompts/completions |
| redact | true | Basic email/phone redaction |
| instrument | true | Auto-patch OpenAI / Anthropic if installed |
| instrumentOpenai | true | Patch OpenAI |
| instrumentAnthropic | true | Patch Anthropic |
| useBatch | true | BatchSpanProcessor (false for tests) |
| exporter | OTLP protobuf | Inject custom exporter (tests) |
Instrumentation
With instrument: true (default), when packages are installed:
- OpenAI —
chat.completions.create(+parse/responses.createwhen present), includingstream: true - Anthropic —
messages.create, includingstream: true
Or wrap a single client: pstone.wrapOpenai(client).
Local smoke (optional)
export PSTONE_API_KEY=psk_...
export PSTONE_INGEST_URL=http://localhost:8000
node -e "
import { pstone } from '@profitstone/pstone';
import { startLlmSpan, recordLlmResponse } from '@profitstone/pstone';
pstone.init(undefined, { useBatch: false, instrument: false });
const s = startLlmSpan({ system: 'openai', model: 'smoke', prompt: 'hi' });
recordLlmResponse(s.span, { completion: 'ok', inputTokens: 1, outputTokens: 1 });
s.end();
await pstone.flushAsync();
await pstone.shutdownAsync();
console.log('flushed');
"License
MIT
