@fallom/trace 0.1.10 → 0.1.12
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/dist/index.d.mts +146 -3
- package/dist/index.d.ts +146 -3
- package/dist/index.js +573 -66
- package/dist/index.mjs +569 -66
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { ExportResult } from '@opentelemetry/core';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Fallom tracing module.
|
|
3
6
|
*
|
|
@@ -211,17 +214,50 @@ declare function wrapGoogleAI<T extends {
|
|
|
211
214
|
* }); // Automatically traced!
|
|
212
215
|
* ```
|
|
213
216
|
*/
|
|
217
|
+
/** Options for wrapAISDK */
|
|
218
|
+
interface WrapAISDKOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Enable debug logging to see the raw Vercel AI SDK response structure.
|
|
221
|
+
* Useful for debugging missing usage/token data.
|
|
222
|
+
*/
|
|
223
|
+
debug?: boolean;
|
|
224
|
+
}
|
|
214
225
|
declare function wrapAISDK<T extends {
|
|
215
226
|
generateText: (...args: any[]) => Promise<any>;
|
|
216
227
|
streamText: (...args: any[]) => any;
|
|
217
228
|
generateObject?: (...args: any[]) => Promise<any>;
|
|
218
229
|
streamObject?: (...args: any[]) => any;
|
|
219
|
-
}>(ai: T): {
|
|
230
|
+
}>(ai: T, options?: WrapAISDKOptions): {
|
|
220
231
|
generateText: T["generateText"];
|
|
221
232
|
streamText: T["streamText"];
|
|
222
233
|
generateObject: T["generateObject"];
|
|
223
234
|
streamObject: T["streamObject"];
|
|
224
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* Wrap a Mastra agent to automatically trace all generate() calls.
|
|
238
|
+
*
|
|
239
|
+
* @param agent - The Mastra Agent instance
|
|
240
|
+
* @returns The same agent with tracing enabled
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* import { trace } from "@fallom/trace";
|
|
245
|
+
* import { Agent } from "@mastra/core";
|
|
246
|
+
*
|
|
247
|
+
* await trace.init({ apiKey: "your-key" });
|
|
248
|
+
*
|
|
249
|
+
* const agent = new Agent({ ... });
|
|
250
|
+
* const tracedAgent = trace.wrapMastraAgent(agent);
|
|
251
|
+
*
|
|
252
|
+
* trace.setSession("my-app", "session-123", "user-456");
|
|
253
|
+
* const result = await tracedAgent.generate([{ role: "user", content: "Hello" }]);
|
|
254
|
+
* // ^ Automatically traced!
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function wrapMastraAgent<T extends {
|
|
258
|
+
generate: (...args: any[]) => Promise<any>;
|
|
259
|
+
name?: string;
|
|
260
|
+
}>(agent: T): T;
|
|
225
261
|
|
|
226
262
|
declare const trace_clearSession: typeof clearSession;
|
|
227
263
|
declare const trace_getSession: typeof getSession;
|
|
@@ -232,9 +268,10 @@ declare const trace_span: typeof span;
|
|
|
232
268
|
declare const trace_wrapAISDK: typeof wrapAISDK;
|
|
233
269
|
declare const trace_wrapAnthropic: typeof wrapAnthropic;
|
|
234
270
|
declare const trace_wrapGoogleAI: typeof wrapGoogleAI;
|
|
271
|
+
declare const trace_wrapMastraAgent: typeof wrapMastraAgent;
|
|
235
272
|
declare const trace_wrapOpenAI: typeof wrapOpenAI;
|
|
236
273
|
declare namespace trace {
|
|
237
|
-
export { trace_clearSession as clearSession, trace_getSession as getSession, init$3 as init, trace_runWithSession as runWithSession, trace_setSession as setSession, trace_shutdown as shutdown, trace_span as span, trace_wrapAISDK as wrapAISDK, trace_wrapAnthropic as wrapAnthropic, trace_wrapGoogleAI as wrapGoogleAI, trace_wrapOpenAI as wrapOpenAI };
|
|
274
|
+
export { trace_clearSession as clearSession, trace_getSession as getSession, init$3 as init, trace_runWithSession as runWithSession, trace_setSession as setSession, trace_shutdown as shutdown, trace_span as span, trace_wrapAISDK as wrapAISDK, trace_wrapAnthropic as wrapAnthropic, trace_wrapGoogleAI as wrapGoogleAI, trace_wrapMastraAgent as wrapMastraAgent, trace_wrapOpenAI as wrapOpenAI };
|
|
238
275
|
}
|
|
239
276
|
|
|
240
277
|
/**
|
|
@@ -444,6 +481,112 @@ interface InitOptions {
|
|
|
444
481
|
*/
|
|
445
482
|
declare function init(options?: InitOptions): Promise<void>;
|
|
446
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Fallom Exporter for Mastra
|
|
486
|
+
*
|
|
487
|
+
* Custom OpenTelemetry exporter that sends traces from Mastra agents to Fallom.
|
|
488
|
+
* Reads session context from the shared trace module (set via trace.setSession()).
|
|
489
|
+
*
|
|
490
|
+
* Usage with Mastra:
|
|
491
|
+
* ```typescript
|
|
492
|
+
* import { trace, FallomExporter } from "@fallom/trace";
|
|
493
|
+
* import { Mastra } from "@mastra/core/mastra";
|
|
494
|
+
*
|
|
495
|
+
* // Initialize trace module
|
|
496
|
+
* await trace.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
497
|
+
*
|
|
498
|
+
* // Create Mastra with Fallom exporter
|
|
499
|
+
* const mastra = new Mastra({
|
|
500
|
+
* agents: { myAgent },
|
|
501
|
+
* telemetry: {
|
|
502
|
+
* serviceName: "my-agent",
|
|
503
|
+
* enabled: true,
|
|
504
|
+
* export: {
|
|
505
|
+
* type: "custom",
|
|
506
|
+
* exporter: new FallomExporter(),
|
|
507
|
+
* },
|
|
508
|
+
* },
|
|
509
|
+
* });
|
|
510
|
+
*
|
|
511
|
+
* // In your request handler:
|
|
512
|
+
* trace.setSession("my-app", "session-123", "user-456");
|
|
513
|
+
* const result = await mastra.getAgent("myAgent").generate("Hello!");
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
interface FallomExporterOptions {
|
|
518
|
+
/** Fallom API key. Defaults to FALLOM_API_KEY env var. */
|
|
519
|
+
apiKey?: string;
|
|
520
|
+
/** Base URL for traces endpoint (defaults to https://traces.fallom.com) */
|
|
521
|
+
baseUrl?: string;
|
|
522
|
+
/** Enable debug logging */
|
|
523
|
+
debug?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Set prompt tracking info.
|
|
527
|
+
* Call this after prompts.get() to track which prompt was used.
|
|
528
|
+
*/
|
|
529
|
+
declare function setMastraPrompt(promptKey: string, version?: number): void;
|
|
530
|
+
/**
|
|
531
|
+
* Set A/B test prompt tracking info.
|
|
532
|
+
* Call this after prompts.getAB() to track which variant was used.
|
|
533
|
+
*/
|
|
534
|
+
declare function setMastraPromptAB(abTestKey: string, variantIndex: number): void;
|
|
535
|
+
/**
|
|
536
|
+
* Clear prompt tracking info.
|
|
537
|
+
*/
|
|
538
|
+
declare function clearMastraPrompt(): void;
|
|
539
|
+
/**
|
|
540
|
+
* OpenTelemetry SpanExporter that sends traces to Fallom.
|
|
541
|
+
*
|
|
542
|
+
* Reads session context from trace.setSession() automatically.
|
|
543
|
+
* Compatible with Mastra's custom exporter interface.
|
|
544
|
+
*/
|
|
545
|
+
declare class FallomExporter implements SpanExporter {
|
|
546
|
+
private apiKey;
|
|
547
|
+
private baseUrl;
|
|
548
|
+
private debug;
|
|
549
|
+
private pendingExports;
|
|
550
|
+
constructor(options?: FallomExporterOptions);
|
|
551
|
+
private log;
|
|
552
|
+
/**
|
|
553
|
+
* Export spans to Fallom.
|
|
554
|
+
*/
|
|
555
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
556
|
+
/**
|
|
557
|
+
* Shutdown the exporter, waiting for pending exports.
|
|
558
|
+
*/
|
|
559
|
+
shutdown(): Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* Force flush pending exports.
|
|
562
|
+
*/
|
|
563
|
+
forceFlush(): Promise<void>;
|
|
564
|
+
/**
|
|
565
|
+
* Send spans to Fallom's OTLP endpoint.
|
|
566
|
+
*/
|
|
567
|
+
private sendSpans;
|
|
568
|
+
/**
|
|
569
|
+
* Convert OpenTelemetry spans to OTLP JSON format.
|
|
570
|
+
*/
|
|
571
|
+
private spansToOtlpJson;
|
|
572
|
+
/**
|
|
573
|
+
* Convert a single span to OTLP format.
|
|
574
|
+
*/
|
|
575
|
+
private spanToOtlp;
|
|
576
|
+
/**
|
|
577
|
+
* Convert attributes to OTLP format.
|
|
578
|
+
*/
|
|
579
|
+
private attributesToOtlp;
|
|
580
|
+
/**
|
|
581
|
+
* Convert a value to OTLP AnyValue format.
|
|
582
|
+
*/
|
|
583
|
+
private valueToOtlp;
|
|
584
|
+
/**
|
|
585
|
+
* Convert HrTime to nanoseconds string.
|
|
586
|
+
*/
|
|
587
|
+
private hrTimeToNanos;
|
|
588
|
+
}
|
|
589
|
+
|
|
447
590
|
/**
|
|
448
591
|
* Fallom - Model A/B testing, prompt management, and tracing for LLM applications.
|
|
449
592
|
*
|
|
@@ -488,4 +631,4 @@ declare const _default: {
|
|
|
488
631
|
prompts: typeof prompts;
|
|
489
632
|
};
|
|
490
633
|
|
|
491
|
-
export { type InitOptions, type PromptResult, _default as default, init, models, prompts, trace };
|
|
634
|
+
export { FallomExporter, type FallomExporterOptions, type InitOptions, type PromptResult, clearMastraPrompt, _default as default, init, models, prompts, setMastraPrompt, setMastraPromptAB, trace };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { ExportResult } from '@opentelemetry/core';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Fallom tracing module.
|
|
3
6
|
*
|
|
@@ -211,17 +214,50 @@ declare function wrapGoogleAI<T extends {
|
|
|
211
214
|
* }); // Automatically traced!
|
|
212
215
|
* ```
|
|
213
216
|
*/
|
|
217
|
+
/** Options for wrapAISDK */
|
|
218
|
+
interface WrapAISDKOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Enable debug logging to see the raw Vercel AI SDK response structure.
|
|
221
|
+
* Useful for debugging missing usage/token data.
|
|
222
|
+
*/
|
|
223
|
+
debug?: boolean;
|
|
224
|
+
}
|
|
214
225
|
declare function wrapAISDK<T extends {
|
|
215
226
|
generateText: (...args: any[]) => Promise<any>;
|
|
216
227
|
streamText: (...args: any[]) => any;
|
|
217
228
|
generateObject?: (...args: any[]) => Promise<any>;
|
|
218
229
|
streamObject?: (...args: any[]) => any;
|
|
219
|
-
}>(ai: T): {
|
|
230
|
+
}>(ai: T, options?: WrapAISDKOptions): {
|
|
220
231
|
generateText: T["generateText"];
|
|
221
232
|
streamText: T["streamText"];
|
|
222
233
|
generateObject: T["generateObject"];
|
|
223
234
|
streamObject: T["streamObject"];
|
|
224
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* Wrap a Mastra agent to automatically trace all generate() calls.
|
|
238
|
+
*
|
|
239
|
+
* @param agent - The Mastra Agent instance
|
|
240
|
+
* @returns The same agent with tracing enabled
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* import { trace } from "@fallom/trace";
|
|
245
|
+
* import { Agent } from "@mastra/core";
|
|
246
|
+
*
|
|
247
|
+
* await trace.init({ apiKey: "your-key" });
|
|
248
|
+
*
|
|
249
|
+
* const agent = new Agent({ ... });
|
|
250
|
+
* const tracedAgent = trace.wrapMastraAgent(agent);
|
|
251
|
+
*
|
|
252
|
+
* trace.setSession("my-app", "session-123", "user-456");
|
|
253
|
+
* const result = await tracedAgent.generate([{ role: "user", content: "Hello" }]);
|
|
254
|
+
* // ^ Automatically traced!
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function wrapMastraAgent<T extends {
|
|
258
|
+
generate: (...args: any[]) => Promise<any>;
|
|
259
|
+
name?: string;
|
|
260
|
+
}>(agent: T): T;
|
|
225
261
|
|
|
226
262
|
declare const trace_clearSession: typeof clearSession;
|
|
227
263
|
declare const trace_getSession: typeof getSession;
|
|
@@ -232,9 +268,10 @@ declare const trace_span: typeof span;
|
|
|
232
268
|
declare const trace_wrapAISDK: typeof wrapAISDK;
|
|
233
269
|
declare const trace_wrapAnthropic: typeof wrapAnthropic;
|
|
234
270
|
declare const trace_wrapGoogleAI: typeof wrapGoogleAI;
|
|
271
|
+
declare const trace_wrapMastraAgent: typeof wrapMastraAgent;
|
|
235
272
|
declare const trace_wrapOpenAI: typeof wrapOpenAI;
|
|
236
273
|
declare namespace trace {
|
|
237
|
-
export { trace_clearSession as clearSession, trace_getSession as getSession, init$3 as init, trace_runWithSession as runWithSession, trace_setSession as setSession, trace_shutdown as shutdown, trace_span as span, trace_wrapAISDK as wrapAISDK, trace_wrapAnthropic as wrapAnthropic, trace_wrapGoogleAI as wrapGoogleAI, trace_wrapOpenAI as wrapOpenAI };
|
|
274
|
+
export { trace_clearSession as clearSession, trace_getSession as getSession, init$3 as init, trace_runWithSession as runWithSession, trace_setSession as setSession, trace_shutdown as shutdown, trace_span as span, trace_wrapAISDK as wrapAISDK, trace_wrapAnthropic as wrapAnthropic, trace_wrapGoogleAI as wrapGoogleAI, trace_wrapMastraAgent as wrapMastraAgent, trace_wrapOpenAI as wrapOpenAI };
|
|
238
275
|
}
|
|
239
276
|
|
|
240
277
|
/**
|
|
@@ -444,6 +481,112 @@ interface InitOptions {
|
|
|
444
481
|
*/
|
|
445
482
|
declare function init(options?: InitOptions): Promise<void>;
|
|
446
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Fallom Exporter for Mastra
|
|
486
|
+
*
|
|
487
|
+
* Custom OpenTelemetry exporter that sends traces from Mastra agents to Fallom.
|
|
488
|
+
* Reads session context from the shared trace module (set via trace.setSession()).
|
|
489
|
+
*
|
|
490
|
+
* Usage with Mastra:
|
|
491
|
+
* ```typescript
|
|
492
|
+
* import { trace, FallomExporter } from "@fallom/trace";
|
|
493
|
+
* import { Mastra } from "@mastra/core/mastra";
|
|
494
|
+
*
|
|
495
|
+
* // Initialize trace module
|
|
496
|
+
* await trace.init({ apiKey: process.env.FALLOM_API_KEY });
|
|
497
|
+
*
|
|
498
|
+
* // Create Mastra with Fallom exporter
|
|
499
|
+
* const mastra = new Mastra({
|
|
500
|
+
* agents: { myAgent },
|
|
501
|
+
* telemetry: {
|
|
502
|
+
* serviceName: "my-agent",
|
|
503
|
+
* enabled: true,
|
|
504
|
+
* export: {
|
|
505
|
+
* type: "custom",
|
|
506
|
+
* exporter: new FallomExporter(),
|
|
507
|
+
* },
|
|
508
|
+
* },
|
|
509
|
+
* });
|
|
510
|
+
*
|
|
511
|
+
* // In your request handler:
|
|
512
|
+
* trace.setSession("my-app", "session-123", "user-456");
|
|
513
|
+
* const result = await mastra.getAgent("myAgent").generate("Hello!");
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
interface FallomExporterOptions {
|
|
518
|
+
/** Fallom API key. Defaults to FALLOM_API_KEY env var. */
|
|
519
|
+
apiKey?: string;
|
|
520
|
+
/** Base URL for traces endpoint (defaults to https://traces.fallom.com) */
|
|
521
|
+
baseUrl?: string;
|
|
522
|
+
/** Enable debug logging */
|
|
523
|
+
debug?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Set prompt tracking info.
|
|
527
|
+
* Call this after prompts.get() to track which prompt was used.
|
|
528
|
+
*/
|
|
529
|
+
declare function setMastraPrompt(promptKey: string, version?: number): void;
|
|
530
|
+
/**
|
|
531
|
+
* Set A/B test prompt tracking info.
|
|
532
|
+
* Call this after prompts.getAB() to track which variant was used.
|
|
533
|
+
*/
|
|
534
|
+
declare function setMastraPromptAB(abTestKey: string, variantIndex: number): void;
|
|
535
|
+
/**
|
|
536
|
+
* Clear prompt tracking info.
|
|
537
|
+
*/
|
|
538
|
+
declare function clearMastraPrompt(): void;
|
|
539
|
+
/**
|
|
540
|
+
* OpenTelemetry SpanExporter that sends traces to Fallom.
|
|
541
|
+
*
|
|
542
|
+
* Reads session context from trace.setSession() automatically.
|
|
543
|
+
* Compatible with Mastra's custom exporter interface.
|
|
544
|
+
*/
|
|
545
|
+
declare class FallomExporter implements SpanExporter {
|
|
546
|
+
private apiKey;
|
|
547
|
+
private baseUrl;
|
|
548
|
+
private debug;
|
|
549
|
+
private pendingExports;
|
|
550
|
+
constructor(options?: FallomExporterOptions);
|
|
551
|
+
private log;
|
|
552
|
+
/**
|
|
553
|
+
* Export spans to Fallom.
|
|
554
|
+
*/
|
|
555
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
556
|
+
/**
|
|
557
|
+
* Shutdown the exporter, waiting for pending exports.
|
|
558
|
+
*/
|
|
559
|
+
shutdown(): Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* Force flush pending exports.
|
|
562
|
+
*/
|
|
563
|
+
forceFlush(): Promise<void>;
|
|
564
|
+
/**
|
|
565
|
+
* Send spans to Fallom's OTLP endpoint.
|
|
566
|
+
*/
|
|
567
|
+
private sendSpans;
|
|
568
|
+
/**
|
|
569
|
+
* Convert OpenTelemetry spans to OTLP JSON format.
|
|
570
|
+
*/
|
|
571
|
+
private spansToOtlpJson;
|
|
572
|
+
/**
|
|
573
|
+
* Convert a single span to OTLP format.
|
|
574
|
+
*/
|
|
575
|
+
private spanToOtlp;
|
|
576
|
+
/**
|
|
577
|
+
* Convert attributes to OTLP format.
|
|
578
|
+
*/
|
|
579
|
+
private attributesToOtlp;
|
|
580
|
+
/**
|
|
581
|
+
* Convert a value to OTLP AnyValue format.
|
|
582
|
+
*/
|
|
583
|
+
private valueToOtlp;
|
|
584
|
+
/**
|
|
585
|
+
* Convert HrTime to nanoseconds string.
|
|
586
|
+
*/
|
|
587
|
+
private hrTimeToNanos;
|
|
588
|
+
}
|
|
589
|
+
|
|
447
590
|
/**
|
|
448
591
|
* Fallom - Model A/B testing, prompt management, and tracing for LLM applications.
|
|
449
592
|
*
|
|
@@ -488,4 +631,4 @@ declare const _default: {
|
|
|
488
631
|
prompts: typeof prompts;
|
|
489
632
|
};
|
|
490
633
|
|
|
491
|
-
export { type InitOptions, type PromptResult, _default as default, init, models, prompts, trace };
|
|
634
|
+
export { FallomExporter, type FallomExporterOptions, type InitOptions, type PromptResult, clearMastraPrompt, _default as default, init, models, prompts, setMastraPrompt, setMastraPromptAB, trace };
|