跳至主要內容

Laminar exporter

Laminar 是一個開源、以 OpenTelemetry 為基礎的 AI Agent 可觀測性平台。只需在 Observability 配置中接入一個 MastraExporter,即可追蹤、偵錯及監察每次 Mastra Agent 執行、模型步驟、Tool 呼叫及子 Agent。

安裝
安裝 的直接連結

npm install @lmnr-ai/lmnr

配置
配置 的直接連結

先決條件
先決條件 的直接連結

  1. Laminar 項目:在 Laminar 建立或選擇一個項目
  2. 項目 API 金鑰:從 Laminar Project Settings 複製
  3. 環境變數:設定你的憑證
.env
# Required
LMNR_PROJECT_API_KEY=lmnr_...

# Optional
LMNR_BASE_URL=https://api.lmnr.ai

零配置設定
零配置設定 的直接連結

設定環境變數後,無需提供任何配置即可使用 exporter:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { Observability } from '@mastra/observability'
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'

Laminar.initialize()

export const mastra = new Mastra({
observability: new Observability({
configs: {
laminar: {
serviceName: 'my-service',
exporters: [new MastraExporter()],
},
},
}),
})

明確配置
明確配置 的直接連結

你亦可直接傳入憑證(其優先級高於環境變數):

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { Observability } from '@mastra/observability'
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'

Laminar.initialize({
projectApiKey: process.env.LMNR_PROJECT_API_KEY!,
baseUrl: process.env.LMNR_BASE_URL, // Optional
// ...other options
})

export const mastra = new Mastra({
observability: new Observability({
configs: {
laminar: {
serviceName: 'my-service',
exporters: [
new MastraExporter({
realtime: process.env.NODE_ENV === 'development', // Optional
}),
],
},
},
}),
})
備註

如需了解進階用法,包括完整的 MastraExporter 選項及多 Agent Trace 範例,請參閱 Laminar 的 Mastra 整合指南

Mastra 亦在 @mastra/laminar 中提供獨立的 LaminarExporter,透過 OTLP/HTTP 傳送 span。它無法繼承有效的 OTel context,也不會將 Mastra span 完整映射至 Laminar 的原生格式。因此,如要使用 observe() wrapper、多 Agent root span,以及在 Laminar 中準確呈現資料,請使用上方的 @lmnr-ai/lmnr 整合。