{"record":{"id":"042f8402fe369e4d","repo":"mastra-ai/mastra","slug":"observability-update-span-not-found","errorCode":"OBSERVABILITY_UPDATE_SPAN_NOT_FOUND","errorMessage":"Trace not found for span update","messagePattern":"Trace not found for span update","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/observability/inmemory.ts","lineNumber":1079,"sourceCode":"      for (const tag of filters.tags) {\n        if (!span.tags.includes(tag)) return false;\n      }\n    }\n\n    if (filters.status !== undefined) {\n      const spanStatus = toTraceSpan(span).status;\n      if (spanStatus !== filters.status) return false;\n    }\n\n    return true;\n  }\n\n  async updateSpan(args: UpdateSpanArgs): Promise<void> {\n    const { traceId, spanId, updates } = args;\n    const traceEntry = this.db.traces.get(traceId);\n\n    if (!traceEntry) {\n      throw new MastraError({\n        id: 'OBSERVABILITY_UPDATE_SPAN_NOT_FOUND',\n        domain: ErrorDomain.MASTRA_OBSERVABILITY,\n        category: ErrorCategory.SYSTEM,\n        text: 'Trace not found for span update',\n      });\n    }\n\n    const span = traceEntry.spans[spanId];\n    if (!span) {\n      throw new MastraError({\n        id: 'OBSERVABILITY_UPDATE_SPAN_NOT_FOUND',\n        domain: ErrorDomain.MASTRA_OBSERVABILITY,\n        category: ErrorCategory.SYSTEM,\n        text: 'Span not found for update',\n      });\n    }\n\n    const updatedSpan: SpanRecord = {","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/observability/inmemory.ts#L1061-L1097","documentation":"updateSpan looks up the parent trace by traceId before applying updates to a span. If no trace entry exists for that traceId in the in-memory store, it throws this error rather than silently dropping the update — the span's trace was never created or has been evicted.","triggerScenarios":"Calling updateSpan({ traceId, spanId, updates }) where this.db.traces has no entry for traceId (trace never created, already deleted, wrong traceId, or storage restarted losing in-memory state).","commonSituations":"Updating spans after process restart (in-memory store is empty); spans outliving trace retention/deletion; a race where updates arrive before trace creation completes; passing the wrong id (spanId vs traceId) or trace ids from a different storage backend.","solutions":["Ensure the trace is created (createTrace/upserted with its spans) before issuing updateSpan calls.","Check ordering: buffer span updates until trace creation is confirmed, or make updates idempotent after re-creating the trace.","Verify traceId correctness and that you are querying the same storage instance that holds the trace.","For ephemeral in-memory stores, expect state loss on restart — persist traces to a durable provider if updates may outlive the process."],"exampleFix":"// before\nawait storage.updateSpan({ traceId, spanId, updates }); // trace never created -> throws\n\n// after\nawait storage.createTrace({ traceId, ... });\nawait storage.createSpan({ traceId, spanId, ... });\nawait storage.updateSpan({ traceId, spanId, updates });","handlingStrategy":"try-catch","validationCode":"const traceExists = storage instanceof ObservabilityInMemory ? (storage as any).db?.traces?.has(traceId) : true;\nif (!traceExists) await storage.createTrace({ traceId, ... });","typeGuard":"function traceIsKnown(entry: unknown): entry is { traceId: string } {\n  return typeof (entry as any)?.traceId === 'string' && (entry as any).traceId.length > 0;\n}","tryCatchPattern":"try {\n  await storage.updateSpan({ traceId, spanId, updates });\n} catch (e) {\n  if ((e as MastraError).id === 'OBSERVABILITY_UPDATE_SPAN_NOT_FOUND') {\n    logger.warn(`Trace ${traceId} missing; skipping span update`, { spanId });\n  } else throw e;\n}","preventionTips":["Create the trace (and span) before issuing span updates; buffer updates until creation completes.","Remember in-memory storage loses state on restart — use durable storage for long-lived traces.","Verify traceId correctness; don't pass spanId where traceId is expected.","Use the same storage instance for trace creation and span updates."],"tags":["storage","observability","tracing","not-found","in-memory"],"backgroundTag":"record-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}