mastra-ai/mastra · error · Error
Trace not found for scoring, traceId
Error message
Trace not found for scoring, traceId: ${target.traceId} What it means
After obtaining the observability store, resolveTraceAndSpan calls observabilityStore.getTrace({ traceId }); when no trace record exists for that id it throws this plain Error. Scoring by trace reference requires the trace to still be present in observability storage.
Solutions
- Verify the traceId by fetching it: await storage.getStore('observability').getTrace({ traceId }).
- Confirm tracing/observability is enabled and traces are persisted to the configured storage.
- Check retention/TTL settings if the trace is old.
- Ensure you're querying the same storage/environment the trace was written to.
- Correct the traceId source — get it from workflowResult.traceId / run traces rather than hardcoding.
Example fix
// before
await score({ target: { traceId: 'hardcoded-trace-id' } });
// after: use the id from the actual run
const result = await run.start({ inputData });
await score({ target: { traceId: result.traceId } }); Defensive patterns
Strategy: validation
Validate before calling
// confirm the trace exists before scoring
const store = await storage.getStore('observability');
const trace = await store?.getTrace({ traceId });
if (!trace) throw new Error(`Trace ${traceId} not persisted; check tracing config and retention`); Type guard
async function traceIsScorable(storage, traceId) {
const store = await storage.getStore('observability');
if (!store) return false;
const trace = await store.getTrace({ traceId });
return trace != null && trace.spans.length > 0;
} Try / catch
try {
await scoreTraces({ target: { traceId } });
} catch (e) {
if (typeof e.message === 'string' && e.message.startsWith('Trace not found for scoring')) {
console.error(`Trace ${traceId} missing — was tracing enabled and retention sufficient?`);
}
throw e;
} Prevention
- Take traceIds from run results (result.traceId), not hardcoded values
- Keep observability tracing enabled in the environment doing the scoring
- Set retention longer than your scoring lag
- Confirm storage/environment parity (dev traceId vs prod storage)
When it happens
Trigger: scoreTraces workflow invoked with target { traceId } where the traceId was never persisted (tracing disabled), was pruned by retention, belongs to a different environment/storage, or the id is mistyped.
Common situations: Passing a traceId from local dev against a staging database; observability exporter not configured so traces never persist; retention TTL expired the trace; typo'd or fabricated traceId; storage region/project mismatch in multi-tenant setups.
Related errors
- MASTRA_OBSERVABILITY_STORAGE_NOT_AVAILABLE
- OBSERVABILITY_CREATE_SPAN_NOT_IMPLEMENTED
- OBSERVABILITY_SPAN_ID_REQUIRED
- OBSERVABILITY_STORAGE_BATCH_CREATE_SPAN_NOT_IMPLEMENTED
- OBSERVABILITY_STORAGE_GET_ROOT_SPAN_NOT_IMPLEMENTED
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/56dfe8741831409c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/core/src/evals/scoreTraces/scoreTracesWorkflow.ts:186
return {
trace: target.trace,
span: resolveTargetSpan({ trace: target.trace, spanId: target.spanId }),
};
}
// TODO: add storage api to get a single span
const observabilityStore = await storage.getStore('observability');
if (!observabilityStore) {
throw new MastraError({
id: 'MASTRA_OBSERVABILITY_STORAGE_NOT_AVAILABLE',
domain: ErrorDomain.STORAGE,
category: ErrorCategory.SYSTEM,
text: 'Observability storage domain is not available',
});
}
const trace = await observabilityStore.getTrace({ traceId: target.traceId });
if (!trace) {
throw new Error(`Trace not found for scoring, traceId: ${target.traceId}`);
}
return { trace, span: resolveTargetSpan({ trace, spanId: target.spanId }) };
}
type TraceScoreResult = Awaited<ReturnType<MastraScorer['run']>>;
/**
* Run a scorer against an already-resolved trace + span.
*
* Span tenancy (`organizationId`, `resourceId` → `projectId`) is threaded into
* the scorer run so any score the scorer emits is correctly multi-tenant.
*/
async function runScorerForTrace({
scorer,
trace,
span,
}: {View on GitHub (pinned to 75dd419e61)