@mastra/langfuse 1.3.5-alpha.0 → 1.3.5
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 +43 -0
- package/dist/index.cjs +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @mastra/langfuse
|
|
2
2
|
|
|
3
|
+
## 1.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added support for custom top-level trace metadata in the Langfuse exporter. Any keys you set under `metadata.langfuse` (other than the reserved `prompt` key) are now forwarded as top-level Langfuse trace metadata, so you can filter and group traces by them. Nested values are serialized with JSON. ([#17689](https://github.com/mastra-ai/mastra/pull/17689))
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const tracingOptions = {
|
|
11
|
+
metadata: {
|
|
12
|
+
langfuse: {
|
|
13
|
+
customerId: 'cust_123',
|
|
14
|
+
tier: 'enterprise',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
// produces langfuse.trace.metadata.customerId and langfuse.trace.metadata.tier
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`151f90e`](https://github.com/mastra-ai/mastra/commit/151f90efa07649e3dd1b4632a46a43f67363728c), [`d468acb`](https://github.com/mastra-ai/mastra/commit/d468acb07aec1bb19a2cb0ada8042b05b46746b2), [`575f815`](https://github.com/mastra-ai/mastra/commit/575f815c5c3567b71c0b83cbb7fa98c8253a9d9c), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`053735a`](https://github.com/mastra-ai/mastra/commit/053735a75c2c18e23ce34d9468007efa4a45f4c4), [`306909a`](https://github.com/mastra-ai/mastra/commit/306909a693de77d709b38706e2673c9547d24a28), [`5191af8`](https://github.com/mastra-ai/mastra/commit/5191af80c799eea25357c545fc05d91b3883531d), [`43bd3d4`](https://github.com/mastra-ai/mastra/commit/43bd3d421987463fdf35386a45199c49499ed069), [`e6fa79e`](https://github.com/mastra-ai/mastra/commit/e6fa79ec72a2ddffdd25e85270398951e9d552a4), [`904bcdf`](https://github.com/mastra-ai/mastra/commit/904bcdf7b8004aa7be823f9f70ca63580e47e470), [`7f5ee1d`](https://github.com/mastra-ai/mastra/commit/7f5ee1dca46daee8d2817f2ebe49e6335da81956), [`1e9aab5`](https://github.com/mastra-ai/mastra/commit/1e9aab50ff11e6e88fde4d7cbf512c44a9fe8d61), [`2bccba4`](https://github.com/mastra-ai/mastra/commit/2bccba4c03cadc815c2d54cbf4dd43a922140a8d), [`bf8eb6d`](https://github.com/mastra-ai/mastra/commit/bf8eb6d0ec213a403eb9265a594ad283c44ab3dc), [`e9be4e7`](https://github.com/mastra-ai/mastra/commit/e9be4e747ec3d8b65548bff92f9377db06105376), [`493a328`](https://github.com/mastra-ai/mastra/commit/493a328f4346a1deeb9f1e2e44c8f2a3a4d7591b), [`d53cfc2`](https://github.com/mastra-ai/mastra/commit/d53cfc2c7f8d78343a4aa84ec4e129ba25f3325e), [`65799d4`](https://github.com/mastra-ai/mastra/commit/65799d4d549e5ebb9c848fbe3f51ac090f64becf), [`c268c89`](https://github.com/mastra-ai/mastra/commit/c268c89f4c63a93ee474d3cffdf3ea60bf00d4f2), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`014e00f`](https://github.com/mastra-ai/mastra/commit/014e00f2b3a597a016b72f9901c6ab27d491f822), [`029a414`](https://github.com/mastra-ai/mastra/commit/029a4141719793bd3e898a39eb5a0466a55f5f3a), [`d468acb`](https://github.com/mastra-ai/mastra/commit/d468acb07aec1bb19a2cb0ada8042b05b46746b2), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`d371ac1`](https://github.com/mastra-ai/mastra/commit/d371ac1d9820afaaf7cfdbc380a475946a994d8f), [`2bccba4`](https://github.com/mastra-ai/mastra/commit/2bccba4c03cadc815c2d54cbf4dd43a922140a8d), [`0c72f03`](https://github.com/mastra-ai/mastra/commit/0c72f032abb13254df5a7856d64be2f207b8006d), [`cf182b7`](https://github.com/mastra-ai/mastra/commit/cf182b7fb495767946d9840ef29f19cfa906f31f), [`3b45ea9`](https://github.com/mastra-ai/mastra/commit/3b45ea95015557a6cb9d70dc5252af54ab1b78ac), [`a049c2a`](https://github.com/mastra-ai/mastra/commit/a049c2a9dfb41d0ee2e7a28874a88cd64fd5669f), [`f084be1`](https://github.com/mastra-ai/mastra/commit/f084be1fcbe33ad7480913e44d6130c421c0976f), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`2a96528`](https://github.com/mastra-ai/mastra/commit/2a9652848dfa3c5a2426f952e9d93554c26fd90f), [`f2ab060`](https://github.com/mastra-ai/mastra/commit/f2ab060162bea81505fda553e2cee29c1979fd04), [`5d302c8`](https://github.com/mastra-ai/mastra/commit/5d302c8eda1a6ac74eab5e442c4f64db6cc97a06), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`a952852`](https://github.com/mastra-ai/mastra/commit/a952852c971a21fb646cd907c75fcf4443cdc963), [`2656d9c`](https://github.com/mastra-ai/mastra/commit/2656d9c2976d4f3354253bfbbbf9b88a1b2bbf34), [`63e3fe1`](https://github.com/mastra-ai/mastra/commit/63e3fe13cc1ea96f91d7c68aea92f400faf9e4da), [`1d4ce8d`](https://github.com/mastra-ai/mastra/commit/1d4ce8daaa54511f325c1b609d31b8e54009d677), [`8c68372`](https://github.com/mastra-ai/mastra/commit/8c68372e85fe0b066ec12c58bd29ffb93e54c552)]:
|
|
22
|
+
- @mastra/otel-exporter@1.2.2
|
|
23
|
+
- @mastra/core@1.42.0
|
|
24
|
+
|
|
25
|
+
## 1.3.5-alpha.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Added support for custom top-level trace metadata in the Langfuse exporter. Any keys you set under `metadata.langfuse` (other than the reserved `prompt` key) are now forwarded as top-level Langfuse trace metadata, so you can filter and group traces by them. Nested values are serialized with JSON. ([#17689](https://github.com/mastra-ai/mastra/pull/17689))
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const tracingOptions = {
|
|
33
|
+
metadata: {
|
|
34
|
+
langfuse: {
|
|
35
|
+
customerId: 'cust_123',
|
|
36
|
+
tier: 'enterprise',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
// produces langfuse.trace.metadata.customerId and langfuse.trace.metadata.tier
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [[`575f815`](https://github.com/mastra-ai/mastra/commit/575f815c5c3567b71c0b83cbb7fa98c8253a9d9c), [`306909a`](https://github.com/mastra-ai/mastra/commit/306909a693de77d709b38706e2673c9547d24a28), [`5191af8`](https://github.com/mastra-ai/mastra/commit/5191af80c799eea25357c545fc05d91b3883531d), [`43bd3d4`](https://github.com/mastra-ai/mastra/commit/43bd3d421987463fdf35386a45199c49499ed069), [`e6fa79e`](https://github.com/mastra-ai/mastra/commit/e6fa79ec72a2ddffdd25e85270398951e9d552a4), [`904bcdf`](https://github.com/mastra-ai/mastra/commit/904bcdf7b8004aa7be823f9f70ca63580e47e470), [`7f5ee1d`](https://github.com/mastra-ai/mastra/commit/7f5ee1dca46daee8d2817f2ebe49e6335da81956), [`1e9aab5`](https://github.com/mastra-ai/mastra/commit/1e9aab50ff11e6e88fde4d7cbf512c44a9fe8d61), [`bf8eb6d`](https://github.com/mastra-ai/mastra/commit/bf8eb6d0ec213a403eb9265a594ad283c44ab3dc), [`493a328`](https://github.com/mastra-ai/mastra/commit/493a328f4346a1deeb9f1e2e44c8f2a3a4d7591b), [`029a414`](https://github.com/mastra-ai/mastra/commit/029a4141719793bd3e898a39eb5a0466a55f5f3a), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`d371ac1`](https://github.com/mastra-ai/mastra/commit/d371ac1d9820afaaf7cfdbc380a475946a994d8f), [`cf182b7`](https://github.com/mastra-ai/mastra/commit/cf182b7fb495767946d9840ef29f19cfa906f31f), [`a049c2a`](https://github.com/mastra-ai/mastra/commit/a049c2a9dfb41d0ee2e7a28874a88cd64fd5669f), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`2a96528`](https://github.com/mastra-ai/mastra/commit/2a9652848dfa3c5a2426f952e9d93554c26fd90f), [`2656d9c`](https://github.com/mastra-ai/mastra/commit/2656d9c2976d4f3354253bfbbbf9b88a1b2bbf34), [`63e3fe1`](https://github.com/mastra-ai/mastra/commit/63e3fe13cc1ea96f91d7c68aea92f400faf9e4da), [`1d4ce8d`](https://github.com/mastra-ai/mastra/commit/1d4ce8daaa54511f325c1b609d31b8e54009d677), [`8c68372`](https://github.com/mastra-ai/mastra/commit/8c68372e85fe0b066ec12c58bd29ffb93e54c552)]:
|
|
44
|
+
- @mastra/core@1.42.0-alpha.4
|
|
45
|
+
|
|
3
46
|
## 1.3.5-alpha.0
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -168,12 +168,23 @@ function mapMastraToLangfuseAttributes(attributes, span, environment, release) {
|
|
|
168
168
|
if (langfuseMetadata) {
|
|
169
169
|
try {
|
|
170
170
|
const parsed = typeof langfuseMetadata === "string" ? JSON.parse(langfuseMetadata) : langfuseMetadata;
|
|
171
|
-
if (parsed
|
|
172
|
-
if (parsed.prompt
|
|
173
|
-
|
|
171
|
+
if (parsed && typeof parsed === "object") {
|
|
172
|
+
if (parsed.prompt) {
|
|
173
|
+
if (parsed.prompt.name !== void 0) {
|
|
174
|
+
attributes["langfuse.observation.prompt.name"] = parsed.prompt.name;
|
|
175
|
+
}
|
|
176
|
+
if (parsed.prompt.version !== void 0) {
|
|
177
|
+
attributes["langfuse.observation.prompt.version"] = parsed.prompt.version;
|
|
178
|
+
}
|
|
174
179
|
}
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
181
|
+
if (key === "prompt" || value === null || value === void 0) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const traceKey = `langfuse.trace.metadata.${key}`;
|
|
185
|
+
if (attributes[traceKey] === void 0) {
|
|
186
|
+
attributes[traceKey] = typeof value === "string" ? value : JSON.stringify(value);
|
|
187
|
+
}
|
|
177
188
|
}
|
|
178
189
|
}
|
|
179
190
|
} catch {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tracing.ts","../src/helpers.ts"],"names":["BaseExporter","LangfuseSpanProcessor","LangfuseClient","SpanConverter","TracingEventType","SpanType"],"mappings":";;;;;;;;;AAiBA,IAAM,UAAA,GAAa,oBAAA;AAEZ,IAAM,yBAAA,GAA4B;AAqBlC,IAAM,gBAAA,GAAN,cAA+BA,0BAAA,CAAa;AAAA,EACjD,IAAA,GAAO,UAAA;AAAA,EACP,UAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,SAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EAEA,WAAA,CAAY,MAAA,GAAiC,EAAC,EAAG;AAC/C,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,mBAAA;AAClD,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,mBAAA;AAClD,IAAA,MAAM,UAAU,oBAAA,CAAqB,MAAA,CAAO,WAAW,OAAA,CAAQ,GAA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AW,SAAS,KAAK,GAAA,CAAI,QAAA,CAAS,SAAS,CAAA,EAAG;AACxD,QAAA,UAAA,CAAW,6BAA6B,CAAA,GAAI,UAAA,CAAW,GAAG,CAAA;AAC1D,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAOA,SAAS,qBAAqB,CAAA,EAAmB;AAC/C,EAAA,IAAI,MAAM,CAAA,CAAE,MAAA;AACZ,EAAA,OAAO,MAAM,CAAA,IAAK,CAAA,CAAE,WAAW,GAAA,GAAM,CAAC,MAAM,EAAA,EAAc;AACxD,IAAA,GAAA,EAAA;AAAA,EACF;AACA,EAAA,OAAO,QAAQ,CAAA,CAAE,MAAA,GAAS,IAAI,CAAA,CAAE,KAAA,CAAM,GAAG,GAAG,CAAA;AAC9C;;;ACrUO,SAAS,mBAAmB,MAAA,EAAoD;AACrF,EAAA,OAAO,CAAA,IAAA,MAAS;AAAA,IACd,GAAG,IAAA;AAAA,IACH,QAAA,EAAU;AAAA,MACR,GAAG,IAAA,CAAK,QAAA;AAAA,MACR,QAAA,EAAU;AAAA,QACR,GAAI,KAAK,QAAA,EAAU,QAAA;AAAA,QACnB,MAAA,EAAQ;AAAA,UACN,GAAI,MAAA,CAAO,IAAA,KAAS,UAAa,EAAE,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,UACrD,GAAI,MAAA,CAAO,OAAA,KAAY,UAAa,EAAE,OAAA,EAAS,OAAO,OAAA,EAAQ;AAAA,UAC9D,GAAI,MAAA,CAAO,EAAA,KAAO,UAAa,EAAE,EAAA,EAAI,OAAO,EAAA;AAAG;AACjD;AACF;AACF,GACF,CAAA;AACF","file":"index.cjs","sourcesContent":["/**\n * Langfuse Exporter for Mastra Observability\n *\n * Sends observability data to Langfuse using the official @langfuse/otel span processor\n * and @langfuse/client for non-tracing features (scoring, prompt management, evaluations).\n *\n * @see https://langfuse.com/docs/observability/sdk/typescript/overview\n */\n\nimport { LangfuseClient } from '@langfuse/client';\nimport { LangfuseSpanProcessor } from '@langfuse/otel';\nimport type { TracingEvent, AnyExportedSpan, InitExporterOptions, ScoreEvent } from '@mastra/core/observability';\nimport { SpanType, TracingEventType } from '@mastra/core/observability';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { SpanConverter } from '@mastra/otel-exporter';\n\nconst LOG_PREFIX = '[LangfuseExporter]';\n\nexport const LANGFUSE_DEFAULT_BASE_URL = 'https://cloud.langfuse.com';\n\nexport interface LangfuseExporterConfig extends BaseExporterConfig {\n /** Langfuse public key */\n publicKey?: string;\n /** Langfuse secret key */\n secretKey?: string;\n /** Langfuse host URL (defaults to https://cloud.langfuse.com) */\n baseUrl?: string;\n /** Enable realtime mode - flushes after each event for immediate visibility */\n realtime?: boolean;\n /** Maximum number of spans per OTEL export batch */\n flushAt?: number;\n /** Maximum time in seconds before pending spans are exported */\n flushInterval?: number;\n /** Langfuse environment tag for traces */\n environment?: string;\n /** Langfuse release tag for traces */\n release?: string;\n}\n\nexport class LangfuseExporter extends BaseExporter {\n name = 'langfuse';\n #processor: LangfuseSpanProcessor | undefined;\n #client: LangfuseClient | undefined;\n #spanConverter: SpanConverter | undefined;\n #realtime: boolean;\n #environment: string | undefined;\n #release: string | undefined;\n\n constructor(config: LangfuseExporterConfig = {}) {\n super(config);\n\n const publicKey = config.publicKey ?? process.env.LANGFUSE_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.LANGFUSE_SECRET_KEY;\n const baseUrl = stripTrailingSlashes(config.baseUrl ?? process.env.LANGFUSE_BASE_URL ?? LANGFUSE_DEFAULT_BASE_URL);\n this.#realtime = config.realtime ?? false;\n\n if (!publicKey || !secretKey) {\n const publicKeySource = config.publicKey\n ? 'from config'\n : process.env.LANGFUSE_PUBLIC_KEY\n ? 'from env'\n : 'missing';\n const secretKeySource = config.secretKey\n ? 'from config'\n : process.env.LANGFUSE_SECRET_KEY\n ? 'from env'\n : 'missing';\n this.setDisabled(\n `${LOG_PREFIX} Missing required credentials (publicKey: ${publicKeySource}, secretKey: ${secretKeySource}). ` +\n `Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY environment variables or pass them in config.`,\n );\n return;\n }\n\n this.#processor = new LangfuseSpanProcessor({\n publicKey,\n secretKey,\n baseUrl,\n environment: config.environment,\n release: config.release,\n exportMode: this.#realtime ? 'immediate' : 'batched',\n flushAt: config.flushAt,\n flushInterval: config.flushInterval,\n // Export all spans — the default filter only passes spans with gen_ai.* attributes\n // or known LLM instrumentation scopes, but Mastra spans use mastra.* attributes.\n shouldExportSpan: () => true,\n });\n\n this.#client = new LangfuseClient({\n publicKey,\n secretKey,\n baseUrl,\n });\n\n this.#environment = config.environment ?? process.env.LANGFUSE_TRACING_ENVIRONMENT;\n this.#release = config.release ?? process.env.LANGFUSE_RELEASE;\n }\n\n init(options: InitExporterOptions) {\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: options.config?.serviceName,\n format: 'GenAI_v1_38_0',\n });\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.type !== TracingEventType.SPAN_ENDED) return;\n if (!this.#processor) return;\n\n await this.exportSpan(event.exportedSpan);\n }\n\n private async exportSpan(span: AnyExportedSpan): Promise<void> {\n if (!this.#spanConverter) {\n // Fallback if init() was not called (e.g., standalone usage without Mastra)\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: 'mastra-service',\n format: 'GenAI_v1_38_0',\n });\n }\n\n try {\n const otelSpan = await this.#spanConverter.convertSpan(span);\n\n // Map mastra.* attributes to langfuse.* namespace so that Langfuse's OTLP\n // endpoint reads them correctly. SpanConverter produces mastra.* attributes,\n // but Langfuse only reads langfuse.* attributes for prompt linking, TTFT, etc.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n mapMastraToLangfuseAttributes(otelSpan.attributes, span, this.#environment, this.#release);\n\n this.#processor!.onEnd(otelSpan);\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Failed to export span ${span.id}:`, error);\n }\n }\n\n /**\n * The LangfuseClient instance for advanced Langfuse features.\n * Use this for prompt management, evaluations, datasets, and direct API access.\n */\n get client(): LangfuseClient | undefined {\n return this.#client;\n }\n\n /**\n * Submit a score to Langfuse. Used by both the new `onScoreEvent` path and the\n * deprecated `addScoreToTrace` wrapper.\n */\n private submitScore(args: {\n id: string;\n traceId: string;\n spanId?: string;\n name: string;\n value: number;\n comment?: string;\n metadata?: Record<string, unknown>;\n }): void {\n if (!this.#client) return;\n\n const { id, traceId, spanId, name, value, comment, metadata } = args;\n try {\n this.#client.score.create({\n id,\n traceId,\n ...(spanId ? { observationId: spanId } : {}),\n name,\n value,\n ...(comment ? { comment } : {}),\n ...(metadata ? { metadata } : {}),\n dataType: 'NUMERIC' as const,\n });\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Error submitting score`, {\n error,\n traceId,\n spanId,\n name,\n });\n }\n }\n\n async onScoreEvent(event: ScoreEvent): Promise<void> {\n const { score } = event;\n if (!score.traceId) return;\n this.submitScore({\n id: score.scoreId,\n traceId: score.traceId,\n spanId: score.spanId,\n name: score.scorerName ?? score.scorerId,\n value: score.score,\n comment: score.reason,\n metadata: score.metadata,\n });\n }\n\n /**\n * @deprecated Use the observability score event pipeline (`mastra.observability.addScore`)\n * instead. This method is preserved for backwards compatibility and forwards to the same\n * underlying client call as `onScoreEvent`.\n */\n async addScoreToTrace({\n traceId,\n spanId,\n score,\n reason,\n scorerName,\n metadata,\n }: {\n traceId: string;\n spanId?: string;\n score: number;\n reason?: string;\n scorerName: string;\n metadata?: Record<string, any>;\n }): Promise<void> {\n this.submitScore({\n id: `${traceId}-${spanId || ''}-${scorerName}`,\n traceId,\n spanId,\n name: scorerName,\n value: score,\n comment: reason,\n metadata,\n });\n }\n\n async flush(): Promise<void> {\n await Promise.all([this.#processor?.forceFlush(), this.#client?.flush()]);\n }\n\n async shutdown(): Promise<void> {\n await Promise.all([this.#processor?.shutdown(), this.#client?.shutdown()]);\n }\n}\n\n/**\n * Maps Mastra-specific OTel attributes to the langfuse.* namespace that\n * Langfuse's OTLP endpoint reads for prompt linking, TTFT, and other features.\n *\n * SpanConverter produces attributes like mastra.metadata.*, mastra.completion_start_time, etc.\n * Langfuse's OTLP server only reads langfuse.observation.prompt.name, langfuse.observation.completion_start_time, etc.\n *\n * This function mutates the attributes object in place.\n * @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n */\nfunction mapMastraToLangfuseAttributes(\n attributes: Record<string, any>,\n span: AnyExportedSpan,\n environment?: string,\n release?: string,\n): void {\n // Environment and release: set directly since onStart() is not called\n if (environment) {\n attributes['langfuse.environment'] = environment;\n }\n if (release) {\n attributes['langfuse.release'] = release;\n }\n\n // Prompt linking: mastra.metadata.langfuse → langfuse.observation.prompt.name / version\n const langfuseMetadata = attributes['mastra.metadata.langfuse'];\n if (langfuseMetadata) {\n try {\n const parsed = typeof langfuseMetadata === 'string' ? JSON.parse(langfuseMetadata) : langfuseMetadata;\n if (parsed?.prompt) {\n if (parsed.prompt.name !== undefined) {\n attributes['langfuse.observation.prompt.name'] = parsed.prompt.name;\n }\n if (parsed.prompt.version !== undefined) {\n attributes['langfuse.observation.prompt.version'] = parsed.prompt.version;\n }\n }\n } catch {\n // best effort — invalid JSON is silently ignored\n }\n delete attributes['mastra.metadata.langfuse'];\n }\n\n // TTFT: mastra.completion_start_time → langfuse.observation.completion_start_time\n if (attributes['mastra.completion_start_time']) {\n attributes['langfuse.observation.completion_start_time'] = attributes['mastra.completion_start_time'];\n delete attributes['mastra.completion_start_time'];\n }\n\n // User ID: mastra.metadata.userId → user.id\n if (attributes['mastra.metadata.userId']) {\n attributes['user.id'] = attributes['mastra.metadata.userId'];\n delete attributes['mastra.metadata.userId'];\n }\n\n // Session ID: mastra.metadata.sessionId or threadId → session.id\n const sessionId = attributes['mastra.metadata.sessionId'] ?? attributes['mastra.metadata.threadId'];\n if (sessionId) {\n attributes['session.id'] = sessionId;\n delete attributes['mastra.metadata.sessionId'];\n delete attributes['mastra.metadata.threadId'];\n }\n\n // Tags: mastra.tags → langfuse.trace.tags\n if (attributes['mastra.tags']) {\n attributes['langfuse.trace.tags'] = attributes['mastra.tags'];\n delete attributes['mastra.tags'];\n }\n\n // Trace name: mastra.metadata.traceName → langfuse.trace.name\n if (attributes['mastra.metadata.traceName']) {\n attributes['langfuse.trace.name'] = attributes['mastra.metadata.traceName'];\n delete attributes['mastra.metadata.traceName'];\n }\n\n // Trace version: mastra.metadata.version → langfuse.trace.version\n if (attributes['mastra.metadata.version']) {\n attributes['langfuse.trace.version'] = attributes['mastra.metadata.version'];\n delete attributes['mastra.metadata.version'];\n }\n\n // Root-span trace identity: scope each Langfuse trace to the entity that\n // started it (agent or workflow). This makes the Langfuse trace name match\n // the agent/workflow id and exposes the same identity as trace metadata, so\n // users can scope Langfuse evaluators per agent via trace name or metadata\n // filters. User-provided traceName (set via mastra.metadata.traceName) takes\n // precedence and is preserved.\n if (span.isRootSpan) {\n if (span.type === SpanType.AGENT_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.agentId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.agentName'] = span.entityName;\n }\n } else if (span.type === SpanType.WORKFLOW_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.workflowId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.workflowName'] = span.entityName;\n }\n }\n }\n\n // Observation metadata: map semantic attributes to langfuse.observation.metadata.*\n // so they become top-level filterable keys on each observation in Langfuse.\n // @see https://langfuse.com/integrations/native/opentelemetry#how-metadata-mapping-works\n if (attributes['gen_ai.agent.id']) {\n attributes['langfuse.observation.metadata.agentId'] = attributes['gen_ai.agent.id'];\n }\n if (attributes['gen_ai.agent.name']) {\n attributes['langfuse.observation.metadata.agentName'] = attributes['gen_ai.agent.name'];\n }\n if (attributes['mastra.span.type']) {\n attributes['langfuse.observation.metadata.spanType'] = attributes['mastra.span.type'];\n }\n if (attributes['gen_ai.operation.name']) {\n attributes['langfuse.observation.metadata.operationName'] = attributes['gen_ai.operation.name'];\n }\n\n // Input/Output: mastra.*.input/output → langfuse.observation.input/output\n // For gen_ai spans, Langfuse reads gen_ai.input.messages natively.\n // For non-gen_ai spans, we map the first mastra.*.input/output we find.\n if (!attributes['gen_ai.input.messages'] && !attributes['gen_ai.tool.call.arguments']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.input')) {\n attributes['langfuse.observation.input'] = attributes[key];\n break;\n }\n }\n }\n if (!attributes['gen_ai.output.messages'] && !attributes['gen_ai.tool.call.result']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.output')) {\n attributes['langfuse.observation.output'] = attributes[key];\n break;\n }\n }\n }\n}\n\n/**\n * Remove trailing \"/\" characters procedurally. Avoids polynomial\n * backtracking that a greedy regex like `/\\/+$/` can exhibit when the\n * input is attacker-controlled.\n */\nfunction stripTrailingSlashes(s: string): string {\n let end = s.length;\n while (end > 0 && s.charCodeAt(end - 1) === 47 /* \"/\" */) {\n end--;\n }\n return end === s.length ? s : s.slice(0, end);\n}\n","/**\n * Langfuse Tracing Options Helpers\n *\n * These helpers integrate with the `buildTracingOptions` pattern from\n * `@mastra/observability` to add Langfuse-specific tracing features.\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * const agent = new Agent({\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\n\nimport type { TracingOptionsUpdater } from '@mastra/observability';\n\n/**\n * Langfuse prompt input - accepts either a Langfuse SDK prompt object\n * or manual fields.\n */\nexport interface LangfusePromptInput {\n /** Prompt name */\n name?: string;\n /** Prompt version */\n version?: number;\n /** @deprecated Langfuse v5 only supports linking by name + version. This field is ignored. */\n id?: string;\n}\n\n/**\n * Adds Langfuse prompt metadata to the tracing options\n * to enable Langfuse Prompt Tracing.\n *\n * The metadata is added under `metadata.langfuse.prompt` and includes:\n * - `name` - Prompt name (required for Langfuse v5)\n * - `version` - Prompt version (required for Langfuse v5)\n *\n * All fields are deeply merged with any existing metadata.\n *\n * @param prompt - Prompt fields for linking (`name` and `version` required)\n * @returns A TracingOptionsUpdater function for use with `buildTracingOptions`\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * // Link a generation to a Langfuse prompt by name and version\n * const tracingOptions = buildTracingOptions(\n * withLangfusePrompt({ name: 'customer-support', version: 1 }),\n * );\n *\n * // Or directly in agent config\n * const agent = new Agent({\n * name: 'support-agent',\n * instructions: 'You are a helpful assistant',\n * model: openai('gpt-4o'),\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\nexport function withLangfusePrompt(prompt: LangfusePromptInput): TracingOptionsUpdater {\n return opts => ({\n ...opts,\n metadata: {\n ...opts.metadata,\n langfuse: {\n ...(opts.metadata?.langfuse as Record<string, unknown>),\n prompt: {\n ...(prompt.name !== undefined && { name: prompt.name }),\n ...(prompt.version !== undefined && { version: prompt.version }),\n ...(prompt.id !== undefined && { id: prompt.id }),\n },\n },\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/tracing.ts","../src/helpers.ts"],"names":["BaseExporter","LangfuseSpanProcessor","LangfuseClient","SpanConverter","TracingEventType","SpanType"],"mappings":";;;;;;;;;AAiBA,IAAM,UAAA,GAAa,oBAAA;AAEZ,IAAM,yBAAA,GAA4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AqB,CAAA,EAAmB;AAC/C,EAAA,IAAI,MAAM,CAAA,CAAE,MAAA;AACZ,EAAA,OAAO,MAAM,CAAA,IAAK,CAAA,CAAE,WAAW,GAAA,GAAM,CAAC,MAAM,EAAA,EAAc;AACxD,IAAA,GAAA,EAAA;AAAA,EACF;AACA,EAAA,OAAO,QAAQ,CAAA,CAAE,MAAA,GAAS,IAAI,CAAA,CAAE,KAAA,CAAM,GAAG,GAAG,CAAA;AAC9C;;;AC/VO,SAAS,mBAAmB,MAAA,EAAoD;AACrF,EAAA,OAAO,CAAA,IAAA,MAAS;AAAA,IACd,GAAG,IAAA;AAAA,IACH,QAAA,EAAU;AAAA,MACR,GAAG,IAAA,CAAK,QAAA;AAAA,MACR,QAAA,EAAU;AAAA,QACR,GAAI,KAAK,QAAA,EAAU,QAAA;AAAA,QACnB,MAAA,EAAQ;AAAA,UACN,GAAI,MAAA,CAAO,IAAA,KAAS,UAAa,EAAE,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,UACrD,GAAI,MAAA,CAAO,OAAA,KAAY,UAAa,EAAE,OAAA,EAAS,OAAO,OAAA,EAAQ;AAAA,UAC9D,GAAI,MAAA,CAAO,EAAA,KAAO,UAAa,EAAE,EAAA,EAAI,OAAO,EAAA;AAAG;AACjD;AACF;AACF,GACF,CAAA;AACF","file":"index.cjs","sourcesContent":["/**\n * Langfuse Exporter for Mastra Observability\n *\n * Sends observability data to Langfuse using the official @langfuse/otel span processor\n * and @langfuse/client for non-tracing features (scoring, prompt management, evaluations).\n *\n * @see https://langfuse.com/docs/observability/sdk/typescript/overview\n */\n\nimport { LangfuseClient } from '@langfuse/client';\nimport { LangfuseSpanProcessor } from '@langfuse/otel';\nimport type { TracingEvent, AnyExportedSpan, InitExporterOptions, ScoreEvent } from '@mastra/core/observability';\nimport { SpanType, TracingEventType } from '@mastra/core/observability';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { SpanConverter } from '@mastra/otel-exporter';\n\nconst LOG_PREFIX = '[LangfuseExporter]';\n\nexport const LANGFUSE_DEFAULT_BASE_URL = 'https://cloud.langfuse.com';\n\nexport interface LangfuseExporterConfig extends BaseExporterConfig {\n /** Langfuse public key */\n publicKey?: string;\n /** Langfuse secret key */\n secretKey?: string;\n /** Langfuse host URL (defaults to https://cloud.langfuse.com) */\n baseUrl?: string;\n /** Enable realtime mode - flushes after each event for immediate visibility */\n realtime?: boolean;\n /** Maximum number of spans per OTEL export batch */\n flushAt?: number;\n /** Maximum time in seconds before pending spans are exported */\n flushInterval?: number;\n /** Langfuse environment tag for traces */\n environment?: string;\n /** Langfuse release tag for traces */\n release?: string;\n}\n\nexport class LangfuseExporter extends BaseExporter {\n name = 'langfuse';\n #processor: LangfuseSpanProcessor | undefined;\n #client: LangfuseClient | undefined;\n #spanConverter: SpanConverter | undefined;\n #realtime: boolean;\n #environment: string | undefined;\n #release: string | undefined;\n\n constructor(config: LangfuseExporterConfig = {}) {\n super(config);\n\n const publicKey = config.publicKey ?? process.env.LANGFUSE_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.LANGFUSE_SECRET_KEY;\n const baseUrl = stripTrailingSlashes(config.baseUrl ?? process.env.LANGFUSE_BASE_URL ?? LANGFUSE_DEFAULT_BASE_URL);\n this.#realtime = config.realtime ?? false;\n\n if (!publicKey || !secretKey) {\n const publicKeySource = config.publicKey\n ? 'from config'\n : process.env.LANGFUSE_PUBLIC_KEY\n ? 'from env'\n : 'missing';\n const secretKeySource = config.secretKey\n ? 'from config'\n : process.env.LANGFUSE_SECRET_KEY\n ? 'from env'\n : 'missing';\n this.setDisabled(\n `${LOG_PREFIX} Missing required credentials (publicKey: ${publicKeySource}, secretKey: ${secretKeySource}). ` +\n `Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY environment variables or pass them in config.`,\n );\n return;\n }\n\n this.#processor = new LangfuseSpanProcessor({\n publicKey,\n secretKey,\n baseUrl,\n environment: config.environment,\n release: config.release,\n exportMode: this.#realtime ? 'immediate' : 'batched',\n flushAt: config.flushAt,\n flushInterval: config.flushInterval,\n // Export all spans — the default filter only passes spans with gen_ai.* attributes\n // or known LLM instrumentation scopes, but Mastra spans use mastra.* attributes.\n shouldExportSpan: () => true,\n });\n\n this.#client = new LangfuseClient({\n publicKey,\n secretKey,\n baseUrl,\n });\n\n this.#environment = config.environment ?? process.env.LANGFUSE_TRACING_ENVIRONMENT;\n this.#release = config.release ?? process.env.LANGFUSE_RELEASE;\n }\n\n init(options: InitExporterOptions) {\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: options.config?.serviceName,\n format: 'GenAI_v1_38_0',\n });\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.type !== TracingEventType.SPAN_ENDED) return;\n if (!this.#processor) return;\n\n await this.exportSpan(event.exportedSpan);\n }\n\n private async exportSpan(span: AnyExportedSpan): Promise<void> {\n if (!this.#spanConverter) {\n // Fallback if init() was not called (e.g., standalone usage without Mastra)\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: 'mastra-service',\n format: 'GenAI_v1_38_0',\n });\n }\n\n try {\n const otelSpan = await this.#spanConverter.convertSpan(span);\n\n // Map mastra.* attributes to langfuse.* namespace so that Langfuse's OTLP\n // endpoint reads them correctly. SpanConverter produces mastra.* attributes,\n // but Langfuse only reads langfuse.* attributes for prompt linking, TTFT, etc.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n mapMastraToLangfuseAttributes(otelSpan.attributes, span, this.#environment, this.#release);\n\n this.#processor!.onEnd(otelSpan);\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Failed to export span ${span.id}:`, error);\n }\n }\n\n /**\n * The LangfuseClient instance for advanced Langfuse features.\n * Use this for prompt management, evaluations, datasets, and direct API access.\n */\n get client(): LangfuseClient | undefined {\n return this.#client;\n }\n\n /**\n * Submit a score to Langfuse. Used by both the new `onScoreEvent` path and the\n * deprecated `addScoreToTrace` wrapper.\n */\n private submitScore(args: {\n id: string;\n traceId: string;\n spanId?: string;\n name: string;\n value: number;\n comment?: string;\n metadata?: Record<string, unknown>;\n }): void {\n if (!this.#client) return;\n\n const { id, traceId, spanId, name, value, comment, metadata } = args;\n try {\n this.#client.score.create({\n id,\n traceId,\n ...(spanId ? { observationId: spanId } : {}),\n name,\n value,\n ...(comment ? { comment } : {}),\n ...(metadata ? { metadata } : {}),\n dataType: 'NUMERIC' as const,\n });\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Error submitting score`, {\n error,\n traceId,\n spanId,\n name,\n });\n }\n }\n\n async onScoreEvent(event: ScoreEvent): Promise<void> {\n const { score } = event;\n if (!score.traceId) return;\n this.submitScore({\n id: score.scoreId,\n traceId: score.traceId,\n spanId: score.spanId,\n name: score.scorerName ?? score.scorerId,\n value: score.score,\n comment: score.reason,\n metadata: score.metadata,\n });\n }\n\n /**\n * @deprecated Use the observability score event pipeline (`mastra.observability.addScore`)\n * instead. This method is preserved for backwards compatibility and forwards to the same\n * underlying client call as `onScoreEvent`.\n */\n async addScoreToTrace({\n traceId,\n spanId,\n score,\n reason,\n scorerName,\n metadata,\n }: {\n traceId: string;\n spanId?: string;\n score: number;\n reason?: string;\n scorerName: string;\n metadata?: Record<string, any>;\n }): Promise<void> {\n this.submitScore({\n id: `${traceId}-${spanId || ''}-${scorerName}`,\n traceId,\n spanId,\n name: scorerName,\n value: score,\n comment: reason,\n metadata,\n });\n }\n\n async flush(): Promise<void> {\n await Promise.all([this.#processor?.forceFlush(), this.#client?.flush()]);\n }\n\n async shutdown(): Promise<void> {\n await Promise.all([this.#processor?.shutdown(), this.#client?.shutdown()]);\n }\n}\n\n/**\n * Maps Mastra-specific OTel attributes to the langfuse.* namespace that\n * Langfuse's OTLP endpoint reads for prompt linking, TTFT, and other features.\n *\n * SpanConverter produces attributes like mastra.metadata.*, mastra.completion_start_time, etc.\n * Langfuse's OTLP server only reads langfuse.observation.prompt.name, langfuse.observation.completion_start_time, etc.\n *\n * This function mutates the attributes object in place.\n * @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n */\nfunction mapMastraToLangfuseAttributes(\n attributes: Record<string, any>,\n span: AnyExportedSpan,\n environment?: string,\n release?: string,\n): void {\n // Environment and release: set directly since onStart() is not called\n if (environment) {\n attributes['langfuse.environment'] = environment;\n }\n if (release) {\n attributes['langfuse.release'] = release;\n }\n\n // mastra.metadata.langfuse holds a user-supplied object with two kinds of keys:\n // - the reserved `prompt` key, used for prompt linking, and\n // - arbitrary custom keys the user wants as top-level, filterable trace metadata.\n // Langfuse only allows filtering/grouping traces by top-level metadata\n // (langfuse.trace.metadata.*), so forward every non-prompt key there. These\n // attributes may be set on any span in the trace and land on the trace record.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n const langfuseMetadata = attributes['mastra.metadata.langfuse'];\n if (langfuseMetadata) {\n try {\n const parsed = typeof langfuseMetadata === 'string' ? JSON.parse(langfuseMetadata) : langfuseMetadata;\n if (parsed && typeof parsed === 'object') {\n // Prompt linking: mastra.metadata.langfuse.prompt → langfuse.observation.prompt.name / version\n if (parsed.prompt) {\n if (parsed.prompt.name !== undefined) {\n attributes['langfuse.observation.prompt.name'] = parsed.prompt.name;\n }\n if (parsed.prompt.version !== undefined) {\n attributes['langfuse.observation.prompt.version'] = parsed.prompt.version;\n }\n }\n\n // Custom keys: mastra.metadata.langfuse.<key> → langfuse.trace.metadata.<key>\n // Reserved identity keys (agentId/agentName/workflowId/workflowName) are set\n // by the root-span block below, which runs after this loop and takes precedence.\n for (const [key, value] of Object.entries(parsed)) {\n if (key === 'prompt' || value === null || value === undefined) {\n continue;\n }\n const traceKey = `langfuse.trace.metadata.${key}`;\n // Don't overwrite a trace.metadata key already mapped from another attribute.\n if (attributes[traceKey] === undefined) {\n // Langfuse maps langfuse.trace.metadata.* as string attributes, so\n // serialize non-strings with JSON. Langfuse Cloud restores numbers,\n // booleans, and objects to their original types on ingestion.\n attributes[traceKey] = typeof value === 'string' ? value : JSON.stringify(value);\n }\n }\n }\n } catch {\n // best effort — invalid JSON is silently ignored\n }\n delete attributes['mastra.metadata.langfuse'];\n }\n\n // TTFT: mastra.completion_start_time → langfuse.observation.completion_start_time\n if (attributes['mastra.completion_start_time']) {\n attributes['langfuse.observation.completion_start_time'] = attributes['mastra.completion_start_time'];\n delete attributes['mastra.completion_start_time'];\n }\n\n // User ID: mastra.metadata.userId → user.id\n if (attributes['mastra.metadata.userId']) {\n attributes['user.id'] = attributes['mastra.metadata.userId'];\n delete attributes['mastra.metadata.userId'];\n }\n\n // Session ID: mastra.metadata.sessionId or threadId → session.id\n const sessionId = attributes['mastra.metadata.sessionId'] ?? attributes['mastra.metadata.threadId'];\n if (sessionId) {\n attributes['session.id'] = sessionId;\n delete attributes['mastra.metadata.sessionId'];\n delete attributes['mastra.metadata.threadId'];\n }\n\n // Tags: mastra.tags → langfuse.trace.tags\n if (attributes['mastra.tags']) {\n attributes['langfuse.trace.tags'] = attributes['mastra.tags'];\n delete attributes['mastra.tags'];\n }\n\n // Trace name: mastra.metadata.traceName → langfuse.trace.name\n if (attributes['mastra.metadata.traceName']) {\n attributes['langfuse.trace.name'] = attributes['mastra.metadata.traceName'];\n delete attributes['mastra.metadata.traceName'];\n }\n\n // Trace version: mastra.metadata.version → langfuse.trace.version\n if (attributes['mastra.metadata.version']) {\n attributes['langfuse.trace.version'] = attributes['mastra.metadata.version'];\n delete attributes['mastra.metadata.version'];\n }\n\n // Root-span trace identity: scope each Langfuse trace to the entity that\n // started it (agent or workflow). This makes the Langfuse trace name match\n // the agent/workflow id and exposes the same identity as trace metadata, so\n // users can scope Langfuse evaluators per agent via trace name or metadata\n // filters. User-provided traceName (set via mastra.metadata.traceName) takes\n // precedence and is preserved.\n if (span.isRootSpan) {\n if (span.type === SpanType.AGENT_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.agentId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.agentName'] = span.entityName;\n }\n } else if (span.type === SpanType.WORKFLOW_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.workflowId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.workflowName'] = span.entityName;\n }\n }\n }\n\n // Observation metadata: map semantic attributes to langfuse.observation.metadata.*\n // so they become top-level filterable keys on each observation in Langfuse.\n // @see https://langfuse.com/integrations/native/opentelemetry#how-metadata-mapping-works\n if (attributes['gen_ai.agent.id']) {\n attributes['langfuse.observation.metadata.agentId'] = attributes['gen_ai.agent.id'];\n }\n if (attributes['gen_ai.agent.name']) {\n attributes['langfuse.observation.metadata.agentName'] = attributes['gen_ai.agent.name'];\n }\n if (attributes['mastra.span.type']) {\n attributes['langfuse.observation.metadata.spanType'] = attributes['mastra.span.type'];\n }\n if (attributes['gen_ai.operation.name']) {\n attributes['langfuse.observation.metadata.operationName'] = attributes['gen_ai.operation.name'];\n }\n\n // Input/Output: mastra.*.input/output → langfuse.observation.input/output\n // For gen_ai spans, Langfuse reads gen_ai.input.messages natively.\n // For non-gen_ai spans, we map the first mastra.*.input/output we find.\n if (!attributes['gen_ai.input.messages'] && !attributes['gen_ai.tool.call.arguments']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.input')) {\n attributes['langfuse.observation.input'] = attributes[key];\n break;\n }\n }\n }\n if (!attributes['gen_ai.output.messages'] && !attributes['gen_ai.tool.call.result']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.output')) {\n attributes['langfuse.observation.output'] = attributes[key];\n break;\n }\n }\n }\n}\n\n/**\n * Remove trailing \"/\" characters procedurally. Avoids polynomial\n * backtracking that a greedy regex like `/\\/+$/` can exhibit when the\n * input is attacker-controlled.\n */\nfunction stripTrailingSlashes(s: string): string {\n let end = s.length;\n while (end > 0 && s.charCodeAt(end - 1) === 47 /* \"/\" */) {\n end--;\n }\n return end === s.length ? s : s.slice(0, end);\n}\n","/**\n * Langfuse Tracing Options Helpers\n *\n * These helpers integrate with the `buildTracingOptions` pattern from\n * `@mastra/observability` to add Langfuse-specific tracing features.\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * const agent = new Agent({\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\n\nimport type { TracingOptionsUpdater } from '@mastra/observability';\n\n/**\n * Langfuse prompt input - accepts either a Langfuse SDK prompt object\n * or manual fields.\n */\nexport interface LangfusePromptInput {\n /** Prompt name */\n name?: string;\n /** Prompt version */\n version?: number;\n /** @deprecated Langfuse v5 only supports linking by name + version. This field is ignored. */\n id?: string;\n}\n\n/**\n * Adds Langfuse prompt metadata to the tracing options\n * to enable Langfuse Prompt Tracing.\n *\n * The metadata is added under `metadata.langfuse.prompt` and includes:\n * - `name` - Prompt name (required for Langfuse v5)\n * - `version` - Prompt version (required for Langfuse v5)\n *\n * All fields are deeply merged with any existing metadata.\n *\n * @param prompt - Prompt fields for linking (`name` and `version` required)\n * @returns A TracingOptionsUpdater function for use with `buildTracingOptions`\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * // Link a generation to a Langfuse prompt by name and version\n * const tracingOptions = buildTracingOptions(\n * withLangfusePrompt({ name: 'customer-support', version: 1 }),\n * );\n *\n * // Or directly in agent config\n * const agent = new Agent({\n * name: 'support-agent',\n * instructions: 'You are a helpful assistant',\n * model: openai('gpt-4o'),\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\nexport function withLangfusePrompt(prompt: LangfusePromptInput): TracingOptionsUpdater {\n return opts => ({\n ...opts,\n metadata: {\n ...opts.metadata,\n langfuse: {\n ...(opts.metadata?.langfuse as Record<string, unknown>),\n prompt: {\n ...(prompt.name !== undefined && { name: prompt.name }),\n ...(prompt.version !== undefined && { version: prompt.version }),\n ...(prompt.id !== undefined && { id: prompt.id }),\n },\n },\n },\n });\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -166,12 +166,23 @@ function mapMastraToLangfuseAttributes(attributes, span, environment, release) {
|
|
|
166
166
|
if (langfuseMetadata) {
|
|
167
167
|
try {
|
|
168
168
|
const parsed = typeof langfuseMetadata === "string" ? JSON.parse(langfuseMetadata) : langfuseMetadata;
|
|
169
|
-
if (parsed
|
|
170
|
-
if (parsed.prompt
|
|
171
|
-
|
|
169
|
+
if (parsed && typeof parsed === "object") {
|
|
170
|
+
if (parsed.prompt) {
|
|
171
|
+
if (parsed.prompt.name !== void 0) {
|
|
172
|
+
attributes["langfuse.observation.prompt.name"] = parsed.prompt.name;
|
|
173
|
+
}
|
|
174
|
+
if (parsed.prompt.version !== void 0) {
|
|
175
|
+
attributes["langfuse.observation.prompt.version"] = parsed.prompt.version;
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
179
|
+
if (key === "prompt" || value === null || value === void 0) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const traceKey = `langfuse.trace.metadata.${key}`;
|
|
183
|
+
if (attributes[traceKey] === void 0) {
|
|
184
|
+
attributes[traceKey] = typeof value === "string" ? value : JSON.stringify(value);
|
|
185
|
+
}
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
} catch {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tracing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QAAA;AAAA,MACR,QAAA,EAAU;AAAA,QACR,GAAI,KAAK,QAAA,EAAU,QAAA;AAAA,QACnB,MAAA,EAAQ;AAAA,UACN,GAAI,MAAA,CAAO,IAAA,KAAS,UAAa,EAAE,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,UACrD,GAAI,MAAA,CAAO,OAAA,KAAY,UAAa,EAAE,OAAA,EAAS,OAAO,OAAA,EAAQ;AAAA,UAC9D,GAAI,MAAA,CAAO,EAAA,KAAO,UAAa,EAAE,EAAA,EAAI,OAAO,EAAA;AAAG;AACjD;AACF;AACF,GACF,CAAA;AACF","file":"index.js","sourcesContent":["/**\n * Langfuse Exporter for Mastra Observability\n *\n * Sends observability data to Langfuse using the official @langfuse/otel span processor\n * and @langfuse/client for non-tracing features (scoring, prompt management, evaluations).\n *\n * @see https://langfuse.com/docs/observability/sdk/typescript/overview\n */\n\nimport { LangfuseClient } from '@langfuse/client';\nimport { LangfuseSpanProcessor } from '@langfuse/otel';\nimport type { TracingEvent, AnyExportedSpan, InitExporterOptions, ScoreEvent } from '@mastra/core/observability';\nimport { SpanType, TracingEventType } from '@mastra/core/observability';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { SpanConverter } from '@mastra/otel-exporter';\n\nconst LOG_PREFIX = '[LangfuseExporter]';\n\nexport const LANGFUSE_DEFAULT_BASE_URL = 'https://cloud.langfuse.com';\n\nexport interface LangfuseExporterConfig extends BaseExporterConfig {\n /** Langfuse public key */\n publicKey?: string;\n /** Langfuse secret key */\n secretKey?: string;\n /** Langfuse host URL (defaults to https://cloud.langfuse.com) */\n baseUrl?: string;\n /** Enable realtime mode - flushes after each event for immediate visibility */\n realtime?: boolean;\n /** Maximum number of spans per OTEL export batch */\n flushAt?: number;\n /** Maximum time in seconds before pending spans are exported */\n flushInterval?: number;\n /** Langfuse environment tag for traces */\n environment?: string;\n /** Langfuse release tag for traces */\n release?: string;\n}\n\nexport class LangfuseExporter extends BaseExporter {\n name = 'langfuse';\n #processor: LangfuseSpanProcessor | undefined;\n #client: LangfuseClient | undefined;\n #spanConverter: SpanConverter | undefined;\n #realtime: boolean;\n #environment: string | undefined;\n #release: string | undefined;\n\n constructor(config: LangfuseExporterConfig = {}) {\n super(config);\n\n const publicKey = config.publicKey ?? process.env.LANGFUSE_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.LANGFUSE_SECRET_KEY;\n const baseUrl = stripTrailingSlashes(config.baseUrl ?? process.env.LANGFUSE_BASE_URL ?? LANGFUSE_DEFAULT_BASE_URL);\n this.#realtime = config.realtime ?? false;\n\n if (!publicKey || !secretKey) {\n const publicKeySource = config.publicKey\n ? 'from config'\n : process.env.LANGFUSE_PUBLIC_KEY\n ? 'from env'\n : 'missing';\n const secretKeySource = config.secretKey\n ? 'from config'\n : process.env.LANGFUSE_SECRET_KEY\n ? 'from env'\n : 'missing';\n this.setDisabled(\n `${LOG_PREFIX} Missing required credentials (publicKey: ${publicKeySource}, secretKey: ${secretKeySource}). ` +\n `Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY environment variables or pass them in config.`,\n );\n return;\n }\n\n this.#processor = new LangfuseSpanProcessor({\n publicKey,\n secretKey,\n baseUrl,\n environment: config.environment,\n release: config.release,\n exportMode: this.#realtime ? 'immediate' : 'batched',\n flushAt: config.flushAt,\n flushInterval: config.flushInterval,\n // Export all spans — the default filter only passes spans with gen_ai.* attributes\n // or known LLM instrumentation scopes, but Mastra spans use mastra.* attributes.\n shouldExportSpan: () => true,\n });\n\n this.#client = new LangfuseClient({\n publicKey,\n secretKey,\n baseUrl,\n });\n\n this.#environment = config.environment ?? process.env.LANGFUSE_TRACING_ENVIRONMENT;\n this.#release = config.release ?? process.env.LANGFUSE_RELEASE;\n }\n\n init(options: InitExporterOptions) {\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: options.config?.serviceName,\n format: 'GenAI_v1_38_0',\n });\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.type !== TracingEventType.SPAN_ENDED) return;\n if (!this.#processor) return;\n\n await this.exportSpan(event.exportedSpan);\n }\n\n private async exportSpan(span: AnyExportedSpan): Promise<void> {\n if (!this.#spanConverter) {\n // Fallback if init() was not called (e.g., standalone usage without Mastra)\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: 'mastra-service',\n format: 'GenAI_v1_38_0',\n });\n }\n\n try {\n const otelSpan = await this.#spanConverter.convertSpan(span);\n\n // Map mastra.* attributes to langfuse.* namespace so that Langfuse's OTLP\n // endpoint reads them correctly. SpanConverter produces mastra.* attributes,\n // but Langfuse only reads langfuse.* attributes for prompt linking, TTFT, etc.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n mapMastraToLangfuseAttributes(otelSpan.attributes, span, this.#environment, this.#release);\n\n this.#processor!.onEnd(otelSpan);\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Failed to export span ${span.id}:`, error);\n }\n }\n\n /**\n * The LangfuseClient instance for advanced Langfuse features.\n * Use this for prompt management, evaluations, datasets, and direct API access.\n */\n get client(): LangfuseClient | undefined {\n return this.#client;\n }\n\n /**\n * Submit a score to Langfuse. Used by both the new `onScoreEvent` path and the\n * deprecated `addScoreToTrace` wrapper.\n */\n private submitScore(args: {\n id: string;\n traceId: string;\n spanId?: string;\n name: string;\n value: number;\n comment?: string;\n metadata?: Record<string, unknown>;\n }): void {\n if (!this.#client) return;\n\n const { id, traceId, spanId, name, value, comment, metadata } = args;\n try {\n this.#client.score.create({\n id,\n traceId,\n ...(spanId ? { observationId: spanId } : {}),\n name,\n value,\n ...(comment ? { comment } : {}),\n ...(metadata ? { metadata } : {}),\n dataType: 'NUMERIC' as const,\n });\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Error submitting score`, {\n error,\n traceId,\n spanId,\n name,\n });\n }\n }\n\n async onScoreEvent(event: ScoreEvent): Promise<void> {\n const { score } = event;\n if (!score.traceId) return;\n this.submitScore({\n id: score.scoreId,\n traceId: score.traceId,\n spanId: score.spanId,\n name: score.scorerName ?? score.scorerId,\n value: score.score,\n comment: score.reason,\n metadata: score.metadata,\n });\n }\n\n /**\n * @deprecated Use the observability score event pipeline (`mastra.observability.addScore`)\n * instead. This method is preserved for backwards compatibility and forwards to the same\n * underlying client call as `onScoreEvent`.\n */\n async addScoreToTrace({\n traceId,\n spanId,\n score,\n reason,\n scorerName,\n metadata,\n }: {\n traceId: string;\n spanId?: string;\n score: number;\n reason?: string;\n scorerName: string;\n metadata?: Record<string, any>;\n }): Promise<void> {\n this.submitScore({\n id: `${traceId}-${spanId || ''}-${scorerName}`,\n traceId,\n spanId,\n name: scorerName,\n value: score,\n comment: reason,\n metadata,\n });\n }\n\n async flush(): Promise<void> {\n await Promise.all([this.#processor?.forceFlush(), this.#client?.flush()]);\n }\n\n async shutdown(): Promise<void> {\n await Promise.all([this.#processor?.shutdown(), this.#client?.shutdown()]);\n }\n}\n\n/**\n * Maps Mastra-specific OTel attributes to the langfuse.* namespace that\n * Langfuse's OTLP endpoint reads for prompt linking, TTFT, and other features.\n *\n * SpanConverter produces attributes like mastra.metadata.*, mastra.completion_start_time, etc.\n * Langfuse's OTLP server only reads langfuse.observation.prompt.name, langfuse.observation.completion_start_time, etc.\n *\n * This function mutates the attributes object in place.\n * @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n */\nfunction mapMastraToLangfuseAttributes(\n attributes: Record<string, any>,\n span: AnyExportedSpan,\n environment?: string,\n release?: string,\n): void {\n // Environment and release: set directly since onStart() is not called\n if (environment) {\n attributes['langfuse.environment'] = environment;\n }\n if (release) {\n attributes['langfuse.release'] = release;\n }\n\n // Prompt linking: mastra.metadata.langfuse → langfuse.observation.prompt.name / version\n const langfuseMetadata = attributes['mastra.metadata.langfuse'];\n if (langfuseMetadata) {\n try {\n const parsed = typeof langfuseMetadata === 'string' ? JSON.parse(langfuseMetadata) : langfuseMetadata;\n if (parsed?.prompt) {\n if (parsed.prompt.name !== undefined) {\n attributes['langfuse.observation.prompt.name'] = parsed.prompt.name;\n }\n if (parsed.prompt.version !== undefined) {\n attributes['langfuse.observation.prompt.version'] = parsed.prompt.version;\n }\n }\n } catch {\n // best effort — invalid JSON is silently ignored\n }\n delete attributes['mastra.metadata.langfuse'];\n }\n\n // TTFT: mastra.completion_start_time → langfuse.observation.completion_start_time\n if (attributes['mastra.completion_start_time']) {\n attributes['langfuse.observation.completion_start_time'] = attributes['mastra.completion_start_time'];\n delete attributes['mastra.completion_start_time'];\n }\n\n // User ID: mastra.metadata.userId → user.id\n if (attributes['mastra.metadata.userId']) {\n attributes['user.id'] = attributes['mastra.metadata.userId'];\n delete attributes['mastra.metadata.userId'];\n }\n\n // Session ID: mastra.metadata.sessionId or threadId → session.id\n const sessionId = attributes['mastra.metadata.sessionId'] ?? attributes['mastra.metadata.threadId'];\n if (sessionId) {\n attributes['session.id'] = sessionId;\n delete attributes['mastra.metadata.sessionId'];\n delete attributes['mastra.metadata.threadId'];\n }\n\n // Tags: mastra.tags → langfuse.trace.tags\n if (attributes['mastra.tags']) {\n attributes['langfuse.trace.tags'] = attributes['mastra.tags'];\n delete attributes['mastra.tags'];\n }\n\n // Trace name: mastra.metadata.traceName → langfuse.trace.name\n if (attributes['mastra.metadata.traceName']) {\n attributes['langfuse.trace.name'] = attributes['mastra.metadata.traceName'];\n delete attributes['mastra.metadata.traceName'];\n }\n\n // Trace version: mastra.metadata.version → langfuse.trace.version\n if (attributes['mastra.metadata.version']) {\n attributes['langfuse.trace.version'] = attributes['mastra.metadata.version'];\n delete attributes['mastra.metadata.version'];\n }\n\n // Root-span trace identity: scope each Langfuse trace to the entity that\n // started it (agent or workflow). This makes the Langfuse trace name match\n // the agent/workflow id and exposes the same identity as trace metadata, so\n // users can scope Langfuse evaluators per agent via trace name or metadata\n // filters. User-provided traceName (set via mastra.metadata.traceName) takes\n // precedence and is preserved.\n if (span.isRootSpan) {\n if (span.type === SpanType.AGENT_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.agentId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.agentName'] = span.entityName;\n }\n } else if (span.type === SpanType.WORKFLOW_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.workflowId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.workflowName'] = span.entityName;\n }\n }\n }\n\n // Observation metadata: map semantic attributes to langfuse.observation.metadata.*\n // so they become top-level filterable keys on each observation in Langfuse.\n // @see https://langfuse.com/integrations/native/opentelemetry#how-metadata-mapping-works\n if (attributes['gen_ai.agent.id']) {\n attributes['langfuse.observation.metadata.agentId'] = attributes['gen_ai.agent.id'];\n }\n if (attributes['gen_ai.agent.name']) {\n attributes['langfuse.observation.metadata.agentName'] = attributes['gen_ai.agent.name'];\n }\n if (attributes['mastra.span.type']) {\n attributes['langfuse.observation.metadata.spanType'] = attributes['mastra.span.type'];\n }\n if (attributes['gen_ai.operation.name']) {\n attributes['langfuse.observation.metadata.operationName'] = attributes['gen_ai.operation.name'];\n }\n\n // Input/Output: mastra.*.input/output → langfuse.observation.input/output\n // For gen_ai spans, Langfuse reads gen_ai.input.messages natively.\n // For non-gen_ai spans, we map the first mastra.*.input/output we find.\n if (!attributes['gen_ai.input.messages'] && !attributes['gen_ai.tool.call.arguments']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.input')) {\n attributes['langfuse.observation.input'] = attributes[key];\n break;\n }\n }\n }\n if (!attributes['gen_ai.output.messages'] && !attributes['gen_ai.tool.call.result']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.output')) {\n attributes['langfuse.observation.output'] = attributes[key];\n break;\n }\n }\n }\n}\n\n/**\n * Remove trailing \"/\" characters procedurally. Avoids polynomial\n * backtracking that a greedy regex like `/\\/+$/` can exhibit when the\n * input is attacker-controlled.\n */\nfunction stripTrailingSlashes(s: string): string {\n let end = s.length;\n while (end > 0 && s.charCodeAt(end - 1) === 47 /* \"/\" */) {\n end--;\n }\n return end === s.length ? s : s.slice(0, end);\n}\n","/**\n * Langfuse Tracing Options Helpers\n *\n * These helpers integrate with the `buildTracingOptions` pattern from\n * `@mastra/observability` to add Langfuse-specific tracing features.\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * const agent = new Agent({\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\n\nimport type { TracingOptionsUpdater } from '@mastra/observability';\n\n/**\n * Langfuse prompt input - accepts either a Langfuse SDK prompt object\n * or manual fields.\n */\nexport interface LangfusePromptInput {\n /** Prompt name */\n name?: string;\n /** Prompt version */\n version?: number;\n /** @deprecated Langfuse v5 only supports linking by name + version. This field is ignored. */\n id?: string;\n}\n\n/**\n * Adds Langfuse prompt metadata to the tracing options\n * to enable Langfuse Prompt Tracing.\n *\n * The metadata is added under `metadata.langfuse.prompt` and includes:\n * - `name` - Prompt name (required for Langfuse v5)\n * - `version` - Prompt version (required for Langfuse v5)\n *\n * All fields are deeply merged with any existing metadata.\n *\n * @param prompt - Prompt fields for linking (`name` and `version` required)\n * @returns A TracingOptionsUpdater function for use with `buildTracingOptions`\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * // Link a generation to a Langfuse prompt by name and version\n * const tracingOptions = buildTracingOptions(\n * withLangfusePrompt({ name: 'customer-support', version: 1 }),\n * );\n *\n * // Or directly in agent config\n * const agent = new Agent({\n * name: 'support-agent',\n * instructions: 'You are a helpful assistant',\n * model: openai('gpt-4o'),\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\nexport function withLangfusePrompt(prompt: LangfusePromptInput): TracingOptionsUpdater {\n return opts => ({\n ...opts,\n metadata: {\n ...opts.metadata,\n langfuse: {\n ...(opts.metadata?.langfuse as Record<string, unknown>),\n prompt: {\n ...(prompt.name !== undefined && { name: prompt.name }),\n ...(prompt.version !== undefined && { version: prompt.version }),\n ...(prompt.id !== undefined && { id: prompt.id }),\n },\n },\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/tracing.ts","../src/helpers.ts"],"names":[],"mappings":";;;;;;;AAiBA,IAAM,UAAA,GAAa,oBAAA;AAEZ,IAAM,yBAAA,GAA4B;AAqBlC,IAAM,gBAAA,GAAN,cAA+B,YAAA,CAAa;AAAA,EACjD,IAAA,GAAO,UAAA;AAAA,EACP,UAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,SAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EAEA,WAAA,CAAY,MAAA,GAAiC,EAAC,EAAG;AAC/C,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,mBAAA;AAClD,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,mBAAA;AAClD,IAAA,MAAM,UAAU,oBAAA,CAAqB,MAAA,CAAO,WAAW,OAAA,CAAQ,GAAA,CAAI,qBAAqB,yBAAyB,CAAA;AACjH,IAAA,IAAA,CAAK,SAAA,GAAY,OAAO,QAAA,IAAY,KAAA;AAEpC,IAAA,IAAI,CAAC,SAAA,IAAa,CAAC,SAAA,EAAW;AAC5B,MAAA,MAAM,kBAAkB,MA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AA,UAC9D,GAAI,MAAA,CAAO,EAAA,KAAO,UAAa,EAAE,EAAA,EAAI,OAAO,EAAA;AAAG;AACjD;AACF;AACF,GACF,CAAA;AACF","file":"index.js","sourcesContent":["/**\n * Langfuse Exporter for Mastra Observability\n *\n * Sends observability data to Langfuse using the official @langfuse/otel span processor\n * and @langfuse/client for non-tracing features (scoring, prompt management, evaluations).\n *\n * @see https://langfuse.com/docs/observability/sdk/typescript/overview\n */\n\nimport { LangfuseClient } from '@langfuse/client';\nimport { LangfuseSpanProcessor } from '@langfuse/otel';\nimport type { TracingEvent, AnyExportedSpan, InitExporterOptions, ScoreEvent } from '@mastra/core/observability';\nimport { SpanType, TracingEventType } from '@mastra/core/observability';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { SpanConverter } from '@mastra/otel-exporter';\n\nconst LOG_PREFIX = '[LangfuseExporter]';\n\nexport const LANGFUSE_DEFAULT_BASE_URL = 'https://cloud.langfuse.com';\n\nexport interface LangfuseExporterConfig extends BaseExporterConfig {\n /** Langfuse public key */\n publicKey?: string;\n /** Langfuse secret key */\n secretKey?: string;\n /** Langfuse host URL (defaults to https://cloud.langfuse.com) */\n baseUrl?: string;\n /** Enable realtime mode - flushes after each event for immediate visibility */\n realtime?: boolean;\n /** Maximum number of spans per OTEL export batch */\n flushAt?: number;\n /** Maximum time in seconds before pending spans are exported */\n flushInterval?: number;\n /** Langfuse environment tag for traces */\n environment?: string;\n /** Langfuse release tag for traces */\n release?: string;\n}\n\nexport class LangfuseExporter extends BaseExporter {\n name = 'langfuse';\n #processor: LangfuseSpanProcessor | undefined;\n #client: LangfuseClient | undefined;\n #spanConverter: SpanConverter | undefined;\n #realtime: boolean;\n #environment: string | undefined;\n #release: string | undefined;\n\n constructor(config: LangfuseExporterConfig = {}) {\n super(config);\n\n const publicKey = config.publicKey ?? process.env.LANGFUSE_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.LANGFUSE_SECRET_KEY;\n const baseUrl = stripTrailingSlashes(config.baseUrl ?? process.env.LANGFUSE_BASE_URL ?? LANGFUSE_DEFAULT_BASE_URL);\n this.#realtime = config.realtime ?? false;\n\n if (!publicKey || !secretKey) {\n const publicKeySource = config.publicKey\n ? 'from config'\n : process.env.LANGFUSE_PUBLIC_KEY\n ? 'from env'\n : 'missing';\n const secretKeySource = config.secretKey\n ? 'from config'\n : process.env.LANGFUSE_SECRET_KEY\n ? 'from env'\n : 'missing';\n this.setDisabled(\n `${LOG_PREFIX} Missing required credentials (publicKey: ${publicKeySource}, secretKey: ${secretKeySource}). ` +\n `Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY environment variables or pass them in config.`,\n );\n return;\n }\n\n this.#processor = new LangfuseSpanProcessor({\n publicKey,\n secretKey,\n baseUrl,\n environment: config.environment,\n release: config.release,\n exportMode: this.#realtime ? 'immediate' : 'batched',\n flushAt: config.flushAt,\n flushInterval: config.flushInterval,\n // Export all spans — the default filter only passes spans with gen_ai.* attributes\n // or known LLM instrumentation scopes, but Mastra spans use mastra.* attributes.\n shouldExportSpan: () => true,\n });\n\n this.#client = new LangfuseClient({\n publicKey,\n secretKey,\n baseUrl,\n });\n\n this.#environment = config.environment ?? process.env.LANGFUSE_TRACING_ENVIRONMENT;\n this.#release = config.release ?? process.env.LANGFUSE_RELEASE;\n }\n\n init(options: InitExporterOptions) {\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: options.config?.serviceName,\n format: 'GenAI_v1_38_0',\n });\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.type !== TracingEventType.SPAN_ENDED) return;\n if (!this.#processor) return;\n\n await this.exportSpan(event.exportedSpan);\n }\n\n private async exportSpan(span: AnyExportedSpan): Promise<void> {\n if (!this.#spanConverter) {\n // Fallback if init() was not called (e.g., standalone usage without Mastra)\n this.#spanConverter = new SpanConverter({\n packageName: '@mastra/langfuse',\n serviceName: 'mastra-service',\n format: 'GenAI_v1_38_0',\n });\n }\n\n try {\n const otelSpan = await this.#spanConverter.convertSpan(span);\n\n // Map mastra.* attributes to langfuse.* namespace so that Langfuse's OTLP\n // endpoint reads them correctly. SpanConverter produces mastra.* attributes,\n // but Langfuse only reads langfuse.* attributes for prompt linking, TTFT, etc.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n mapMastraToLangfuseAttributes(otelSpan.attributes, span, this.#environment, this.#release);\n\n this.#processor!.onEnd(otelSpan);\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Failed to export span ${span.id}:`, error);\n }\n }\n\n /**\n * The LangfuseClient instance for advanced Langfuse features.\n * Use this for prompt management, evaluations, datasets, and direct API access.\n */\n get client(): LangfuseClient | undefined {\n return this.#client;\n }\n\n /**\n * Submit a score to Langfuse. Used by both the new `onScoreEvent` path and the\n * deprecated `addScoreToTrace` wrapper.\n */\n private submitScore(args: {\n id: string;\n traceId: string;\n spanId?: string;\n name: string;\n value: number;\n comment?: string;\n metadata?: Record<string, unknown>;\n }): void {\n if (!this.#client) return;\n\n const { id, traceId, spanId, name, value, comment, metadata } = args;\n try {\n this.#client.score.create({\n id,\n traceId,\n ...(spanId ? { observationId: spanId } : {}),\n name,\n value,\n ...(comment ? { comment } : {}),\n ...(metadata ? { metadata } : {}),\n dataType: 'NUMERIC' as const,\n });\n } catch (error) {\n this.logger.error(`${LOG_PREFIX} Error submitting score`, {\n error,\n traceId,\n spanId,\n name,\n });\n }\n }\n\n async onScoreEvent(event: ScoreEvent): Promise<void> {\n const { score } = event;\n if (!score.traceId) return;\n this.submitScore({\n id: score.scoreId,\n traceId: score.traceId,\n spanId: score.spanId,\n name: score.scorerName ?? score.scorerId,\n value: score.score,\n comment: score.reason,\n metadata: score.metadata,\n });\n }\n\n /**\n * @deprecated Use the observability score event pipeline (`mastra.observability.addScore`)\n * instead. This method is preserved for backwards compatibility and forwards to the same\n * underlying client call as `onScoreEvent`.\n */\n async addScoreToTrace({\n traceId,\n spanId,\n score,\n reason,\n scorerName,\n metadata,\n }: {\n traceId: string;\n spanId?: string;\n score: number;\n reason?: string;\n scorerName: string;\n metadata?: Record<string, any>;\n }): Promise<void> {\n this.submitScore({\n id: `${traceId}-${spanId || ''}-${scorerName}`,\n traceId,\n spanId,\n name: scorerName,\n value: score,\n comment: reason,\n metadata,\n });\n }\n\n async flush(): Promise<void> {\n await Promise.all([this.#processor?.forceFlush(), this.#client?.flush()]);\n }\n\n async shutdown(): Promise<void> {\n await Promise.all([this.#processor?.shutdown(), this.#client?.shutdown()]);\n }\n}\n\n/**\n * Maps Mastra-specific OTel attributes to the langfuse.* namespace that\n * Langfuse's OTLP endpoint reads for prompt linking, TTFT, and other features.\n *\n * SpanConverter produces attributes like mastra.metadata.*, mastra.completion_start_time, etc.\n * Langfuse's OTLP server only reads langfuse.observation.prompt.name, langfuse.observation.completion_start_time, etc.\n *\n * This function mutates the attributes object in place.\n * @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n */\nfunction mapMastraToLangfuseAttributes(\n attributes: Record<string, any>,\n span: AnyExportedSpan,\n environment?: string,\n release?: string,\n): void {\n // Environment and release: set directly since onStart() is not called\n if (environment) {\n attributes['langfuse.environment'] = environment;\n }\n if (release) {\n attributes['langfuse.release'] = release;\n }\n\n // mastra.metadata.langfuse holds a user-supplied object with two kinds of keys:\n // - the reserved `prompt` key, used for prompt linking, and\n // - arbitrary custom keys the user wants as top-level, filterable trace metadata.\n // Langfuse only allows filtering/grouping traces by top-level metadata\n // (langfuse.trace.metadata.*), so forward every non-prompt key there. These\n // attributes may be set on any span in the trace and land on the trace record.\n // @see https://langfuse.com/integrations/native/opentelemetry#property-mapping\n const langfuseMetadata = attributes['mastra.metadata.langfuse'];\n if (langfuseMetadata) {\n try {\n const parsed = typeof langfuseMetadata === 'string' ? JSON.parse(langfuseMetadata) : langfuseMetadata;\n if (parsed && typeof parsed === 'object') {\n // Prompt linking: mastra.metadata.langfuse.prompt → langfuse.observation.prompt.name / version\n if (parsed.prompt) {\n if (parsed.prompt.name !== undefined) {\n attributes['langfuse.observation.prompt.name'] = parsed.prompt.name;\n }\n if (parsed.prompt.version !== undefined) {\n attributes['langfuse.observation.prompt.version'] = parsed.prompt.version;\n }\n }\n\n // Custom keys: mastra.metadata.langfuse.<key> → langfuse.trace.metadata.<key>\n // Reserved identity keys (agentId/agentName/workflowId/workflowName) are set\n // by the root-span block below, which runs after this loop and takes precedence.\n for (const [key, value] of Object.entries(parsed)) {\n if (key === 'prompt' || value === null || value === undefined) {\n continue;\n }\n const traceKey = `langfuse.trace.metadata.${key}`;\n // Don't overwrite a trace.metadata key already mapped from another attribute.\n if (attributes[traceKey] === undefined) {\n // Langfuse maps langfuse.trace.metadata.* as string attributes, so\n // serialize non-strings with JSON. Langfuse Cloud restores numbers,\n // booleans, and objects to their original types on ingestion.\n attributes[traceKey] = typeof value === 'string' ? value : JSON.stringify(value);\n }\n }\n }\n } catch {\n // best effort — invalid JSON is silently ignored\n }\n delete attributes['mastra.metadata.langfuse'];\n }\n\n // TTFT: mastra.completion_start_time → langfuse.observation.completion_start_time\n if (attributes['mastra.completion_start_time']) {\n attributes['langfuse.observation.completion_start_time'] = attributes['mastra.completion_start_time'];\n delete attributes['mastra.completion_start_time'];\n }\n\n // User ID: mastra.metadata.userId → user.id\n if (attributes['mastra.metadata.userId']) {\n attributes['user.id'] = attributes['mastra.metadata.userId'];\n delete attributes['mastra.metadata.userId'];\n }\n\n // Session ID: mastra.metadata.sessionId or threadId → session.id\n const sessionId = attributes['mastra.metadata.sessionId'] ?? attributes['mastra.metadata.threadId'];\n if (sessionId) {\n attributes['session.id'] = sessionId;\n delete attributes['mastra.metadata.sessionId'];\n delete attributes['mastra.metadata.threadId'];\n }\n\n // Tags: mastra.tags → langfuse.trace.tags\n if (attributes['mastra.tags']) {\n attributes['langfuse.trace.tags'] = attributes['mastra.tags'];\n delete attributes['mastra.tags'];\n }\n\n // Trace name: mastra.metadata.traceName → langfuse.trace.name\n if (attributes['mastra.metadata.traceName']) {\n attributes['langfuse.trace.name'] = attributes['mastra.metadata.traceName'];\n delete attributes['mastra.metadata.traceName'];\n }\n\n // Trace version: mastra.metadata.version → langfuse.trace.version\n if (attributes['mastra.metadata.version']) {\n attributes['langfuse.trace.version'] = attributes['mastra.metadata.version'];\n delete attributes['mastra.metadata.version'];\n }\n\n // Root-span trace identity: scope each Langfuse trace to the entity that\n // started it (agent or workflow). This makes the Langfuse trace name match\n // the agent/workflow id and exposes the same identity as trace metadata, so\n // users can scope Langfuse evaluators per agent via trace name or metadata\n // filters. User-provided traceName (set via mastra.metadata.traceName) takes\n // precedence and is preserved.\n if (span.isRootSpan) {\n if (span.type === SpanType.AGENT_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.agentId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.agentName'] = span.entityName;\n }\n } else if (span.type === SpanType.WORKFLOW_RUN) {\n if (!attributes['langfuse.trace.name'] && (span.entityName || span.entityId)) {\n attributes['langfuse.trace.name'] = span.entityName ?? span.entityId;\n }\n if (span.entityId) {\n attributes['langfuse.trace.metadata.workflowId'] = span.entityId;\n }\n if (span.entityName) {\n attributes['langfuse.trace.metadata.workflowName'] = span.entityName;\n }\n }\n }\n\n // Observation metadata: map semantic attributes to langfuse.observation.metadata.*\n // so they become top-level filterable keys on each observation in Langfuse.\n // @see https://langfuse.com/integrations/native/opentelemetry#how-metadata-mapping-works\n if (attributes['gen_ai.agent.id']) {\n attributes['langfuse.observation.metadata.agentId'] = attributes['gen_ai.agent.id'];\n }\n if (attributes['gen_ai.agent.name']) {\n attributes['langfuse.observation.metadata.agentName'] = attributes['gen_ai.agent.name'];\n }\n if (attributes['mastra.span.type']) {\n attributes['langfuse.observation.metadata.spanType'] = attributes['mastra.span.type'];\n }\n if (attributes['gen_ai.operation.name']) {\n attributes['langfuse.observation.metadata.operationName'] = attributes['gen_ai.operation.name'];\n }\n\n // Input/Output: mastra.*.input/output → langfuse.observation.input/output\n // For gen_ai spans, Langfuse reads gen_ai.input.messages natively.\n // For non-gen_ai spans, we map the first mastra.*.input/output we find.\n if (!attributes['gen_ai.input.messages'] && !attributes['gen_ai.tool.call.arguments']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.input')) {\n attributes['langfuse.observation.input'] = attributes[key];\n break;\n }\n }\n }\n if (!attributes['gen_ai.output.messages'] && !attributes['gen_ai.tool.call.result']) {\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('mastra.') && key.endsWith('.output')) {\n attributes['langfuse.observation.output'] = attributes[key];\n break;\n }\n }\n }\n}\n\n/**\n * Remove trailing \"/\" characters procedurally. Avoids polynomial\n * backtracking that a greedy regex like `/\\/+$/` can exhibit when the\n * input is attacker-controlled.\n */\nfunction stripTrailingSlashes(s: string): string {\n let end = s.length;\n while (end > 0 && s.charCodeAt(end - 1) === 47 /* \"/\" */) {\n end--;\n }\n return end === s.length ? s : s.slice(0, end);\n}\n","/**\n * Langfuse Tracing Options Helpers\n *\n * These helpers integrate with the `buildTracingOptions` pattern from\n * `@mastra/observability` to add Langfuse-specific tracing features.\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * const agent = new Agent({\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\n\nimport type { TracingOptionsUpdater } from '@mastra/observability';\n\n/**\n * Langfuse prompt input - accepts either a Langfuse SDK prompt object\n * or manual fields.\n */\nexport interface LangfusePromptInput {\n /** Prompt name */\n name?: string;\n /** Prompt version */\n version?: number;\n /** @deprecated Langfuse v5 only supports linking by name + version. This field is ignored. */\n id?: string;\n}\n\n/**\n * Adds Langfuse prompt metadata to the tracing options\n * to enable Langfuse Prompt Tracing.\n *\n * The metadata is added under `metadata.langfuse.prompt` and includes:\n * - `name` - Prompt name (required for Langfuse v5)\n * - `version` - Prompt version (required for Langfuse v5)\n *\n * All fields are deeply merged with any existing metadata.\n *\n * @param prompt - Prompt fields for linking (`name` and `version` required)\n * @returns A TracingOptionsUpdater function for use with `buildTracingOptions`\n *\n * @example\n * ```typescript\n * import { buildTracingOptions } from '@mastra/observability';\n * import { withLangfusePrompt } from '@mastra/langfuse';\n *\n * // Link a generation to a Langfuse prompt by name and version\n * const tracingOptions = buildTracingOptions(\n * withLangfusePrompt({ name: 'customer-support', version: 1 }),\n * );\n *\n * // Or directly in agent config\n * const agent = new Agent({\n * name: 'support-agent',\n * instructions: 'You are a helpful assistant',\n * model: openai('gpt-4o'),\n * defaultGenerateOptions: {\n * tracingOptions: buildTracingOptions(\n * withLangfusePrompt({ name: 'my-prompt', version: 1 }),\n * ),\n * },\n * });\n * ```\n */\nexport function withLangfusePrompt(prompt: LangfusePromptInput): TracingOptionsUpdater {\n return opts => ({\n ...opts,\n metadata: {\n ...opts.metadata,\n langfuse: {\n ...(opts.metadata?.langfuse as Record<string, unknown>),\n prompt: {\n ...(prompt.name !== undefined && { name: prompt.name }),\n ...(prompt.version !== undefined && { version: prompt.version }),\n ...(prompt.id !== undefined && { id: prompt.id }),\n },\n },\n },\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/langfuse",
|
|
3
|
-
"version": "1.3.5
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Langfuse observability provider for Mastra - uses official Langfuse v5 SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@langfuse/client": "^5.0.2",
|
|
28
28
|
"@langfuse/otel": "^5.0.2",
|
|
29
29
|
"@mastra/observability": "1.14.1",
|
|
30
|
-
"@mastra/otel-exporter": "1.2.2
|
|
30
|
+
"@mastra/otel-exporter": "1.2.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@opentelemetry/api": "^1.9.1",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"tsup": "^8.5.1",
|
|
40
40
|
"typescript": "^6.0.3",
|
|
41
41
|
"vitest": "4.1.5",
|
|
42
|
-
"@internal/lint": "0.0.
|
|
43
|
-
"@internal/types-builder": "0.0.
|
|
44
|
-
"@mastra/core": "1.42.0
|
|
42
|
+
"@internal/lint": "0.0.104",
|
|
43
|
+
"@internal/types-builder": "0.0.79",
|
|
44
|
+
"@mastra/core": "1.42.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@mastra/core": ">=1.16.0-0 <2.0.0-0",
|