(traceId: string)
| 178 | } |
| 179 | |
| 180 | async function loadTraceData(traceId: string): Promise<TraceData | null> { |
| 181 | const traceStore = getTraceStore(); |
| 182 | const maxAttempts = Math.min( |
| 183 | MAX_TRACE_FETCH_MAX_ATTEMPTS, |
| 184 | Math.max(1, getEnvInt('PROMPTFOO_TRACE_FETCH_MAX_ATTEMPTS', DEFAULT_TRACE_FETCH_MAX_ATTEMPTS)), |
| 185 | ); |
| 186 | const retryDelayMs = Math.min( |
| 187 | MAX_TRACE_FETCH_RETRY_DELAY_MS, |
| 188 | Math.max( |
| 189 | 0, |
| 190 | getEnvInt('PROMPTFOO_TRACE_FETCH_RETRY_DELAY_MS', DEFAULT_TRACE_FETCH_RETRY_DELAY_MS), |
| 191 | ), |
| 192 | ); |
| 193 | const stablePolls = Math.min( |
| 194 | MAX_TRACE_FETCH_STABLE_POLLS, |
| 195 | Math.max(1, getEnvInt('PROMPTFOO_TRACE_FETCH_STABLE_POLLS', DEFAULT_TRACE_FETCH_STABLE_POLLS)), |
| 196 | ); |
| 197 | |
| 198 | let lastSpanCount = -1; |
| 199 | let stableObservations = 0; |
| 200 | let latestTrace: TraceData | null = null; |
| 201 | |
| 202 | for (let attempt = 0; attempt < maxAttempts; attempt++) { |
| 203 | latestTrace = await traceStore.getTrace(traceId, { sanitizeAttributes: false }); |
| 204 | |
| 205 | const spanCount = latestTrace?.spans?.length ?? 0; |
| 206 | if (spanCount > 0) { |
| 207 | stableObservations = spanCount === lastSpanCount ? stableObservations + 1 : 1; |
| 208 | lastSpanCount = spanCount; |
| 209 | |
| 210 | if (stableObservations >= stablePolls || attempt === maxAttempts - 1) { |
| 211 | return latestTrace; |
| 212 | } |
| 213 | } else { |
| 214 | stableObservations = 0; |
| 215 | lastSpanCount = spanCount; |
| 216 | } |
| 217 | |
| 218 | if (attempt < maxAttempts - 1) { |
| 219 | await sleep(retryDelayMs); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return latestTrace; |
| 224 | } |
| 225 | |
| 226 | const ASSERTION_HANDLERS: Record< |
| 227 | BaseAssertionTypes, |
no test coverage detected
searching dependent graphs…