Skip to main content

可观测性 API

🌐 Observability API

可观测性 API 提供了获取追踪、监控应用性能以及对追踪进行评估评分的方法。这有助于你了解 AI 代理和工作流程的表现情况。

🌐 The Observability API provides methods to retrieve traces, monitor your application's performance, and score traces for evaluation. This helps you understand how your AI agents and workflows are performing.

获取特定跟踪
Direct link to 获取特定跟踪

🌐 Getting a Specific Trace

通过其 ID 检索特定跟踪,包括其所有跨度和详细信息:

🌐 Retrieve a specific trace by its ID, including all its spans and details:

const trace = await mastraClient.getTrace("trace-id-123");

获取带过滤的跟踪
Direct link to 获取带过滤的跟踪

🌐 Getting Traces with Filtering

检索带分页的追踪根跨度列表,可选择性进行过滤:

🌐 Retrieve a paginated list of trace root spans with optional filtering:

const traces = await mastraClient.getTraces({
pagination: {
page: 1,
perPage: 20,
dateRange: {
start: new Date("2024-01-01"),
end: new Date("2024-01-31"),
},
},
filters: {
name: "weather-agent", // Filter by trace name
spanType: "agent", // Filter by span type
entityId: "weather-agent-id", // Filter by entity ID
entityType: "agent", // Filter by entity type
},
});

console.log(`Found ${traces.spans.length} root spans`);
console.log(`Total pages: ${traces.pagination.totalPages}`);

// To get the complete trace with all spans, use getTrace
const completeTrace = await mastraClient.getTrace(traces.spans[0].traceId);

评分痕迹
Direct link to 评分痕迹

🌐 Scoring Traces

使用已注册的评分器对特定痕迹进行评分以进行评估:

🌐 Score specific traces using registered scorers for evaluation:

const result = await mastraClient.score({
scorerName: "answer-relevancy",
targets: [
{ traceId: "trace-1", spanId: "span-1" }, // Score specific span
{ traceId: "trace-2" }, // Score specific span which defaults to the parent span
],
});

按范围获取分数
Direct link to 按范围获取分数

🌐 Getting Scores by Span

检索跟踪中特定时间段的分数:

🌐 Retrieve scores for a specific span within a trace:

const scores = await mastraClient.listScoresBySpan({
traceId: "trace-123",
spanId: "span-456",
page: 1,
perPage: 20,
});

🌐 Related