mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
feat(core): route Chat SDK logs through the Mastra logger (#29392)
## Description
Chat SDK logs from channels now use the Mastra logger, so one app has
one log format, one level, and one redact list. Apps can pass the new
`toChatLogger` export to their adapters, because an app creates its
adapters before the Mastra instance exists.
- `AgentChannels.initialize(mastra)` gives the Chat instance a bridge
that reads `mastra.getLogger()` on each call. `chatOptions.logger` still
overrides it.
- `toChatLogger(logger, { minLevel, component })` is exported from
`@mastra/core/channels`.
- `Mastra.setLogger` and file-based loggers now reach channels.
- `child('CHANNEL')` becomes `child({ component })`, so pino no longer
writes `"0":"C","1":"H",...` on channel logs.
- Chat SDK warnings and errors now reach observability log export. A
failed slash command's `error` record includes the command's text, and
the docs explain this.
- This PR does not add trace ids to Chat SDK logs, because those logs
run outside agent spans.
## Related issue(s)
Fixes #29358
## Type of change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Test update
## Checklist
- [x] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## ELI5
This PR sends Chat SDK logs through Mastra’s logger so they use the same
logging setup as the rest of the app. It also adds a helper that apps
can use to send adapter logs through that logger.
## Changes
- Added `toChatLogger()` and `ToChatLoggerOptions` to
`@mastra/core/channels`. The helper supports a minimum log level and a
component name.
- Set the Chat instance’s default logger to use the current Mastra
logger. `chatOptions.logger` overrides this default.
- Propagated logger updates to registered agent channels and controller
channels. Channel logger children now use a `component` field.
- Made the logger bridge suppress logger failures so they do not
interrupt Chat SDK logging calls.
- Added documentation for adapter logging, log levels, redaction limits,
and slash-command error logs. Added tests for the bridge and channel
logger behavior.
## Checks
- CI, build, and test results: not available.
- Review finding counts: not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
4442de30c1
commit
bb0fcd6211
11 changed files with 582 additions and 10 deletions
Loading…
Add table
Add a link
Reference in a new issue