Skip to content

Commit 4a79372

Browse files
authored
feat(trace): add advanced span filters (#2466)
resolves https://linear.app/braintrustdata/issue/SDK-343/add-filters-on-traceget-spans-to-javascript-sdk Add `filters` to `Trace.getSpans()` so callers can select spans by type, name, error state, partial metadata, and duration without fetching the whole trace and filtering it themselves. ```typescript const spans = await trace.getSpans({ filters: { spanType: ["tool"], name: ["search", "lookup"], hasError: true, metadata: { model: "gpt-5" }, duration: { min: 0.5, max: 10 }, }, }); ``` Combine filter dimensions with AND and match any value within each name or span-type list. Duration bounds are inclusive and measured in seconds. Keep the existing top-level `spanType` option supported. Apply consistent filtering to buffered spans, complete trace caches, and BTQL queries. Validate metadata as cycle-free JSON data, check returned metadata candidates locally to avoid backend type coercion, and avoid caching partial filtered results as complete traces.
1 parent a2526e7 commit 4a79372

4 files changed

Lines changed: 861 additions & 131 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"braintrust": minor
3+
---
4+
5+
feat: Add advanced filters to `Trace.getSpans()`

‎js/src/exports.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,13 @@ export {
319319
PromptDefinitionWithTools,
320320
} from "./prompt-schemas";
321321

322-
export type { Trace, SpanData, GetThreadOptions } from "./trace";
322+
export type {
323+
Trace,
324+
SpanData,
325+
SpanDurationFilter,
326+
SpanFilters,
327+
GetThreadOptions,
328+
} from "./trace";
323329
export { SpanFetcher, CachedSpanFetcher, LocalTrace } from "./trace";
324330

325331
export type {

0 commit comments

Comments
 (0)