@superbased/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +438 -2
- package/dist/cjs/admit.d.ts +139 -0
- package/dist/cjs/admit.js +442 -0
- package/dist/cjs/admit.js.map +1 -0
- package/dist/cjs/attrs.d.ts +113 -0
- package/dist/cjs/attrs.js +183 -0
- package/dist/cjs/attrs.js.map +1 -0
- package/dist/cjs/config.d.ts +202 -0
- package/dist/cjs/config.js +386 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/context.d.ts +102 -0
- package/dist/cjs/context.js +234 -0
- package/dist/cjs/context.js.map +1 -0
- package/dist/cjs/control.d.ts +99 -0
- package/dist/cjs/control.js +243 -0
- package/dist/cjs/control.js.map +1 -0
- package/dist/cjs/cost.d.ts +108 -0
- package/dist/cjs/cost.js +211 -0
- package/dist/cjs/cost.js.map +1 -0
- package/dist/cjs/destination.d.ts +125 -0
- package/dist/cjs/destination.js +357 -0
- package/dist/cjs/destination.js.map +1 -0
- package/dist/cjs/experiments.d.ts +237 -0
- package/dist/cjs/experiments.js +678 -0
- package/dist/cjs/experiments.js.map +1 -0
- package/dist/cjs/export.d.ts +84 -0
- package/dist/cjs/export.js +328 -0
- package/dist/cjs/export.js.map +1 -0
- package/dist/cjs/index.d.ts +168 -0
- package/dist/cjs/index.js +581 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/instrument.d.ts +88 -0
- package/dist/cjs/instrument.js +397 -0
- package/dist/cjs/instrument.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/policy.d.ts +77 -0
- package/dist/cjs/policy.js +252 -0
- package/dist/cjs/policy.js.map +1 -0
- package/dist/cjs/prompts.d.ts +175 -0
- package/dist/cjs/prompts.js +476 -0
- package/dist/cjs/prompts.js.map +1 -0
- package/dist/cjs/propagation.d.ts +34 -0
- package/dist/cjs/propagation.js +151 -0
- package/dist/cjs/propagation.js.map +1 -0
- package/dist/cjs/req.d.ts +10 -0
- package/dist/cjs/req.js +3 -0
- package/dist/cjs/req.js.map +1 -0
- package/dist/cjs/runtime.d.ts +44 -0
- package/dist/cjs/runtime.js +67 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/scores.d.ts +102 -0
- package/dist/cjs/scores.js +226 -0
- package/dist/cjs/scores.js.map +1 -0
- package/dist/cjs/spans.d.ts +193 -0
- package/dist/cjs/spans.js +398 -0
- package/dist/cjs/spans.js.map +1 -0
- package/dist/cjs/vendor.d.ts +33 -0
- package/dist/cjs/vendor.js +67 -0
- package/dist/cjs/vendor.js.map +1 -0
- package/dist/esm/admit.d.ts +139 -0
- package/dist/esm/admit.js +432 -0
- package/dist/esm/admit.js.map +1 -0
- package/dist/esm/attrs.d.ts +113 -0
- package/dist/esm/attrs.js +179 -0
- package/dist/esm/attrs.js.map +1 -0
- package/dist/esm/config.d.ts +202 -0
- package/dist/esm/config.js +364 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/context.d.ts +102 -0
- package/dist/esm/context.js +221 -0
- package/dist/esm/context.js.map +1 -0
- package/dist/esm/control.d.ts +99 -0
- package/dist/esm/control.js +230 -0
- package/dist/esm/control.js.map +1 -0
- package/dist/esm/cost.d.ts +108 -0
- package/dist/esm/cost.js +202 -0
- package/dist/esm/cost.js.map +1 -0
- package/dist/esm/destination.d.ts +125 -0
- package/dist/esm/destination.js +346 -0
- package/dist/esm/destination.js.map +1 -0
- package/dist/esm/experiments.d.ts +237 -0
- package/dist/esm/experiments.js +666 -0
- package/dist/esm/experiments.js.map +1 -0
- package/dist/esm/export.d.ts +84 -0
- package/dist/esm/export.js +314 -0
- package/dist/esm/export.js.map +1 -0
- package/dist/esm/index.d.ts +168 -0
- package/dist/esm/index.js +500 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/instrument.d.ts +88 -0
- package/dist/esm/instrument.js +391 -0
- package/dist/esm/instrument.js.map +1 -0
- package/dist/esm/policy.d.ts +77 -0
- package/dist/esm/policy.js +240 -0
- package/dist/esm/policy.js.map +1 -0
- package/dist/esm/prompts.d.ts +175 -0
- package/dist/esm/prompts.js +460 -0
- package/dist/esm/prompts.js.map +1 -0
- package/dist/esm/propagation.d.ts +34 -0
- package/dist/esm/propagation.js +145 -0
- package/dist/esm/propagation.js.map +1 -0
- package/dist/esm/req.d.ts +10 -0
- package/dist/esm/req.js +2 -0
- package/dist/esm/req.js.map +1 -0
- package/dist/esm/runtime.d.ts +44 -0
- package/dist/esm/runtime.js +59 -0
- package/dist/esm/runtime.js.map +1 -0
- package/dist/esm/scores.d.ts +102 -0
- package/dist/esm/scores.js +219 -0
- package/dist/esm/scores.js.map +1 -0
- package/dist/esm/spans.d.ts +193 -0
- package/dist/esm/spans.js +378 -0
- package/dist/esm/spans.js.map +1 -0
- package/dist/esm/vendor.d.ts +33 -0
- package/dist/esm/vendor.js +61 -0
- package/dist/esm/vendor.js.map +1 -0
- package/package.json +130 -4
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* superbased SDK for TypeScript / Node: send LLM-app and agent traces to
|
|
3
|
+
* superbased over OpenTelemetry (OTLP/HTTP).
|
|
4
|
+
*
|
|
5
|
+
* A thin layer over OpenTelemetry JS 2.x that exports spans to the Observer
|
|
6
|
+
* on this machine (`http://127.0.0.1:4318/v1/traces` by default), to an org
|
|
7
|
+
* or SaaS OTLP gateway, or to both, and tags them with superbased attributes.
|
|
8
|
+
* Anything it does, a raw OTel exporter pointed at Observer does too.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: never set `sbo.emitted_by=observer`: that is Observer's own
|
|
11
|
+
* echo-guard marker and such a resource is DROPPED at ingestion.
|
|
12
|
+
*/
|
|
13
|
+
import { type TracerProvider } from "@opentelemetry/api";
|
|
14
|
+
import { type SpanExporter, type SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
15
|
+
import { type DestinationChoice, type Settings, type SettingsInput } from "./config.js";
|
|
16
|
+
import { type MaskFn, type ShouldExportFn } from "./policy.js";
|
|
17
|
+
import { type VendorTracing } from "./vendor.js";
|
|
18
|
+
export { VERSION } from "./runtime.js";
|
|
19
|
+
export { admit, Degraded, DEFAULT_ADMISSION_ENDPOINT, DEFAULT_ADMIT_TIMEOUT_MS, SDK_ADMIT_PATH, parseVerdict, type AdmitOptions, type Verdict, } from "./admit.js";
|
|
20
|
+
export { DEFAULT_DISCOVER_TIMEOUT_MS, DEFAULT_ENDPOINT, DEFAULT_EXPORT_TIMEOUT_MS, DEFAULT_MAX_CONTENT_CHARS, DEFAULT_API_TIMEOUT_MS, DEFAULT_NODE_URL, DEFAULT_PROMPT_CACHE_TTL_MS, DEFAULT_SERVICE_NAME, DEFAULT_SHUTDOWN_TIMEOUT_MS, DESTINATION_CHOICES, destinations, parseKvList, resolveSettings, type Destination, type DestinationChoice, type Settings, type SettingsInput, } from "./config.js";
|
|
21
|
+
export { K as Attr, LIMITS, REQUEST_PARAMS, SEMCONV_COMMIT, SEMCONV_SCHEMA_URL } from "./attrs.js";
|
|
22
|
+
export { getCurrentAttributes, identify, propagateAttributes, type AttributeScope, type PropagateOptions, type TraceAttributes, } from "./context.js";
|
|
23
|
+
export { DISCOVERY_PATH, isLoopbackUrl, parseDiscovery, readCredentialFile, type Discovered } from "./destination.js";
|
|
24
|
+
export { keepTrace, TRUNCATED_MARK, type MaskFn, type ShouldExportFn } from "./policy.js";
|
|
25
|
+
export { continueTrace, extract, getTraceparent, inject, type Carrier } from "./propagation.js";
|
|
26
|
+
export { Kind, getCurrentSpanId, getCurrentTraceId, observe, setContent, setDocuments, setInput, setOutput, setRequestParams, setToolResult, setUsage, withAgentSpan, withEmbeddingSpan, withLlmSpan, withRetrieverSpan, withSpan, withToolSpan, type AgentInfo, type Content, type Document, type EmbeddingInfo, type LlmInfo, type ObserveOptions, type PromptRef, type RequestParams, type RetrieverInfo, type SpanOptions, type SpanKind, type ToolInfo, type Usage, } from "./spans.js";
|
|
27
|
+
export * from "./scores.js";
|
|
28
|
+
export * from "./cost.js";
|
|
29
|
+
export * from "./prompts.js";
|
|
30
|
+
export * from "./experiments.js";
|
|
31
|
+
export * from "./instrument.js";
|
|
32
|
+
export interface InitOptions extends SettingsInput {
|
|
33
|
+
/** Also print spans to stdout (debugging). Env: SUPERBASED_CONSOLE. */
|
|
34
|
+
console?: boolean;
|
|
35
|
+
/** A SpanExporter to use instead of OTLP/HTTP (tests, custom transport). Replaces every destination. */
|
|
36
|
+
exporter?: SpanExporter;
|
|
37
|
+
/**
|
|
38
|
+
* A tracer provider to hold the SDK's spans instead of the global one. An
|
|
39
|
+
* OTel JS 1.x provider gets the SDK's processor added; a 2.x provider must
|
|
40
|
+
* have been built with `spanProcessors: [spanProcessor()]`.
|
|
41
|
+
*/
|
|
42
|
+
tracerProvider?: TracerProvider;
|
|
43
|
+
/** Rewrite each content value before export (fail-safe: a throw withholds the value). Code only. */
|
|
44
|
+
mask?: MaskFn;
|
|
45
|
+
/** Return false to drop a finished span. Code only. */
|
|
46
|
+
shouldExport?: ShouldExportFn;
|
|
47
|
+
}
|
|
48
|
+
/** How the SDK holds spans: its own registered provider, the host's provider, or a private one. */
|
|
49
|
+
export type Mode = "" | "owned" | "attached" | "standalone";
|
|
50
|
+
/**
|
|
51
|
+
* The SDK's span processor, for an app on OpenTelemetry JS 2.x that builds its
|
|
52
|
+
* own provider (2.x providers take processors only at construction):
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const provider = new NodeTracerProvider({ spanProcessors: [spanProcessor(), ...yours] });
|
|
56
|
+
* provider.register();
|
|
57
|
+
* init({ serviceName: "my-app" }); // exports through that provider
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function spanProcessor(): SpanProcessor;
|
|
61
|
+
/**
|
|
62
|
+
* Configure tracing to export to superbased over OTLP/HTTP. Idempotent.
|
|
63
|
+
*
|
|
64
|
+
* Every option maps to an env var (`SUPERBASED_*`, then the standard `OTEL_*`
|
|
65
|
+
* one where it exists); an explicit option wins. See the README's settings
|
|
66
|
+
* table.
|
|
67
|
+
*
|
|
68
|
+
* Destination (D18): `local` (this machine), `online` (the org or SaaS
|
|
69
|
+
* gateway) or `both`, from the option, `SUPERBASED_DESTINATION`, the local
|
|
70
|
+
* Observer's default, then a fallback. See {@link ready}.
|
|
71
|
+
*
|
|
72
|
+
* - No provider registered yet: the SDK registers its own (mode `owned`).
|
|
73
|
+
* - An OTel JS 1.x SDK provider is registered: the SDK adds its processor to
|
|
74
|
+
* it (mode `attached`).
|
|
75
|
+
* - An OTel JS 2.x provider built with `spanProcessors: [spanProcessor()]`:
|
|
76
|
+
* the SDK exports through it (mode `attached`).
|
|
77
|
+
* - Any other provider is registered: the SDK keeps a private provider for
|
|
78
|
+
* its own spans (mode `standalone`); they still join the active trace.
|
|
79
|
+
*
|
|
80
|
+
* A second call with the same settings is a no-op; with different settings it
|
|
81
|
+
* replaces the SDK's exporters in place, shutting the previous ones down.
|
|
82
|
+
*/
|
|
83
|
+
export declare function init(opts?: InitOptions): Settings;
|
|
84
|
+
/**
|
|
85
|
+
* Resolves once the destination is known (immediately unless init is asking
|
|
86
|
+
* the local Observer for its default, which takes at most
|
|
87
|
+
* `discoverTimeoutMs`). Spans finished before then are held, not lost.
|
|
88
|
+
*/
|
|
89
|
+
export declare function ready(): Promise<DestinationChoice | "">;
|
|
90
|
+
/**
|
|
91
|
+
* The settings the last `init()` resolved (null before init). `apiKey` and the
|
|
92
|
+
* header maps are readable but not enumerable, so logging the object never
|
|
93
|
+
* prints the credential.
|
|
94
|
+
*/
|
|
95
|
+
export declare function settings(): Settings | null;
|
|
96
|
+
/**
|
|
97
|
+
* Export every finished span now. Bounded by `timeoutMs` (default: the
|
|
98
|
+
* shutdownTimeoutMs setting). Resolves true when everything went out in time;
|
|
99
|
+
* never rejects. Await it at the end of a serverless handler.
|
|
100
|
+
*/
|
|
101
|
+
export declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Flush and stop the SDK's exporters. Bounded by `timeoutMs` even when an
|
|
104
|
+
* endpoint is down; never rejects (ECONNREFUSED, 302 and 401 included). The
|
|
105
|
+
* host's provider, when the SDK attached to one, keeps running. A later
|
|
106
|
+
* `init()` starts exporting again.
|
|
107
|
+
*/
|
|
108
|
+
export declare function shutdown(timeoutMs?: number): Promise<boolean>;
|
|
109
|
+
export interface Diagnostics {
|
|
110
|
+
mode: Mode;
|
|
111
|
+
initialized: boolean;
|
|
112
|
+
/** local, online or both, or "" while discovering (or before init). */
|
|
113
|
+
destination: DestinationChoice | "";
|
|
114
|
+
/** Where it came from: argument, env, machine, inferred, default, exporter, or discovering. */
|
|
115
|
+
destinationSource: string;
|
|
116
|
+
/** The exporters running now. */
|
|
117
|
+
destinations: Array<{
|
|
118
|
+
name: string;
|
|
119
|
+
endpoint: string;
|
|
120
|
+
}>;
|
|
121
|
+
/** Why the destination could not be honoured in full (also logged once as warnings). */
|
|
122
|
+
destinationProblems: string[];
|
|
123
|
+
/** The gateway's base URL in force ("" when none). */
|
|
124
|
+
gatewayUrl: string;
|
|
125
|
+
/** The degraded reason ("" when the destination is honoured in full; contract destination.md section 7). */
|
|
126
|
+
degraded: string;
|
|
127
|
+
/** Informational lines, for example why discovery got no answer. */
|
|
128
|
+
notes: string[];
|
|
129
|
+
/** What the machine reported about sign-in; null when no machine answered. */
|
|
130
|
+
signedIn: boolean | null;
|
|
131
|
+
/** Where the credential came from: argument, env, file, or "" (never the credential itself). */
|
|
132
|
+
credentialSource: string;
|
|
133
|
+
pendingSpans: number;
|
|
134
|
+
exportedSpans: number;
|
|
135
|
+
failedExports: number;
|
|
136
|
+
droppedSpans: number;
|
|
137
|
+
/** Spans left out by head sampling (sampleRate). */
|
|
138
|
+
sampledOutSpans: number;
|
|
139
|
+
/** Spans dropped by shouldExport. */
|
|
140
|
+
filteredSpans: number;
|
|
141
|
+
/** shouldExport hooks that threw (the span was kept). */
|
|
142
|
+
shouldExportErrors: number;
|
|
143
|
+
/** mask hooks that threw (that value was dropped). */
|
|
144
|
+
maskErrors: number;
|
|
145
|
+
lastHookError: string;
|
|
146
|
+
lastError: string;
|
|
147
|
+
/** Epoch ms of the last error, 0 when none. */
|
|
148
|
+
lastErrorAt: number;
|
|
149
|
+
/** Control API calls (scores, prompts, datasets, experiments) made and failed. */
|
|
150
|
+
controlCalls: number;
|
|
151
|
+
controlFailures: number;
|
|
152
|
+
controlLastError: string;
|
|
153
|
+
/** admit() calls that got no decision (admitted, or denied under failClosed), and why the last one (review E-39). */
|
|
154
|
+
admissionDegraded: number;
|
|
155
|
+
admissionLastError: string;
|
|
156
|
+
/** Epoch ms of that last one, 0 when none. */
|
|
157
|
+
admissionLastErrorAt: number;
|
|
158
|
+
/** Per model client library that traces itself (`anthropic`): `off` (init() turned its own spans off; `instrument([...])` records the calls) or `kept` (the app set its switch, e.g. `ANTHROPIC_OPEN_TELEMETRY=true`). */
|
|
159
|
+
vendorTracing: Record<string, VendorTracing>;
|
|
160
|
+
/** Spans from such a library dropped at export (a client built before init()). */
|
|
161
|
+
vendorSpansDropped: number;
|
|
162
|
+
/** setUsage calls whose inputTokens was below its cache parts, recorded as a net count (input + cache). */
|
|
163
|
+
usageNetInputCorrected: number;
|
|
164
|
+
}
|
|
165
|
+
/** A snapshot of the SDK's export health. */
|
|
166
|
+
export declare function diagnostics(): Diagnostics;
|
|
167
|
+
/** Forget all SDK state (tests only). Does not touch the global provider. */
|
|
168
|
+
export declare function _resetForTests(): Promise<void>;
|