( spans: TraceSpan[], pattern: string, ctx: LogViewContext, opts?: GrepSpansOptions )
| 307 | * the ref preview). Only bounded match snippets are accumulated. |
| 308 | */ |
| 309 | export async function grepSpans( |
| 310 | spans: TraceSpan[], |
| 311 | pattern: string, |
| 312 | ctx: LogViewContext, |
| 313 | opts?: GrepSpansOptions |
| 314 | ): Promise<GrepSpansResult> { |
| 315 | const state: GrepState = { |
| 316 | matches: [], |
| 317 | slicesScanned: 0, |
| 318 | truncated: false, |
| 319 | maxMatches: opts?.maxMatches ?? DEFAULT_MAX_MATCHES, |
| 320 | maxSnippetChars: opts?.maxSnippetChars ?? DEFAULT_MAX_SNIPPET_CHARS, |
| 321 | maxSlicesScanned: opts?.maxSlicesScanned ?? DEFAULT_MAX_SLICES_SCANNED, |
| 322 | regex: buildRegex(pattern), |
| 323 | } |
| 324 | |
| 325 | const walk = async (list: TraceSpan[]): Promise<void> => { |
| 326 | for (const span of list) { |
| 327 | if (done(state)) return |
| 328 | recordIfMatch(span.name, 'name', span, state) |
| 329 | recordIfMatch(span.type, 'type', span, state) |
| 330 | if (span.errorMessage) recordIfMatch(span.errorMessage, 'error', span, state) |
| 331 | if (span.input !== undefined) await grepField(span.input, 'input', span, ctx, state) |
| 332 | if (span.output !== undefined) await grepField(span.output, 'output', span, ctx, state) |
| 333 | if (span.children && span.children.length > 0) await walk(span.children) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | await walk(spans) |
| 338 | return { matches: state.matches, truncated: state.truncated } |
| 339 | } |
no test coverage detected