|
| 1 | +--- |
| 2 | +"@voltagent/langfuse-exporter": patch |
| 3 | +"@voltagent/core": patch |
| 4 | +--- |
| 5 | + |
| 6 | +feat: Add Langfuse Observability Exporter |
| 7 | + |
| 8 | +This introduces a new package `@voltagent/langfuse-exporter` that allows you to export OpenTelemetry traces generated by `@voltagent/core` directly to Langfuse (https://langfuse.com/) for detailed observability into your agent's operations. |
| 9 | + |
| 10 | +**How to Use:** |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Install the necessary packages: |
| 15 | + |
| 16 | +```bash |
| 17 | +npm install @voltagent/core @voltagent/langfuse-exporter |
| 18 | +# or |
| 19 | +yarn add @voltagent/core @voltagent/langfuse-exporter |
| 20 | +``` |
| 21 | + |
| 22 | +## Configuration |
| 23 | + |
| 24 | +Configure the `LangfuseExporter` and pass it to `VoltAgent`: |
| 25 | + |
| 26 | +```typescript |
| 27 | +import { Agent, VoltAgent } from "@voltagent/core"; |
| 28 | +import { LangfuseExporter } from "@voltagent/langfuse-exporter"; |
| 29 | +// import { YourLLMProvider } from "./your-llm-provider"; // Replace with your provider |
| 30 | +// import { yourModel } from "./your-model"; // Replace with your model |
| 31 | +// import { yourTools } from "./your-tools"; // Replace with your tools |
| 32 | + |
| 33 | +// Ensure LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY are set in your environment |
| 34 | + |
| 35 | +// Define your agent(s) |
| 36 | +const agent = new Agent({ |
| 37 | + name: "MyLangfuseAgent", |
| 38 | + // description: "...", |
| 39 | + // llm: new YourLLMProvider(), |
| 40 | + // model: yourModel, |
| 41 | + // tools: yourTools, |
| 42 | +}); |
| 43 | + |
| 44 | +// Configure the Langfuse Exporter |
| 45 | +const langfuseExporter = new LangfuseExporter({ |
| 46 | + publicKey: process.env.LANGFUSE_PUBLIC_KEY, |
| 47 | + secretKey: process.env.LANGFUSE_SECRET_KEY, |
| 48 | + baseUrl: process.env.LANGFUSE_BASE_URL, // Optional: Defaults to Langfuse Cloud |
| 49 | + // debug: true // Optional: Enable exporter logging |
| 50 | +}); |
| 51 | + |
| 52 | +// Initialize VoltAgent with the exporter |
| 53 | +// This automatically sets up OpenTelemetry tracing |
| 54 | +new VoltAgent({ |
| 55 | + agents: { |
| 56 | + agent, // Register your agent(s) |
| 57 | + }, |
| 58 | + telemetryExporter: langfuseExporter, // Pass the exporter instance |
| 59 | +}); |
| 60 | + |
| 61 | +console.log("VoltAgent initialized with Langfuse exporter."); |
| 62 | + |
| 63 | +// Now, any operations performed by 'agent' (e.g., agent.generateText(...)) |
| 64 | +// will automatically generate traces and send them to Langfuse. |
| 65 | +``` |
| 66 | + |
| 67 | +By providing the `telemetryExporter` to `VoltAgent`, OpenTelemetry is automatically configured, and detailed traces including LLM interactions, tool usage, and agent metadata will appear in your Langfuse project. |
0 commit comments