@fallom/trace 0.1.12 → 0.2.1
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 +208 -256
- package/dist/index.d.ts +208 -256
- package/dist/index.js +794 -789
- package/dist/index.mjs +594 -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.mts
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,214 @@ 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 (PostHog style).
|
|
159
|
+
* Returns the same model type with tracing injected.
|
|
160
|
+
*/
|
|
161
|
+
traceModel<T>(model: T): T;
|
|
162
|
+
/** Wrap OpenAI client. Delegates to shared wrapper. */
|
|
163
|
+
wrapOpenAI<T extends {
|
|
164
|
+
chat: {
|
|
165
|
+
completions: {
|
|
166
|
+
create: (...args: any[]) => Promise<any>;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
}>(client: T): T;
|
|
170
|
+
/** Wrap Anthropic client. Delegates to shared wrapper. */
|
|
171
|
+
wrapAnthropic<T extends {
|
|
172
|
+
messages: {
|
|
173
|
+
create: (...args: any[]) => Promise<any>;
|
|
174
|
+
};
|
|
175
|
+
}>(client: T): T;
|
|
176
|
+
/** Wrap Google AI model. Delegates to shared wrapper. */
|
|
177
|
+
wrapGoogleAI<T extends {
|
|
178
|
+
generateContent: (...args: any[]) => Promise<any>;
|
|
179
|
+
}>(model: T): T;
|
|
180
|
+
/** Wrap Vercel AI SDK. Delegates to shared wrapper. */
|
|
181
|
+
wrapAISDK<T extends {
|
|
182
|
+
generateText: (...args: any[]) => Promise<any>;
|
|
183
|
+
streamText: (...args: any[]) => any;
|
|
184
|
+
generateObject?: (...args: any[]) => Promise<any>;
|
|
185
|
+
streamObject?: (...args: any[]) => any;
|
|
186
|
+
}>(ai: T, options?: WrapAISDKOptions): {
|
|
187
|
+
generateText: T["generateText"];
|
|
188
|
+
streamText: T["streamText"];
|
|
189
|
+
generateObject: T["generateObject"];
|
|
190
|
+
streamObject: T["streamObject"];
|
|
191
|
+
};
|
|
192
|
+
/** Wrap Mastra agent. Delegates to shared wrapper. */
|
|
193
|
+
wrapMastraAgent<T extends {
|
|
194
|
+
generate: (...args: any[]) => Promise<any>;
|
|
195
|
+
name?: string;
|
|
196
|
+
}>(agent: T): T;
|
|
224
197
|
}
|
|
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
198
|
/**
|
|
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" });
|
|
199
|
+
* Create a session-scoped Fallom instance.
|
|
200
|
+
*/
|
|
201
|
+
declare function session(options: SessionOptions): FallomSession;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Fallom tracing module.
|
|
248
205
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
206
|
+
* Auto-instruments all LLM calls via OTEL and groups them by session.
|
|
207
|
+
* Also supports custom spans for business metrics.
|
|
251
208
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* // ^ Automatically traced!
|
|
255
|
-
* ```
|
|
209
|
+
* This file re-exports from the modular trace/ directory.
|
|
210
|
+
* Each wrapper is in its own file for better maintainability.
|
|
256
211
|
*/
|
|
257
|
-
declare function wrapMastraAgent<T extends {
|
|
258
|
-
generate: (...args: any[]) => Promise<any>;
|
|
259
|
-
name?: string;
|
|
260
|
-
}>(agent: T): T;
|
|
261
212
|
|
|
262
|
-
|
|
263
|
-
declare const
|
|
264
|
-
|
|
265
|
-
|
|
213
|
+
type trace_FallomSession = FallomSession;
|
|
214
|
+
declare const trace_FallomSession: typeof FallomSession;
|
|
215
|
+
type trace_SessionContext = SessionContext;
|
|
216
|
+
type trace_SessionOptions = SessionOptions;
|
|
217
|
+
type trace_TraceContext = TraceContext;
|
|
218
|
+
type trace_TraceData = TraceData;
|
|
219
|
+
type trace_WrapAISDKOptions = WrapAISDKOptions;
|
|
220
|
+
declare const trace_session: typeof session;
|
|
266
221
|
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
222
|
declare namespace trace {
|
|
274
|
-
export {
|
|
223
|
+
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
224
|
}
|
|
276
225
|
|
|
277
226
|
/**
|
|
@@ -304,9 +253,6 @@ declare function init$2(options?: {
|
|
|
304
253
|
*
|
|
305
254
|
* Same session_id always returns same model (sticky assignment).
|
|
306
255
|
*
|
|
307
|
-
* Also automatically sets trace context, so all subsequent LLM calls
|
|
308
|
-
* are tagged with this session.
|
|
309
|
-
*
|
|
310
256
|
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
311
257
|
* @param sessionId - Your session/conversation ID (must be consistent)
|
|
312
258
|
* @param options - Optional settings
|
|
@@ -485,7 +431,7 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
485
431
|
* Fallom Exporter for Mastra
|
|
486
432
|
*
|
|
487
433
|
* Custom OpenTelemetry exporter that sends traces from Mastra agents to Fallom.
|
|
488
|
-
*
|
|
434
|
+
* Session context should be passed to the exporter constructor.
|
|
489
435
|
*
|
|
490
436
|
* Usage with Mastra:
|
|
491
437
|
* ```typescript
|
|
@@ -495,7 +441,14 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
495
441
|
* // Initialize trace module
|
|
496
442
|
* await trace.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
497
443
|
*
|
|
498
|
-
* // Create
|
|
444
|
+
* // Create session for this request
|
|
445
|
+
* const session = trace.session({
|
|
446
|
+
* configKey: "my-app",
|
|
447
|
+
* sessionId: "session-123",
|
|
448
|
+
* customerId: "user-456"
|
|
449
|
+
* });
|
|
450
|
+
*
|
|
451
|
+
* // Create Mastra with Fallom exporter (pass session context)
|
|
499
452
|
* const mastra = new Mastra({
|
|
500
453
|
* agents: { myAgent },
|
|
501
454
|
* telemetry: {
|
|
@@ -503,13 +456,13 @@ declare function init(options?: InitOptions): Promise<void>;
|
|
|
503
456
|
* enabled: true,
|
|
504
457
|
* export: {
|
|
505
458
|
* type: "custom",
|
|
506
|
-
* exporter: new FallomExporter(
|
|
459
|
+
* exporter: new FallomExporter({
|
|
460
|
+
* session: session.getContext()
|
|
461
|
+
* }),
|
|
507
462
|
* },
|
|
508
463
|
* },
|
|
509
464
|
* });
|
|
510
465
|
*
|
|
511
|
-
* // In your request handler:
|
|
512
|
-
* trace.setSession("my-app", "session-123", "user-456");
|
|
513
466
|
* const result = await mastra.getAgent("myAgent").generate("Hello!");
|
|
514
467
|
* ```
|
|
515
468
|
*/
|
|
@@ -521,6 +474,8 @@ interface FallomExporterOptions {
|
|
|
521
474
|
baseUrl?: string;
|
|
522
475
|
/** Enable debug logging */
|
|
523
476
|
debug?: boolean;
|
|
477
|
+
/** Session context for tracing */
|
|
478
|
+
session?: SessionContext;
|
|
524
479
|
}
|
|
525
480
|
/**
|
|
526
481
|
* Set prompt tracking info.
|
|
@@ -539,13 +494,14 @@ declare function clearMastraPrompt(): void;
|
|
|
539
494
|
/**
|
|
540
495
|
* OpenTelemetry SpanExporter that sends traces to Fallom.
|
|
541
496
|
*
|
|
542
|
-
*
|
|
497
|
+
* Pass session context via constructor options.
|
|
543
498
|
* Compatible with Mastra's custom exporter interface.
|
|
544
499
|
*/
|
|
545
500
|
declare class FallomExporter implements SpanExporter {
|
|
546
501
|
private apiKey;
|
|
547
502
|
private baseUrl;
|
|
548
503
|
private debug;
|
|
504
|
+
private session?;
|
|
549
505
|
private pendingExports;
|
|
550
506
|
constructor(options?: FallomExporterOptions);
|
|
551
507
|
private log;
|
|
@@ -592,35 +548,30 @@ declare class FallomExporter implements SpanExporter {
|
|
|
592
548
|
*
|
|
593
549
|
* @example
|
|
594
550
|
* ```typescript
|
|
595
|
-
* import fallom from 'fallom';
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
551
|
+
* import fallom from '@fallom/trace';
|
|
552
|
+
* import * as ai from 'ai';
|
|
553
|
+
* import { createOpenAI } from '@ai-sdk/openai';
|
|
554
|
+
*
|
|
555
|
+
* // Initialize once
|
|
556
|
+
* await fallom.init({ apiKey: "your-api-key" });
|
|
557
|
+
*
|
|
558
|
+
* // Create a session for this conversation/request
|
|
559
|
+
* const session = fallom.session({
|
|
560
|
+
* configKey: "my-agent",
|
|
561
|
+
* sessionId: "session-123",
|
|
562
|
+
* customerId: "user-456",
|
|
606
563
|
* });
|
|
607
564
|
*
|
|
608
|
-
* //
|
|
609
|
-
* const
|
|
610
|
-
*
|
|
611
|
-
* });
|
|
565
|
+
* // Option 1: Wrap the AI SDK (our style)
|
|
566
|
+
* const { generateText } = session.wrapAISDK(ai);
|
|
567
|
+
* await generateText({ model: openai("gpt-4o"), prompt: "Hello!" });
|
|
612
568
|
*
|
|
613
|
-
* //
|
|
614
|
-
* const
|
|
615
|
-
*
|
|
616
|
-
* messages: [
|
|
617
|
-
* { role: "system", content: prompt.system },
|
|
618
|
-
* { role: "user", content: prompt.user }
|
|
619
|
-
* ]
|
|
620
|
-
* });
|
|
569
|
+
* // Option 2: Wrap the model directly (PostHog style)
|
|
570
|
+
* const model = session.traceModel(openai("gpt-4o"));
|
|
571
|
+
* await ai.generateText({ model, prompt: "Hello!" });
|
|
621
572
|
*
|
|
622
|
-
* //
|
|
623
|
-
*
|
|
573
|
+
* // Get A/B tested model within session
|
|
574
|
+
* const modelName = await session.getModel({ fallback: "gpt-4o-mini" });
|
|
624
575
|
* ```
|
|
625
576
|
*/
|
|
626
577
|
|
|
@@ -629,6 +580,7 @@ declare const _default: {
|
|
|
629
580
|
trace: typeof trace;
|
|
630
581
|
models: typeof models;
|
|
631
582
|
prompts: typeof prompts;
|
|
583
|
+
session: typeof session;
|
|
632
584
|
};
|
|
633
585
|
|
|
634
|
-
export { FallomExporter, type FallomExporterOptions, type InitOptions, type PromptResult, clearMastraPrompt, _default as default, init, models, prompts, setMastraPrompt, setMastraPromptAB, trace };
|
|
586
|
+
export { FallomExporter, type FallomExporterOptions, FallomSession, type InitOptions, type PromptResult, type SessionContext, type SessionOptions, clearMastraPrompt, _default as default, init, models, prompts, session, setMastraPrompt, setMastraPromptAB, trace };
|