MCPcopy
hub / github.com/promptfoo/promptfoo / loadTraceData

Function loadTraceData

src/assertions/index.ts:180–224  ·  view source on GitHub ↗
(traceId: string)

Source from the content-addressed store, hash-verified

178}
179
180async 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
226const ASSERTION_HANDLERS: Record<
227 BaseAssertionTypes,

Callers 2

runAssertionFunction · 0.85
runAssertionsFunction · 0.85

Calls 4

getTraceStoreFunction · 0.90
getEnvIntFunction · 0.90
sleepFunction · 0.90
getTraceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…