@uselemma/tracing 3.0.3 → 4.0.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/README.md +189 -45
- package/dist/client.d.ts +237 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +660 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -17
- package/dist/index.js.map +1 -1
- package/dist/vercel-ai.d.ts +117 -0
- package/dist/vercel-ai.d.ts.map +1 -0
- package/dist/vercel-ai.js +230 -0
- package/dist/vercel-ai.js.map +1 -0
- package/examples/callback-tracing.ts +55 -0
- package/examples/record-by-id.ts +47 -0
- package/examples/trace-handles.ts +59 -0
- package/examples/vercel-ai-v6.ts +27 -0
- package/examples/vercel-ai-v7.ts +27 -0
- package/package.json +5 -13
- package/dist/register.d.ts +0 -61
- package/dist/register.d.ts.map +0 -1
- package/dist/register.js +0 -76
- package/dist/register.js.map +0 -1
- package/dist/run-batch-span-processor.d.ts +0 -25
- package/dist/run-batch-span-processor.d.ts.map +0 -1
- package/dist/run-batch-span-processor.js +0 -139
- package/dist/run-batch-span-processor.js.map +0 -1
- package/dist/span-helpers.d.ts +0 -55
- package/dist/span-helpers.d.ts.map +0 -1
- package/dist/span-helpers.js +0 -103
- package/dist/span-helpers.js.map +0 -1
- package/dist/trace-wrapper.d.ts +0 -107
- package/dist/trace-wrapper.d.ts.map +0 -1
- package/dist/trace-wrapper.js +0 -133
- package/dist/trace-wrapper.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @uselemma/tracing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
HTTP tracing SDK for AI agents. No OpenTelemetry setup is required: the SDK sends completed trace payloads directly to the Lemma API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,80 +10,224 @@ npm install @uselemma/tracing
|
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```typescript
|
|
14
|
+
import { Lemma } from "@uselemma/tracing";
|
|
15
|
+
|
|
16
|
+
const lemma = new Lemma({
|
|
17
|
+
apiKey: process.env.LEMMA_API_KEY,
|
|
18
|
+
projectId: process.env.LEMMA_PROJECT_ID,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const answer = await lemma.trace(
|
|
22
|
+
{
|
|
23
|
+
name: "support-agent",
|
|
24
|
+
input: userMessage,
|
|
25
|
+
threadId: conversationId,
|
|
26
|
+
userId: user.id,
|
|
27
|
+
},
|
|
28
|
+
async (trace) => {
|
|
29
|
+
const docs = await searchDocs(userMessage);
|
|
30
|
+
trace.recordTool({
|
|
31
|
+
name: "search_docs",
|
|
32
|
+
input: { query: userMessage },
|
|
33
|
+
output: docs,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const response = await callModel(userMessage, docs);
|
|
37
|
+
trace.recordGeneration({
|
|
38
|
+
name: "draft-reply",
|
|
39
|
+
input: response.messages,
|
|
40
|
+
output: response.text,
|
|
41
|
+
model: "gpt-4o",
|
|
42
|
+
usage: {
|
|
43
|
+
inputTokens: response.usage.inputTokens,
|
|
44
|
+
outputTokens: response.usage.outputTokens,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return response.text;
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`trace()` creates one Lemma trace. The callback receives a context object; any child span, generation, or tool recorded through that context is attached to the trace.
|
|
14
54
|
|
|
15
|
-
|
|
55
|
+
## One-Off Events
|
|
56
|
+
|
|
57
|
+
Use one-off calls when the work already happened and you want to record it:
|
|
16
58
|
|
|
17
59
|
```typescript
|
|
18
|
-
|
|
60
|
+
trace.recordSpan({
|
|
61
|
+
name: "rerank-results",
|
|
62
|
+
input: { candidates: candidates.length },
|
|
63
|
+
output: { kept: ranked.length },
|
|
64
|
+
});
|
|
19
65
|
|
|
20
|
-
|
|
66
|
+
trace.recordTool({
|
|
67
|
+
name: "lookup_order",
|
|
68
|
+
input: { orderId },
|
|
69
|
+
output: order,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
trace.recordGeneration({
|
|
73
|
+
name: "answer",
|
|
74
|
+
input: messages,
|
|
75
|
+
output: text,
|
|
76
|
+
model: "gpt-4o",
|
|
77
|
+
llmInputMessages: [{ role: "user", content: userMessage }],
|
|
78
|
+
llmInvocationParameters: { temperature: 0.2 },
|
|
79
|
+
});
|
|
21
80
|
```
|
|
22
81
|
|
|
23
|
-
|
|
82
|
+
Pass contract fields as native props such as `llmInputMessages`, `llmInvocationParameters`, `toolParameters`, and `retrievalDocuments`. Use `attributes` only when you need to send raw span attributes that do not yet have a native SDK prop.
|
|
83
|
+
|
|
84
|
+
## Live Spans
|
|
24
85
|
|
|
25
|
-
`
|
|
86
|
+
Use `startSpan()`, `startTool()`, or `startGeneration()` when you want the SDK to measure work from a handle and finish it later:
|
|
26
87
|
|
|
27
88
|
```typescript
|
|
28
|
-
|
|
89
|
+
const span = trace.startSpan({ name: "retrieve-context", input: query });
|
|
90
|
+
try {
|
|
91
|
+
const docs = await retrieve(query);
|
|
92
|
+
span.end({ output: docs, durationMs: 250 });
|
|
93
|
+
} catch (error) {
|
|
94
|
+
span.end({ error });
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
29
98
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
99
|
+
```typescript
|
|
100
|
+
const tool = trace.startTool({ name: "search_docs", input: { query } });
|
|
101
|
+
const docs = await searchDocs(query);
|
|
102
|
+
tool.end({ output: docs, durationMs: 25 });
|
|
103
|
+
|
|
104
|
+
const generation = trace.startGeneration({
|
|
105
|
+
name: "answer",
|
|
106
|
+
input: messages,
|
|
107
|
+
model: "gpt-4o",
|
|
108
|
+
});
|
|
109
|
+
const response = await callModel(messages);
|
|
110
|
+
generation.end({ output: response.text, durationMs: response.durationMs });
|
|
111
|
+
```
|
|
37
112
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
113
|
+
The SDK measures trace durations from timestamps. Pass `durationMs` on callback traces, spans, generations, tools, `span.end({ durationMs })`, or `trace.end({ durationMs })` when you already measured the work yourself. When child spans, generations, or tools omit `durationMs`, Lemma splits the parent's remaining unclaimed duration equally across siblings that also omitted duration.
|
|
114
|
+
|
|
115
|
+
You can also create a trace handle first and record work on it over time:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const trace = lemma.trace({ name: "support-agent", input: userMessage });
|
|
119
|
+
|
|
120
|
+
const span = trace.startSpan("retrieve-context");
|
|
121
|
+
const docs = await retrieve(userMessage);
|
|
122
|
+
span.recordTool({
|
|
123
|
+
name: "search_docs",
|
|
124
|
+
input: { query: userMessage },
|
|
125
|
+
output: docs,
|
|
126
|
+
toolParameters: { query: "string" },
|
|
127
|
+
});
|
|
128
|
+
span.end({
|
|
129
|
+
output: { count: docs.length },
|
|
130
|
+
durationMs: 250,
|
|
131
|
+
retrievalDocuments: docs.map((doc) => ({
|
|
132
|
+
id: doc.id,
|
|
133
|
+
content: doc.text,
|
|
134
|
+
score: doc.score,
|
|
135
|
+
})),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await trace.end({ output: "final answer", durationMs: 1234 });
|
|
42
139
|
```
|
|
43
140
|
|
|
44
|
-
|
|
141
|
+
## Vercel AI SDK
|
|
45
142
|
|
|
46
|
-
|
|
143
|
+
Pass `vercelAI()` to the AI SDK telemetry integrations option while the call runs inside a Lemma trace. AI SDK v7 uses `telemetry`; AI SDK v6 uses `experimental_telemetry`.
|
|
47
144
|
|
|
48
145
|
```typescript
|
|
49
|
-
import {
|
|
146
|
+
import { generateText } from "ai";
|
|
147
|
+
import { Lemma, vercelAI } from "@uselemma/tracing";
|
|
148
|
+
|
|
149
|
+
const lemma = new Lemma();
|
|
150
|
+
|
|
151
|
+
const answer = await lemma.trace(
|
|
152
|
+
{ name: "support-agent", input: userMessage },
|
|
153
|
+
async () => {
|
|
154
|
+
const result = await generateText({
|
|
155
|
+
model,
|
|
156
|
+
prompt: userMessage,
|
|
157
|
+
telemetry: {
|
|
158
|
+
integrations: [vercelAI()],
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return result.text;
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
```
|
|
50
166
|
|
|
51
|
-
|
|
52
|
-
return vectorDB.search(query, { topK: 5 });
|
|
53
|
-
});
|
|
167
|
+
For AI SDK v6, pass the same helper through `experimental_telemetry`:
|
|
54
168
|
|
|
55
|
-
|
|
56
|
-
|
|
169
|
+
```typescript
|
|
170
|
+
await generateText({
|
|
171
|
+
model,
|
|
172
|
+
prompt: userMessage,
|
|
173
|
+
experimental_telemetry: {
|
|
174
|
+
integrations: [vercelAI()],
|
|
175
|
+
},
|
|
57
176
|
});
|
|
177
|
+
```
|
|
58
178
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
179
|
+
The integration records model calls as generations and tool executions as tool calls. Use `vercelAI({ recordInputs: false, recordOutputs: false })` to avoid sending prompts, tool inputs, tool outputs, or model output text.
|
|
180
|
+
|
|
181
|
+
When you pass a trace handle with `vercelAI({ trace })`, the integration ends it from the AI SDK terminal callback: `onEnd` in AI SDK v7 and `onFinish` in AI SDK v6. When you use the callback form of `lemma.trace()`, the callback still owns trace closure.
|
|
182
|
+
|
|
183
|
+
When a helper only has IDs, use the client-level methods:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const trace = lemma.trace();
|
|
187
|
+
|
|
188
|
+
const span = lemma.startSpan({ traceId: trace.id });
|
|
189
|
+
lemma.recordTool({
|
|
190
|
+
traceId: trace.id,
|
|
191
|
+
parentSpanId: span.id,
|
|
192
|
+
name: "tool call",
|
|
63
193
|
});
|
|
194
|
+
|
|
195
|
+
await trace.flush();
|
|
64
196
|
```
|
|
65
197
|
|
|
66
|
-
|
|
198
|
+
Detached handle calls require `traceId`. If a detached observation has a parent, pass `parentSpanId`; calls that cannot attach safely warn and no-op.
|
|
67
199
|
|
|
68
|
-
|
|
69
|
-
- A run batch is exported when its top-level `ai.agent.run` span ends.
|
|
70
|
-
- `forceFlush()` exports remaining runs in separate batches per run.
|
|
71
|
-
- Spans with `instrumentationScope.name === "next.js"` are excluded from export.
|
|
200
|
+
## Active Context
|
|
72
201
|
|
|
73
|
-
|
|
202
|
+
The SDK keeps the active trace in async context, so helpers deeper in your code can record without receiving the context explicitly:
|
|
74
203
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
204
|
+
```typescript
|
|
205
|
+
import { active } from "@uselemma/tracing";
|
|
206
|
+
|
|
207
|
+
export function recordSearch(docs: unknown[]) {
|
|
208
|
+
active().recordTool({
|
|
209
|
+
name: "search_docs",
|
|
210
|
+
output: docs,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Configuration
|
|
79
216
|
|
|
80
|
-
|
|
217
|
+
| Option | Environment variable | Default |
|
|
218
|
+
| ----------- | -------------------- | ------------------------- |
|
|
219
|
+
| `apiKey` | `LEMMA_API_KEY` | Required |
|
|
220
|
+
| `projectId` | `LEMMA_PROJECT_ID` | Required |
|
|
221
|
+
| `baseUrl` | none | `https://api.uselemma.ai` |
|
|
81
222
|
|
|
82
223
|
## Documentation
|
|
83
224
|
|
|
84
|
-
- [Quickstart](https://docs.uselemma.ai/getting-started/quickstart)
|
|
85
|
-
- [
|
|
86
|
-
|
|
225
|
+
- [Quickstart](https://docs.uselemma.ai/getting-started/quickstart)
|
|
226
|
+
- [Trace contract](https://docs.uselemma.ai/reference/trace-contract)
|
|
227
|
+
|
|
228
|
+
## Examples
|
|
229
|
+
|
|
230
|
+
See [`examples/`](./examples) for complete callback tracing, trace handle, record-by-ID, and Vercel AI SDK v6/v7 examples.
|
|
87
231
|
|
|
88
232
|
## License
|
|
89
233
|
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type LemmaClientOptions = {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
};
|
|
10
|
+
export type TraceOptions = {
|
|
11
|
+
id?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
input?: unknown;
|
|
15
|
+
output?: unknown;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
threadId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
environment?: string;
|
|
20
|
+
};
|
|
21
|
+
export type TraceEndOptions = {
|
|
22
|
+
output?: unknown;
|
|
23
|
+
durationMs?: number;
|
|
24
|
+
};
|
|
25
|
+
export type SpanType = "span" | "generation" | "tool";
|
|
26
|
+
export type SpanOptions = {
|
|
27
|
+
id?: string;
|
|
28
|
+
parentId?: string | null;
|
|
29
|
+
parentSpanId?: string | null;
|
|
30
|
+
name: string;
|
|
31
|
+
type?: SpanType;
|
|
32
|
+
input?: unknown;
|
|
33
|
+
output?: unknown;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
attributes?: Record<string, unknown>;
|
|
36
|
+
startedAt?: Date | string;
|
|
37
|
+
endedAt?: Date | string | null;
|
|
38
|
+
durationMs?: number;
|
|
39
|
+
status?: "OK" | "ERROR";
|
|
40
|
+
error?: unknown;
|
|
41
|
+
model?: string;
|
|
42
|
+
usage?: {
|
|
43
|
+
inputTokens?: number;
|
|
44
|
+
outputTokens?: number;
|
|
45
|
+
};
|
|
46
|
+
toolName?: string;
|
|
47
|
+
inputMimeType?: string;
|
|
48
|
+
outputMimeType?: string;
|
|
49
|
+
llmModelName?: string;
|
|
50
|
+
llmProvider?: string;
|
|
51
|
+
llmSystem?: string;
|
|
52
|
+
llmInvocationParameters?: unknown;
|
|
53
|
+
llmInputMessages?: unknown[];
|
|
54
|
+
llmOutputMessages?: unknown[];
|
|
55
|
+
llmTools?: unknown;
|
|
56
|
+
llmTokenCountPrompt?: number;
|
|
57
|
+
llmTokenCountCompletion?: number;
|
|
58
|
+
llmTokenCountTotal?: number;
|
|
59
|
+
llmPromptTemplate?: string;
|
|
60
|
+
llmPromptTemplateVariables?: unknown;
|
|
61
|
+
llmPromptTemplateVersion?: string;
|
|
62
|
+
toolDescription?: string;
|
|
63
|
+
toolParameters?: unknown;
|
|
64
|
+
retrievalDocuments?: unknown[];
|
|
65
|
+
embeddingModelName?: string;
|
|
66
|
+
embeddingInvocationParameters?: unknown;
|
|
67
|
+
embeddingEmbeddings?: unknown;
|
|
68
|
+
rerankerModelName?: string;
|
|
69
|
+
rerankerInputDocuments?: unknown[];
|
|
70
|
+
rerankerOutputDocuments?: unknown[];
|
|
71
|
+
};
|
|
72
|
+
export type GenerationOptions = Omit<SpanOptions, "type" | "toolName">;
|
|
73
|
+
export type ToolOptions = Omit<SpanOptions, "type" | "model" | "usage">;
|
|
74
|
+
export type DetachedSpanOptions = Partial<SpanOptions> & {
|
|
75
|
+
traceId?: string;
|
|
76
|
+
};
|
|
77
|
+
export type DetachedGenerationOptions = Partial<GenerationOptions> & {
|
|
78
|
+
traceId?: string;
|
|
79
|
+
parentSpanId?: string | null;
|
|
80
|
+
};
|
|
81
|
+
export type DetachedToolOptions = Partial<ToolOptions> & {
|
|
82
|
+
traceId?: string;
|
|
83
|
+
parentSpanId?: string | null;
|
|
84
|
+
};
|
|
85
|
+
type SdkTraceSpanPayload = {
|
|
86
|
+
id?: string;
|
|
87
|
+
parent_id?: string | null;
|
|
88
|
+
name: string;
|
|
89
|
+
type: SpanType;
|
|
90
|
+
input?: unknown;
|
|
91
|
+
output?: unknown;
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
attributes?: Record<string, unknown>;
|
|
94
|
+
started_at?: string;
|
|
95
|
+
ended_at?: string | null;
|
|
96
|
+
duration_ms?: number;
|
|
97
|
+
status?: "OK" | "ERROR";
|
|
98
|
+
error?: string | null;
|
|
99
|
+
model?: string;
|
|
100
|
+
usage?: {
|
|
101
|
+
input_tokens?: number;
|
|
102
|
+
output_tokens?: number;
|
|
103
|
+
};
|
|
104
|
+
tool_name?: string;
|
|
105
|
+
};
|
|
106
|
+
type SdkTracePayload = {
|
|
107
|
+
project_id: string;
|
|
108
|
+
trace: {
|
|
109
|
+
id?: string;
|
|
110
|
+
name: string;
|
|
111
|
+
input?: unknown;
|
|
112
|
+
output?: unknown;
|
|
113
|
+
metadata?: Record<string, unknown>;
|
|
114
|
+
thread_id?: string;
|
|
115
|
+
user_id?: string;
|
|
116
|
+
environment?: string;
|
|
117
|
+
started_at: string;
|
|
118
|
+
ended_at?: string | null;
|
|
119
|
+
duration_ms?: number;
|
|
120
|
+
status?: "OK" | "ERROR";
|
|
121
|
+
error?: string | null;
|
|
122
|
+
spans: SdkTraceSpanPayload[];
|
|
123
|
+
};
|
|
124
|
+
replace?: boolean;
|
|
125
|
+
};
|
|
126
|
+
export declare class SpanHandle {
|
|
127
|
+
private readonly trace;
|
|
128
|
+
private readonly options;
|
|
129
|
+
readonly id: string;
|
|
130
|
+
private ended;
|
|
131
|
+
private readonly payload;
|
|
132
|
+
constructor(trace: TraceContext, options: SpanOptions, payload?: SdkTraceSpanPayload);
|
|
133
|
+
end(options?: Omit<SpanOptions, "id" | "name" | "type" | "startedAt">): void;
|
|
134
|
+
startSpan(name: string): SpanHandle;
|
|
135
|
+
startSpan(options: Omit<SpanOptions, "endedAt">): SpanHandle;
|
|
136
|
+
startGeneration(name: string): SpanHandle;
|
|
137
|
+
startGeneration(options: Omit<GenerationOptions, "endedAt" | "type">): SpanHandle;
|
|
138
|
+
startTool(name: string): SpanHandle;
|
|
139
|
+
startTool(options: Omit<ToolOptions, "endedAt" | "type">): SpanHandle;
|
|
140
|
+
recordSpan(name: string): SpanHandle;
|
|
141
|
+
recordSpan(options: SpanOptions): SpanHandle;
|
|
142
|
+
recordGeneration(options: string | GenerationOptions): void;
|
|
143
|
+
recordTool(options: string | ToolOptions): void;
|
|
144
|
+
/** @deprecated Use startSpan() or recordSpan(). */
|
|
145
|
+
span(name: string): SpanHandle;
|
|
146
|
+
span(options: SpanOptions): SpanHandle;
|
|
147
|
+
/** @deprecated Use recordGeneration() or startGeneration(). */
|
|
148
|
+
generation(options: string | GenerationOptions): void;
|
|
149
|
+
/** @deprecated Use recordTool() or startTool(). */
|
|
150
|
+
tool(options: string | ToolOptions): void;
|
|
151
|
+
}
|
|
152
|
+
export declare class NoopSpanHandle {
|
|
153
|
+
readonly id = "";
|
|
154
|
+
end(): void;
|
|
155
|
+
startSpan(): NoopSpanHandle;
|
|
156
|
+
startGeneration(): NoopSpanHandle;
|
|
157
|
+
startTool(): NoopSpanHandle;
|
|
158
|
+
recordSpan(): NoopSpanHandle;
|
|
159
|
+
recordGeneration(): void;
|
|
160
|
+
recordTool(): void;
|
|
161
|
+
span(): NoopSpanHandle;
|
|
162
|
+
generation(): void;
|
|
163
|
+
tool(): void;
|
|
164
|
+
}
|
|
165
|
+
export declare class TraceContext {
|
|
166
|
+
private readonly options;
|
|
167
|
+
private onChange?;
|
|
168
|
+
private readonly spans;
|
|
169
|
+
private traceOutput;
|
|
170
|
+
private traceError;
|
|
171
|
+
readonly id: string;
|
|
172
|
+
constructor(options: TraceOptions, onChange?: (() => void) | undefined);
|
|
173
|
+
input(value: unknown): void;
|
|
174
|
+
output(value: unknown): void;
|
|
175
|
+
duration(durationMs: number): void;
|
|
176
|
+
fail(error: unknown): void;
|
|
177
|
+
changed(): void;
|
|
178
|
+
setChangeHandler(onChange: () => void): void;
|
|
179
|
+
addSpan(options: SpanOptions): SdkTraceSpanPayload;
|
|
180
|
+
recordSpan(name: string): SpanHandle;
|
|
181
|
+
recordSpan(options: SpanOptions): SpanHandle;
|
|
182
|
+
recordGeneration(options: string | GenerationOptions): void;
|
|
183
|
+
recordTool(options: string | ToolOptions): void;
|
|
184
|
+
startSpan(name: string): SpanHandle;
|
|
185
|
+
startSpan(options: Omit<SpanOptions, "endedAt">): SpanHandle;
|
|
186
|
+
startGeneration(options: Omit<GenerationOptions, "endedAt" | "type">): SpanHandle;
|
|
187
|
+
startTool(options: Omit<ToolOptions, "endedAt" | "type">): SpanHandle;
|
|
188
|
+
/** @deprecated Use startSpan() or recordSpan(). */
|
|
189
|
+
span(name: string): SpanHandle;
|
|
190
|
+
span(options: SpanOptions): SpanHandle;
|
|
191
|
+
/** @deprecated Use recordGeneration() or startGeneration(). */
|
|
192
|
+
generation(options: string | GenerationOptions): void;
|
|
193
|
+
/** @deprecated Use recordTool() or startTool(). */
|
|
194
|
+
tool(options: string | ToolOptions): void;
|
|
195
|
+
toPayload(projectId: string, startedAt: Date, endedAt: Date, replace?: boolean): SdkTracePayload;
|
|
196
|
+
}
|
|
197
|
+
export declare class TraceHandle extends TraceContext {
|
|
198
|
+
private readonly flushFn;
|
|
199
|
+
private readonly startedAt;
|
|
200
|
+
private flushTimer;
|
|
201
|
+
private flushPromise;
|
|
202
|
+
constructor(options: TraceOptions, flushFn: (trace: TraceHandle, startedAt: Date, endedAt: Date) => Promise<void>, startedAt?: Date);
|
|
203
|
+
flush(): Promise<void>;
|
|
204
|
+
end(): Promise<void>;
|
|
205
|
+
end(output: unknown): Promise<void>;
|
|
206
|
+
end(options: TraceEndOptions): Promise<void>;
|
|
207
|
+
private scheduleFlush;
|
|
208
|
+
}
|
|
209
|
+
export declare class Lemma {
|
|
210
|
+
private readonly apiKey;
|
|
211
|
+
private readonly projectId;
|
|
212
|
+
private readonly baseUrl;
|
|
213
|
+
private readonly fetchImpl;
|
|
214
|
+
private readonly traces;
|
|
215
|
+
constructor(options?: LemmaClientOptions);
|
|
216
|
+
trace(): TraceHandle;
|
|
217
|
+
trace(options: TraceOptions | string): TraceHandle;
|
|
218
|
+
trace<T>(options: TraceOptions | string, fn: (trace: TraceContext) => T | Promise<T>): Promise<T>;
|
|
219
|
+
recordSpan(options: DetachedSpanOptions | string): SpanHandle | NoopSpanHandle;
|
|
220
|
+
recordGeneration(options: DetachedGenerationOptions | string): void;
|
|
221
|
+
recordTool(options: DetachedToolOptions | string): void;
|
|
222
|
+
startSpan(options: Omit<SpanOptions, "endedAt"> | DetachedSpanOptions): SpanHandle | NoopSpanHandle;
|
|
223
|
+
startGeneration(options: Omit<GenerationOptions, "endedAt" | "type"> | DetachedGenerationOptions): SpanHandle | NoopSpanHandle;
|
|
224
|
+
startTool(options: Omit<ToolOptions, "endedAt" | "type"> | DetachedToolOptions): SpanHandle | NoopSpanHandle;
|
|
225
|
+
/** @deprecated Use startSpan() or recordSpan(). */
|
|
226
|
+
span(options: DetachedSpanOptions | string): SpanHandle | NoopSpanHandle;
|
|
227
|
+
/** @deprecated Use recordGeneration() or startGeneration(). */
|
|
228
|
+
generation(options: DetachedGenerationOptions | string): void;
|
|
229
|
+
/** @deprecated Use recordTool() or startTool(). */
|
|
230
|
+
tool(options: DetachedToolOptions | string): void;
|
|
231
|
+
private traceFor;
|
|
232
|
+
private detachedTraceFor;
|
|
233
|
+
private flushTrace;
|
|
234
|
+
}
|
|
235
|
+
export declare function active(): TraceContext;
|
|
236
|
+
export {};
|
|
237
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,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