Repository navigation
Commit 4a79372
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
| |||
0 commit comments