Skip to content

Function: chatTurnTraceIoMiddleware()

chatTurnTraceIoMiddleware(req, res, next): void

Express middleware that stamps chat turn I/O onto the active OTel span.

Tee res.write / res.end instead of listening for finish: the HTTP instrumentation ends the root span on finish, and an attribute set after a span ends never reaches the exporter.

path is mount-relative (what the Mastra sub-app sees), e.g. /agents/support/stream.

Request

Response

NextFunction

void