0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00

Compare commits

...

1 commit

Author SHA1 Message Date
mastra-platform[bot]
3feb69dffc fix(observability): stop deep-copying span metadata twice per context
`getLoggerContext()` and `getMetricsContext()` deep-copied `span.metadata`
before handing it to `LoggerContextImpl` / `MetricsContextImpl`, whose
constructors deep-copy it again. Every logger and metrics context therefore
ran two structured clones of the same object, four per pair, on the ordinary
agent execution path — hundreds per turn for apps that put metadata in
`tracingOptions`.

The factories now pass span metadata straight through. The constructors stay
the single defensive-copy boundary, so emitted log and metric metadata is
still a snapshot that later mutations of the span's metadata cannot change.

The two comments in `spans/base.ts` that attributed the clone to the factory
methods are corrected, so the invariant is documented where it is read.

## Test plan

- [x] `vitest run src/instances/base.test.ts` — 4/4 pass; the two clone-count tests report 2 clones with the fix reverted
- [x] `vitest run src/context/logger.test.ts src/context/metrics.test.ts src/tracing.test.ts` — 139/139 pass
- [x] `vitest run` (full `@mastra/observability` suite) — 1883 pass, 0 fail
- [x] `tsc --noEmit -p tsconfig.json` — clean
- [x] `oxlint --type-aware observability/mastra` — 0 warnings, 0 errors
- [x] core callers: `context-factory.test.ts`, `dual-logger.test.ts`, `observe.test.ts`, `observe-execute.test.ts`, `processor-stream-observability-context.test.ts` — 67/67 pass

Fixes #30665

Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com>
2026-11-17 08:31:45 +00:00
4 changed files with 122 additions and 5 deletions