@mastra/langfuse 1.0.0-beta.8 → 1.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/CHANGELOG.md +294 -0
- package/README.md +48 -6
- package/dist/index.cjs +102 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -192
- package/dist/index.js.map +1 -1
- package/dist/metrics.d.ts +17 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/tracing.d.ts +59 -32
- package/dist/tracing.d.ts.map +1 -1
- package/package.json +8 -7
package/dist/tracing.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* Root spans start traces in Langfuse.
|
|
6
6
|
* MODEL_GENERATION spans become Langfuse generations, all others become spans.
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
|
|
8
|
+
import type { AnyExportedSpan, SpanErrorInfo } from '@mastra/core/observability';
|
|
9
|
+
import { TrackingExporter } from '@mastra/observability';
|
|
10
|
+
import type { TrackingExporterConfig, TraceData } from '@mastra/observability';
|
|
11
|
+
import type { LangfuseTraceClient, LangfuseSpanClient, LangfuseGenerationClient, LangfuseEventClient } from 'langfuse';
|
|
12
|
+
export interface LangfuseExporterConfig extends TrackingExporterConfig {
|
|
12
13
|
/** Langfuse API key */
|
|
13
14
|
publicKey?: string;
|
|
14
15
|
/** Langfuse secret key */
|
|
@@ -20,41 +21,62 @@ export interface LangfuseExporterConfig extends BaseExporterConfig {
|
|
|
20
21
|
/** Additional options to pass to the Langfuse client */
|
|
21
22
|
options?: any;
|
|
22
23
|
}
|
|
24
|
+
type LangfusePromptData = {
|
|
25
|
+
name?: string;
|
|
26
|
+
version?: number;
|
|
27
|
+
id?: string;
|
|
28
|
+
};
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
30
|
+
* With Langfuse, data from the root span is stored in both the Root and the
|
|
31
|
+
* first span.
|
|
25
32
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Formats UsageStats to Langfuse's expected format.
|
|
36
|
-
*/
|
|
37
|
-
export declare function formatUsageMetrics(usage?: UsageStats): LangfuseUsageMetrics;
|
|
38
|
-
export declare class LangfuseExporter extends BaseExporter {
|
|
33
|
+
type LangfuseRoot = LangfuseTraceClient;
|
|
34
|
+
type LangfuseSpan = LangfuseSpanClient | LangfuseGenerationClient;
|
|
35
|
+
type LangfuseEvent = LangfuseEventClient;
|
|
36
|
+
type LangfuseMetadata = {
|
|
37
|
+
prompt?: LangfusePromptData;
|
|
38
|
+
};
|
|
39
|
+
type LangfuseTraceData = TraceData<LangfuseRoot, LangfuseSpan, LangfuseEvent, LangfuseMetadata>;
|
|
40
|
+
export declare class LangfuseExporter extends TrackingExporter<LangfuseRoot, LangfuseSpan, LangfuseEvent, LangfuseMetadata, LangfuseExporterConfig> {
|
|
41
|
+
#private;
|
|
39
42
|
name: string;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
constructor(config?: LangfuseExporterConfig);
|
|
44
|
+
protected _postExportTracingEvent(): Promise<void>;
|
|
45
|
+
protected _buildRoot(args: {
|
|
46
|
+
span: AnyExportedSpan;
|
|
47
|
+
traceData: LangfuseTraceData;
|
|
48
|
+
}): Promise<LangfuseTraceClient | undefined>;
|
|
49
|
+
protected _buildEvent(args: {
|
|
50
|
+
span: AnyExportedSpan;
|
|
51
|
+
traceData: LangfuseTraceData;
|
|
52
|
+
}): Promise<LangfuseEvent | undefined>;
|
|
53
|
+
protected _buildSpan(args: {
|
|
54
|
+
span: AnyExportedSpan;
|
|
55
|
+
traceData: LangfuseTraceData;
|
|
56
|
+
}): Promise<LangfuseSpan | undefined>;
|
|
57
|
+
protected _updateSpan(args: {
|
|
58
|
+
span: AnyExportedSpan;
|
|
59
|
+
traceData: LangfuseTraceData;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
protected _finishSpan(args: {
|
|
62
|
+
span: AnyExportedSpan;
|
|
63
|
+
traceData: LangfuseTraceData;
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
protected _abortSpan(args: {
|
|
66
|
+
span: LangfuseSpan;
|
|
67
|
+
reason: SpanErrorInfo;
|
|
68
|
+
}): Promise<void>;
|
|
51
69
|
private buildTracePayload;
|
|
52
70
|
/**
|
|
53
|
-
* Look up the Langfuse prompt from the closest
|
|
71
|
+
* Look up the Langfuse prompt from the closest span that has one.
|
|
54
72
|
* This enables prompt inheritance for MODEL_GENERATION spans when the prompt
|
|
55
73
|
* is set on a parent span (e.g., AGENT_RUN) rather than directly on the generation.
|
|
74
|
+
* This enables prompt linking when:
|
|
75
|
+
* - A workflow calls multiple agents, each with different prompts
|
|
76
|
+
* - Nested agents have different prompts
|
|
77
|
+
* - The prompt is set on AGENT_RUN but MODEL_GENERATION inherits it
|
|
56
78
|
*/
|
|
57
|
-
private
|
|
79
|
+
private findLangfusePrompt;
|
|
58
80
|
private buildSpanPayload;
|
|
59
81
|
addScoreToTrace({ traceId, spanId, score, reason, scorerName, metadata, }: {
|
|
60
82
|
traceId: string;
|
|
@@ -64,6 +86,11 @@ export declare class LangfuseExporter extends BaseExporter {
|
|
|
64
86
|
scorerName: string;
|
|
65
87
|
metadata?: Record<string, any>;
|
|
66
88
|
}): Promise<void>;
|
|
67
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Force flush any buffered data to Langfuse without shutting down.
|
|
91
|
+
*/
|
|
92
|
+
protected _flush(): Promise<void>;
|
|
93
|
+
_postShutdown(): Promise<void>;
|
|
68
94
|
}
|
|
95
|
+
export {};
|
|
69
96
|
//# sourceMappingURL=tracing.d.ts.map
|
package/dist/tracing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAA6B,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGvH,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB;IACpE,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,KAAK,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E;;;GAGG;AAEH,KAAK,YAAY,GAAG,mBAAmB,CAAC;AACxC,KAAK,YAAY,GAAG,kBAAkB,GAAG,wBAAwB,CAAC;AAClE,KAAK,aAAa,GAAG,mBAAmB,CAAC;AACzC,KAAK,gBAAgB,GAAG;IAAE,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC;AACxD,KAAK,iBAAiB,GAAG,SAAS,CAAC,Y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K,EACL,MAAM,EACN,UAAU,EACV,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBjB;;OAEG;cACsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/langfuse",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Langfuse observability provider for Mastra - includes tracing and future observability features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"langfuse": "^3.38.6",
|
|
28
|
-
"@mastra/observability": "1.0.0
|
|
28
|
+
"@mastra/observability": "1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "22.13.17",
|
|
@@ -33,11 +33,12 @@
|
|
|
33
33
|
"@vitest/ui": "4.0.12",
|
|
34
34
|
"eslint": "^9.37.0",
|
|
35
35
|
"tsup": "^8.5.0",
|
|
36
|
-
"typescript": "^5.
|
|
37
|
-
"vitest": "4.0.
|
|
38
|
-
"@internal/
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "4.0.16",
|
|
38
|
+
"@internal/types-builder": "0.0.29",
|
|
39
|
+
"@internal/lint": "0.0.54",
|
|
40
|
+
"@observability/test-utils": "0.0.1",
|
|
41
|
+
"@mastra/core": "1.0.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|