Skip to content

Function: chatTurnTelemetryMiddleware()

chatTurnTelemetryMiddleware(req, res, next, options?): void

Express middleware that stamps chat turn I/O onto the exported OTel root.

Tee res.write, res.json, and res.end instead of listening for finish: HTTP instrumentation ends its server span on finish, and attributes set after a span ends never reach the exporter.

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

Request

Response

NextFunction

ChatTurnTelemetryOptions = {}

void