SuperPenguin Docs
SDKsTypeScript

OpenTelemetry

Submit existing OpenTelemetry spans to SuperPenguin for cost attribution.

This page describes the in-process SDK OTel helper: application code calls submitSpan(), which converts one span into a SuperPenguin SDK event.

import { submitSpan } from "@superpenguin/js";

await submitSpan(span, {
  metadata: {
    environment: "production",
    feature: "support_agent",
  },
});

Vercel AI SDK telemetry fields (functionId) and OpenTelemetry trace IDs are stored under custom_tags unless they map to a first-class attribution column.

With content capture on, a sampled span that carries the prompt and response (ai.prompt* / ai.response.* or gen_ai.* attributes) is captured whole. The sample's session_id / turn_id come from metadata, else from the span attributes sp.session_id / sp.turn_id or ai.telemetry.metadata.session_id / .turn_id (set through the Vercel AI SDK's experimental_telemetry.metadata). Span export often runs outside your request's withMetadata scope, so put the ids on the span. In serverless code, await flushContentCapture() before returning.

For a provider or standard exporter that should POST OTLP/HTTP JSON directly, use the separate hosted OpenTelemetry endpoint. Do not send an OTLP envelope to /api/sdk/ingest, and do not call both paths for the same generation unless they share a provider response ID.

Python correlation

Install the optional extra and keep an active OTel span around wrapped calls:

pip install "superpenguin[otel]"

When a span is active, the Python SDK stores trace_id, span_id, traceparent, and otel_scope under custom_tags. @sp.trace also stores superpenguin_trace_id for correlation.

Configuration reference (TypeScript)

init()

ParameterDefaultDescription
apiKeySP_API_KEYSuperPenguin key
baseUrlhttps://app.superpenguin.aiAPI endpoint
flushMode"immediate"Use "interval" for long-lived workers
batchSize50Max events per POST
flushIntervalMs5000Interval flush cadence
maxRetries2Transient failure retries
throwOnErrorfalsePropagate ingest errors
keepalivetruefetch keepalive for serverless

Call await flush() before shutting down interval-mode workers.