{"record":{"id":"56dfe8741831409c","repo":"mastra-ai/mastra","slug":"trace-not-found-for-scoring-traceid-target-tra","errorCode":null,"errorMessage":"Trace not found for scoring, traceId: ${target.traceId}","messagePattern":"Trace not found for scoring, traceId: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/scoreTraces/scoreTracesWorkflow.ts","lineNumber":186,"sourceCode":"    return {\n      trace: target.trace,\n      span: resolveTargetSpan({ trace: target.trace, spanId: target.spanId }),\n    };\n  }\n\n  // TODO: add storage api to get a single span\n  const observabilityStore = await storage.getStore('observability');\n  if (!observabilityStore) {\n    throw new MastraError({\n      id: 'MASTRA_OBSERVABILITY_STORAGE_NOT_AVAILABLE',\n      domain: ErrorDomain.STORAGE,\n      category: ErrorCategory.SYSTEM,\n      text: 'Observability storage domain is not available',\n    });\n  }\n  const trace = await observabilityStore.getTrace({ traceId: target.traceId });\n  if (!trace) {\n    throw new Error(`Trace not found for scoring, traceId: ${target.traceId}`);\n  }\n\n  return { trace, span: resolveTargetSpan({ trace, spanId: target.spanId }) };\n}\n\ntype TraceScoreResult = Awaited<ReturnType<MastraScorer['run']>>;\n\n/**\n * Run a scorer against an already-resolved trace + span.\n *\n * Span tenancy (`organizationId`, `resourceId` → `projectId`) is threaded into\n * the scorer run so any score the scorer emits is correctly multi-tenant.\n */\nasync function runScorerForTrace({\n  scorer,\n  trace,\n  span,\n}: {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/scoreTraces/scoreTracesWorkflow.ts#L168-L204","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait score({ target: { traceId: 'hardcoded-trace-id' } });\n// after: use the id from the actual run\nconst result = await run.start({ inputData });\nawait score({ target: { traceId: result.traceId } });","handlingStrategy":"validation","validationCode":"// confirm the trace exists before scoring\nconst store = await storage.getStore('observability');\nconst trace = await store?.getTrace({ traceId });\nif (!trace) throw new Error(`Trace ${traceId} not persisted; check tracing config and retention`);","typeGuard":"async function traceIsScorable(storage, traceId) {\n  const store = await storage.getStore('observability');\n  if (!store) return false;\n  const trace = await store.getTrace({ traceId });\n  return trace != null && trace.spans.length > 0;\n}","tryCatchPattern":"try {\n  await scoreTraces({ target: { traceId } });\n} catch (e) {\n  if (typeof e.message === 'string' && e.message.startsWith('Trace not found for scoring')) {\n    console.error(`Trace ${traceId} missing — was tracing enabled and retention sufficient?`);\n  }\n  throw e;\n}","preventionTips":["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)"],"tags":["observability","tracing","storage","score-traces"],"backgroundTag":"trace-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}