@fallom/trace 0.1.12 → 0.2.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 +215 -178
- package/dist/chunk-2BP4H4AD.mjs +3012 -0
- package/dist/chunk-7P6ASYW6.mjs +9 -0
- package/dist/chunk-K7HYYE4Y.mjs +2930 -0
- package/dist/chunk-KAZ5NEU2.mjs +2237 -0
- package/dist/chunk-KMA4IPED.mjs +252 -0
- package/dist/chunk-W6M2RQ3W.mjs +251 -0
- package/dist/index.d.mts +210 -256
- package/dist/index.d.ts +210 -256
- package/dist/index.js +792 -789
- package/dist/index.mjs +592 -590
- package/dist/models-2Y6DRQPS.mjs +9 -0
- package/dist/models-BUHMMTWK.mjs +9 -0
- package/dist/models-JIO5LVMB.mjs +8 -0
- package/dist/models-JKMOBZUO.mjs +8 -0
- package/dist/prompts-XSZHTCX7.mjs +15 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
|
2
2
|
import { ExportResult } from '@opentelemetry/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Fallom tracing module.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
5
|
+
* Type definitions for Fallom tracing module.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Session context for grouping traces.
|
|
9
9
|
*/
|
|
10
10
|
interface SessionContext {
|
|
11
11
|
configKey: string;
|
|
@@ -13,265 +13,216 @@ interface SessionContext {
|
|
|
13
13
|
customerId?: string;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param options - Configuration options
|
|
19
|
-
* @param options.apiKey - Your Fallom API key. Defaults to FALLOM_API_KEY env var.
|
|
20
|
-
* @param options.baseUrl - API base URL. Defaults to FALLOM_BASE_URL env var, or https://spans.fallom.com
|
|
21
|
-
* @param options.captureContent - Whether to capture prompt/completion content in traces.
|
|
22
|
-
* Set to false for privacy/compliance. Defaults to true.
|
|
23
|
-
* Also respects FALLOM_CAPTURE_CONTENT env var ("true"/"false").
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* import fallom from 'fallom';
|
|
28
|
-
*
|
|
29
|
-
* // Normal usage (captures everything)
|
|
30
|
-
* fallom.trace.init();
|
|
31
|
-
*
|
|
32
|
-
* // Privacy mode (no prompts/completions stored)
|
|
33
|
-
* fallom.trace.init({ captureContent: false });
|
|
34
|
-
*
|
|
35
|
-
* fallom.trace.setSession("my-agent", sessionId);
|
|
36
|
-
* await agent.run(message); // Automatically traced
|
|
37
|
-
* ```
|
|
16
|
+
* Trace context for linking spans together.
|
|
38
17
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
debug?: boolean;
|
|
44
|
-
}): Promise<void>;
|
|
18
|
+
interface TraceContext {
|
|
19
|
+
traceId: string;
|
|
20
|
+
parentSpanId?: string;
|
|
21
|
+
}
|
|
45
22
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* All subsequent LLM calls in this async context will be
|
|
49
|
-
* automatically tagged with this configKey, sessionId, and customerId.
|
|
50
|
-
*
|
|
51
|
-
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
52
|
-
* @param sessionId - Your session/conversation ID
|
|
53
|
-
* @param customerId - Optional customer/user identifier for analytics
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* trace.setSession("linkedin-agent", sessionId, "user_123");
|
|
58
|
-
* await agent.run(message); // Automatically traced with session + customer
|
|
59
|
-
* ```
|
|
23
|
+
* Data structure for a trace sent to the Fallom API.
|
|
60
24
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
25
|
+
interface TraceData {
|
|
26
|
+
config_key: string;
|
|
27
|
+
session_id: string;
|
|
28
|
+
customer_id?: string;
|
|
29
|
+
trace_id: string;
|
|
30
|
+
span_id: string;
|
|
31
|
+
parent_span_id?: string;
|
|
32
|
+
name: string;
|
|
33
|
+
kind?: string;
|
|
34
|
+
model?: string;
|
|
35
|
+
start_time: string;
|
|
36
|
+
end_time: string;
|
|
37
|
+
duration_ms: number;
|
|
38
|
+
status: "OK" | "ERROR";
|
|
39
|
+
error_message?: string;
|
|
40
|
+
prompt_tokens?: number;
|
|
41
|
+
completion_tokens?: number;
|
|
42
|
+
total_tokens?: number;
|
|
43
|
+
time_to_first_token_ms?: number;
|
|
44
|
+
is_streaming?: boolean;
|
|
45
|
+
attributes?: Record<string, unknown>;
|
|
46
|
+
prompt_key?: string;
|
|
47
|
+
prompt_version?: number;
|
|
48
|
+
prompt_ab_test_key?: string;
|
|
49
|
+
prompt_variant_index?: number;
|
|
50
|
+
}
|
|
79
51
|
/**
|
|
80
|
-
*
|
|
52
|
+
* Options for creating a Fallom session.
|
|
81
53
|
*/
|
|
82
|
-
|
|
54
|
+
interface SessionOptions {
|
|
55
|
+
/** Your config name (e.g., "linkedin-agent") */
|
|
56
|
+
configKey: string;
|
|
57
|
+
/** Your session/conversation ID */
|
|
58
|
+
sessionId: string;
|
|
59
|
+
/** Optional customer/user identifier for analytics */
|
|
60
|
+
customerId?: string;
|
|
61
|
+
}
|
|
83
62
|
/**
|
|
84
|
-
*
|
|
63
|
+
* Options for wrapAISDK.
|
|
85
64
|
*/
|
|
86
|
-
|
|
65
|
+
interface WrapAISDKOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Enable debug logging to see the raw Vercel AI SDK response structure.
|
|
68
|
+
* Useful for debugging token extraction issues with different providers.
|
|
69
|
+
*/
|
|
70
|
+
debug?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
87
73
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* Use this for metrics that OTEL can't capture automatically:
|
|
91
|
-
* - Outlier scores
|
|
92
|
-
* - Engagement metrics
|
|
93
|
-
* - Conversion rates
|
|
94
|
-
* - Any business-specific outcome
|
|
74
|
+
* Core Fallom tracing functionality.
|
|
95
75
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @param options.configKey - Config name (optional if setSession was called)
|
|
99
|
-
* @param options.sessionId - Session ID (optional if setSession was called)
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* // If session context is set:
|
|
104
|
-
* trace.span({ outlier_score: 0.8, engagement: 42 });
|
|
105
|
-
*
|
|
106
|
-
* // Or explicitly:
|
|
107
|
-
* trace.span(
|
|
108
|
-
* { outlier_score: 0.8 },
|
|
109
|
-
* { configKey: "linkedin-agent", sessionId: "user123-convo456" }
|
|
110
|
-
* );
|
|
111
|
-
* ```
|
|
76
|
+
* Handles initialization and trace sending.
|
|
77
|
+
* Session management is now handled by FallomSession.
|
|
112
78
|
*/
|
|
113
|
-
|
|
114
|
-
configKey?: string;
|
|
115
|
-
sessionId?: string;
|
|
116
|
-
}): void;
|
|
117
|
-
/**
|
|
118
|
-
* Shutdown the tracing SDK gracefully.
|
|
119
|
-
*/
|
|
120
|
-
declare function shutdown(): Promise<void>;
|
|
79
|
+
|
|
121
80
|
/**
|
|
122
|
-
*
|
|
123
|
-
* Works with OpenAI, OpenRouter, Azure OpenAI, LiteLLM, and any OpenAI-compatible API.
|
|
81
|
+
* Initialize Fallom tracing.
|
|
124
82
|
*
|
|
125
|
-
* @param
|
|
126
|
-
* @
|
|
83
|
+
* @param options - Configuration options
|
|
84
|
+
* @param options.apiKey - Your Fallom API key. Defaults to FALLOM_API_KEY env var.
|
|
85
|
+
* @param options.baseUrl - API base URL. Defaults to https://traces.fallom.com
|
|
86
|
+
* @param options.captureContent - Whether to capture prompt/completion content.
|
|
87
|
+
* @param options.debug - Enable debug logging.
|
|
127
88
|
*
|
|
128
89
|
* @example
|
|
129
90
|
* ```typescript
|
|
130
|
-
* import
|
|
131
|
-
*
|
|
91
|
+
* import fallom from '@fallom/trace';
|
|
92
|
+
*
|
|
93
|
+
* await fallom.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
132
94
|
*
|
|
133
|
-
* const
|
|
95
|
+
* const session = fallom.session({
|
|
96
|
+
* configKey: "my-agent",
|
|
97
|
+
* sessionId: "session-123",
|
|
98
|
+
* });
|
|
134
99
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
100
|
+
* const { generateText } = session.wrapAISDK(ai);
|
|
101
|
+
* await generateText({ model: openai("gpt-4o"), prompt: "Hello!" });
|
|
137
102
|
* ```
|
|
138
103
|
*/
|
|
139
|
-
declare function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}>(client: T): T;
|
|
104
|
+
declare function init$3(options?: {
|
|
105
|
+
apiKey?: string;
|
|
106
|
+
baseUrl?: string;
|
|
107
|
+
captureContent?: boolean;
|
|
108
|
+
debug?: boolean;
|
|
109
|
+
}): Promise<void>;
|
|
146
110
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @param client - The Anthropic client instance
|
|
150
|
-
* @returns The same client with tracing enabled
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* import Anthropic from "@anthropic-ai/sdk";
|
|
155
|
-
* import { trace } from "@fallom/trace";
|
|
156
|
-
*
|
|
157
|
-
* const anthropic = trace.wrapAnthropic(new Anthropic());
|
|
158
|
-
*
|
|
159
|
-
* trace.setSession("my-config", sessionId);
|
|
160
|
-
* const response = await anthropic.messages.create({...}); // Automatically traced!
|
|
161
|
-
* ```
|
|
111
|
+
* Shutdown the tracing SDK gracefully.
|
|
162
112
|
*/
|
|
163
|
-
declare function
|
|
164
|
-
|
|
165
|
-
create: (...args: any[]) => Promise<any>;
|
|
166
|
-
};
|
|
167
|
-
}>(client: T): T;
|
|
113
|
+
declare function shutdown(): Promise<void>;
|
|
114
|
+
|
|
168
115
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @param client - The GoogleGenerativeAI client instance
|
|
172
|
-
* @returns The same client with tracing enabled
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
177
|
-
* import { trace } from "@fallom/trace";
|
|
178
|
-
*
|
|
179
|
-
* const genAI = new GoogleGenerativeAI(apiKey);
|
|
180
|
-
* const model = trace.wrapGoogleAI(genAI.getGenerativeModel({ model: "gemini-pro" }));
|
|
181
|
-
*
|
|
182
|
-
* trace.setSession("my-config", sessionId);
|
|
183
|
-
* const response = await model.generateContent("Hello!"); // Automatically traced!
|
|
184
|
-
* ```
|
|
116
|
+
* FallomSession - Session-scoped tracing for concurrent-safe operations.
|
|
185
117
|
*/
|
|
186
|
-
|
|
187
|
-
generateContent: (...args: any[]) => Promise<any>;
|
|
188
|
-
}>(model: T): T;
|
|
118
|
+
|
|
189
119
|
/**
|
|
190
|
-
*
|
|
191
|
-
* Works with generateText, streamText, generateObject, streamObject.
|
|
120
|
+
* A session-scoped Fallom instance.
|
|
192
121
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
122
|
+
* All wrappers created from this session automatically use the session context,
|
|
123
|
+
* making them safe for concurrent operations without global state issues.
|
|
195
124
|
*
|
|
196
125
|
* @example
|
|
197
126
|
* ```typescript
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* await trace.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
203
|
-
* const { generateText, streamText } = trace.wrapAISDK(ai);
|
|
204
|
-
*
|
|
205
|
-
* const openrouter = createOpenAI({
|
|
206
|
-
* apiKey: process.env.OPENROUTER_API_KEY,
|
|
207
|
-
* baseURL: "https://openrouter.ai/api/v1",
|
|
127
|
+
* const session = fallom.session({
|
|
128
|
+
* configKey: "my-app",
|
|
129
|
+
* sessionId: "session-123",
|
|
130
|
+
* customerId: "user-456"
|
|
208
131
|
* });
|
|
209
132
|
*
|
|
210
|
-
*
|
|
211
|
-
* const {
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
133
|
+
* // All calls use the session context
|
|
134
|
+
* const { generateText } = session.wrapAISDK(ai);
|
|
135
|
+
* await generateText({ model: openai("gpt-4o"), prompt: "..." });
|
|
136
|
+
*
|
|
137
|
+
* // Or wrap the model directly
|
|
138
|
+
* const model = session.traceModel(openai("gpt-4o"));
|
|
139
|
+
* await generateText({ model, prompt: "..." });
|
|
215
140
|
* ```
|
|
216
141
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
142
|
+
declare class FallomSession {
|
|
143
|
+
private ctx;
|
|
144
|
+
constructor(options: SessionOptions);
|
|
145
|
+
/** Get the session context. */
|
|
146
|
+
getContext(): SessionContext;
|
|
219
147
|
/**
|
|
220
|
-
*
|
|
221
|
-
* Useful for debugging missing usage/token data.
|
|
148
|
+
* Get model assignment for this session (A/B testing).
|
|
222
149
|
*/
|
|
223
|
-
|
|
150
|
+
getModel(configKeyOrOptions?: string | {
|
|
151
|
+
fallback?: string;
|
|
152
|
+
version?: number;
|
|
153
|
+
}, options?: {
|
|
154
|
+
fallback?: string;
|
|
155
|
+
version?: number;
|
|
156
|
+
}): Promise<string>;
|
|
157
|
+
/**
|
|
158
|
+
* Wrap a Vercel AI SDK model to trace all calls.
|
|
159
|
+
*/
|
|
160
|
+
traceModel<T extends {
|
|
161
|
+
doGenerate?: (...args: any[]) => Promise<any>;
|
|
162
|
+
doStream?: (...args: any[]) => Promise<any>;
|
|
163
|
+
}>(model: T): T;
|
|
164
|
+
/** Wrap OpenAI client. Delegates to shared wrapper. */
|
|
165
|
+
wrapOpenAI<T extends {
|
|
166
|
+
chat: {
|
|
167
|
+
completions: {
|
|
168
|
+
create: (...args: any[]) => Promise<any>;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
}>(client: T): T;
|
|
172
|
+
/** Wrap Anthropic client. Delegates to shared wrapper. */
|
|
173
|
+
wrapAnthropic<T extends {
|
|
174
|
+
messages: {
|
|
175
|
+
create: (...args: any[]) => Promise<any>;
|
|
176
|
+
};
|
|
177
|
+
}>(client: T): T;
|
|
178
|
+
/** Wrap Google AI model. Delegates to shared wrapper. */
|
|
179
|
+
wrapGoogleAI<T extends {
|
|
180
|
+
generateContent: (...args: any[]) => Promise<any>;
|
|
181
|
+
}>(model: T): T;
|
|
182
|
+
/** Wrap Vercel AI SDK. Delegates to shared wrapper. */
|
|
183
|
+
wrapAISDK<T extends {
|
|
184
|
+
generateText: (...args: any[]) => Promise<any>;
|
|
185
|
+
streamText: (...args: any[]) => any;
|
|
186
|
+
generateObject?: (...args: any[]) => Promise<any>;
|
|
187
|
+
streamObject?: (...args: any[]) => any;
|
|
188
|
+
}>(ai: T, options?: WrapAISDKOptions): {
|
|
189
|
+
generateText: T["generateText"];
|
|
190
|
+
streamText: T["streamText"];
|
|
191
|
+
generateObject: T["generateObject"];
|
|
192
|
+
streamObject: T["streamObject"];
|
|
193
|
+
};
|
|
194
|
+
/** Wrap Mastra agent. Delegates to shared wrapper. */
|
|
195
|
+
wrapMastraAgent<T extends {
|
|
196
|
+
generate: (...args: any[]) => Promise<any>;
|
|
197
|
+
name?: string;
|
|
198
|
+
}>(agent: T): T;
|
|
224
199
|
}
|
|
225
|
-
declare function wrapAISDK<T extends {
|
|
226
|
-
generateText: (...args: any[]) => Promise<any>;
|
|
227
|
-
streamText: (...args: any[]) => any;
|
|
228
|
-
generateObject?: (...args: any[]) => Promise<any>;
|
|
229
|
-
streamObject?: (...args: any[]) => any;
|
|
230
|
-
}>(ai: T, options?: WrapAISDKOptions): {
|
|
231
|
-
generateText: T["generateText"];
|
|
232
|
-
streamText: T["streamText"];
|
|
233
|
-
generateObject: T["generateObject"];
|
|
234
|
-
streamObject: T["streamObject"];
|
|
235
|
-
};
|
|
236
200
|
/**
|
|
237
|
-
*
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
*
|
|
243
|
-
* ```typescript
|
|
244
|
-
* import { trace } from "@fallom/trace";
|
|
245
|
-
* import { Agent } from "@mastra/core";
|
|
246
|
-
*
|
|
247
|
-
* await trace.init({ apiKey: "your-key" });
|
|
201
|
+
* Create a session-scoped Fallom instance.
|
|
202
|
+
*/
|
|
203
|
+
declare function session(options: SessionOptions): FallomSession;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Fallom tracing module.
|
|
248
207
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
208
|
+
* Auto-instruments all LLM calls via OTEL and groups them by session.
|
|
209
|
+
* Also supports custom spans for business metrics.
|
|
251
210
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* // ^ Automatically traced!
|
|
255
|
-
* ```
|
|
211
|
+
* This file re-exports from the modular trace/ directory.
|
|
212
|
+
* Each wrapper is in its own file for better maintainability.
|
|
256
213
|
*/
|
|
257
|
-
declare function wrapMastraAgent<T extends {
|
|
258
|
-
generate: (...args: any[]) => Promise<any>;
|
|
259
|
-
name?: string;
|
|
260
|
-
}>(agent: T): T;
|
|
261
214
|
|
|
262
|
-
|
|
263
|
-
declare const
|
|
264
|
-
|
|
265
|
-
|
|
215
|
+
type trace_FallomSession = FallomSession;
|
|
216
|
+
declare const trace_FallomSession: typeof FallomSession;
|
|
217
|
+
type trace_SessionContext = SessionContext;
|
|
218
|
+
type trace_SessionOptions = SessionOptions;
|
|
219
|
+
type trace_TraceContext = TraceContext;
|
|
220
|
+
type trace_TraceData = TraceData;
|
|
221
|
+
type trace_WrapAISDKOptions = WrapAISDKOptions;
|
|
222
|
+
declare const trace_session: typeof session;
|
|
266
223
|
declare const trace_shutdown: typeof shutdown;
|
|
267
|
-
declare const trace_span: typeof span;
|
|
268
|
-
declare const trace_wrapAISDK: typeof wrapAISDK;
|
|
269
|
-
declare const trace_wrapAnthropic: typeof wrapAnthropic;
|
|
270
|
-
declare const trace_wrapGoogleAI: typeof wrapGoogleAI;
|
|
271
|
-
declare const trace_wrapMastraAgent: typeof wrapMastraAgent;
|
|
272
|
-
declare const trace_wrapOpenAI: typeof wrapOpenAI;
|
|
273
224
|
declare namespace trace {
|
|
274
|
-
export {
|
|
225
|
+
export { trace_FallomSession as FallomSession, type trace_SessionContext as SessionContext, type trace_SessionOptions as SessionOptions, type trace_TraceContext as TraceContext, type trace_TraceData as TraceData, type trace_WrapAISDKOptions as WrapAISDKOptions, init$3 as init, trace_session as session, trace_shutdown as shutdown };
|
|
275
226
|
}
|
|
276
227
|
|
|
277
228
|
/**
|
|
@@ -304,9 +255,6 @@ declare function init$2(options?: {
|
|
|
304
255
|
*
|
|
305
256
|
* Same session_id always returns same model (sticky assignment).
|
|
306
257
|
*
|
|
307
|
-
* Also automatically sets trace context, so all subsequent LLM calls
|
|
308
|
-
* are tagged with this session.
|
|
309
|
-
*
|
|
310
258
|
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
311
259
|
* @param sessionId - Your session/conversation ID (must be consistent)
|
|
312
260
|
* @param options - Optional settings
|
|
@@ -485,7 +433,7 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
485
433
|
* Fallom Exporter for Mastra
|
|
486
434
|
*
|
|
487
435
|
* Custom OpenTelemetry exporter that sends traces from Mastra agents to Fallom.
|
|
488
|
-
*
|
|
436
|
+
* Session context should be passed to the exporter constructor.
|
|
489
437
|
*
|
|
490
438
|
* Usage with Mastra:
|
|
491
439
|
* ```typescript
|
|
@@ -495,7 +443,14 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
495
443
|
* // Initialize trace module
|
|
496
444
|
* await trace.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
497
445
|
*
|
|
498
|
-
* // Create
|
|
446
|
+
* // Create session for this request
|
|
447
|
+
* const session = trace.session({
|
|
448
|
+
* configKey: "my-app",
|
|
449
|
+
* sessionId: "session-123",
|
|
450
|
+
* customerId: "user-456"
|
|
451
|
+
* });
|
|
452
|
+
*
|
|
453
|
+
* // Create Mastra with Fallom exporter (pass session context)
|
|
499
454
|
* const mastra = new Mastra({
|
|
500
455
|
* agents: { myAgent },
|
|
501
456
|
* telemetry: {
|
|
@@ -503,13 +458,13 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
503
458
|
* enabled: true,
|
|
504
459
|
* export: {
|
|
505
460
|
* type: "custom",
|
|
506
|
-
* exporter: new FallomExporter(
|
|
461
|
+
* exporter: new FallomExporter({
|
|
462
|
+
* session: session.getContext()
|
|
463
|
+
* }),
|
|
507
464
|
* },
|
|
508
465
|
* },
|
|
509
466
|
* });
|
|
510
467
|
*
|
|
511
|
-
* // In your request handler:
|
|
512
|
-
* trace.setSession("my-app", "session-123", "user-456");
|
|
513
468
|
* const result = await mastra.getAgent("myAgent").generate("Hello!");
|
|
514
469
|
* ```
|
|
515
470
|
*/
|
|
@@ -521,6 +476,8 @@ interface FallomExporterOptions {
|
|
|
521
476
|
baseUrl?: string;
|
|
522
477
|
/** Enable debug logging */
|
|
523
478
|
debug?: boolean;
|
|
479
|
+
/** Session context for tracing */
|
|
480
|
+
session?: SessionContext;
|
|
524
481
|
}
|
|
525
482
|
/**
|
|
526
483
|
* Set prompt tracking info.
|
|
@@ -539,13 +496,14 @@ declare function clearMastraPrompt(): void;
|
|
|
539
496
|
/**
|
|
540
497
|
* OpenTelemetry SpanExporter that sends traces to Fallom.
|
|
541
498
|
*
|
|
542
|
-
*
|
|
499
|
+
* Pass session context via constructor options.
|
|
543
500
|
* Compatible with Mastra's custom exporter interface.
|
|
544
501
|
*/
|
|
545
502
|
declare class FallomExporter implements SpanExporter {
|
|
546
503
|
private apiKey;
|
|
547
504
|
private baseUrl;
|
|
548
505
|
private debug;
|
|
506
|
+
private session?;
|
|
549
507
|
private pendingExports;
|
|
550
508
|
constructor(options?: FallomExporterOptions);
|
|
551
509
|
private log;
|
|
@@ -592,35 +550,30 @@ declare class FallomExporter implements SpanExporter {
|
|
|
592
550
|
*
|
|
593
551
|
* @example
|
|
594
552
|
* ```typescript
|
|
595
|
-
* import fallom from 'fallom';
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
553
|
+
* import fallom from '@fallom/trace';
|
|
554
|
+
* import * as ai from 'ai';
|
|
555
|
+
* import { createOpenAI } from '@ai-sdk/openai';
|
|
556
|
+
*
|
|
557
|
+
* // Initialize once
|
|
558
|
+
* await fallom.init({ apiKey: "your-api-key" });
|
|
559
|
+
*
|
|
560
|
+
* // Create a session for this conversation/request
|
|
561
|
+
* const session = fallom.session({
|
|
562
|
+
* configKey: "my-agent",
|
|
563
|
+
* sessionId: "session-123",
|
|
564
|
+
* customerId: "user-456",
|
|
606
565
|
* });
|
|
607
566
|
*
|
|
608
|
-
* //
|
|
609
|
-
* const
|
|
610
|
-
*
|
|
611
|
-
* });
|
|
567
|
+
* // Option 1: Wrap the AI SDK (our style)
|
|
568
|
+
* const { generateText } = session.wrapAISDK(ai);
|
|
569
|
+
* await generateText({ model: openai("gpt-4o"), prompt: "Hello!" });
|
|
612
570
|
*
|
|
613
|
-
* //
|
|
614
|
-
* const
|
|
615
|
-
*
|
|
616
|
-
* messages: [
|
|
617
|
-
* { role: "system", content: prompt.system },
|
|
618
|
-
* { role: "user", content: prompt.user }
|
|
619
|
-
* ]
|
|
620
|
-
* });
|
|
571
|
+
* // Option 2: Wrap the model directly (PostHog style)
|
|
572
|
+
* const model = session.traceModel(openai("gpt-4o"));
|
|
573
|
+
* await ai.generateText({ model, prompt: "Hello!" });
|
|
621
574
|
*
|
|
622
|
-
* //
|
|
623
|
-
*
|
|
575
|
+
* // Get A/B tested model within session
|
|
576
|
+
* const modelName = await session.getModel({ fallback: "gpt-4o-mini" });
|
|
624
577
|
* ```
|
|
625
578
|
*/
|
|
626
579
|
|
|
@@ -629,6 +582,7 @@ declare const _default: {
|
|
|
629
582
|
trace: typeof trace;
|
|
630
583
|
models: typeof models;
|
|
631
584
|
prompts: typeof prompts;
|
|
585
|
+
session: typeof session;
|
|
632
586
|
};
|
|
633
587
|
|
|
634
|
-
export { FallomExporter, type FallomExporterOptions, type InitOptions, type PromptResult, clearMastraPrompt, _default as default, init, models, prompts, setMastraPrompt, setMastraPromptAB, trace };
|
|
588
|
+
export { FallomExporter, type FallomExporterOptions, FallomSession, type InitOptions, type PromptResult, type SessionContext, type SessionOptions, clearMastraPrompt, _default as default, init, models, prompts, session, setMastraPrompt, setMastraPromptAB, trace };
|