feat(logging): attach structured JSON logging with sessionId to root logger#63
Merged
Conversation
lyzustc
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
Problem
When running RL rollouts on ACR, logs from user code (
rl_app.py,reward.py) and third-party libraries (migration_bench,httpx) were impossible to correlate in CloudWatch. The upstream SDK'sRequestContextFormatteronly attaches to thebedrock_agentcore.applogger — every other logger in the process used the default text formatter with nosessionId, making it impossible to filter all logs for a single rollout session.Solution
CorrelatedFormatterthat emits structured JSON withsessionIdandrequestIdpulled fromBedrockAgentCoreContext(the public API)AgentCoreRLApp.__init__viaconfigure_logging()— every logger in the process inherits it automaticallylogging.getLogger(__name__)to get full session correlationChanges
src/agentcore_rl_toolkit/logging.py— new module withCorrelatedFormatterandconfigure_logging()src/agentcore_rl_toolkit/app.py— callconfigure_logging()in__init__, switch barelogging.info()to named loggerprint()→logger.info()in reward functions for structured outputlogging.basicConfig(level=DEBUG)) viamin()logicTest plan
tests/test_logging.py) — formatter output, context injection, idempotencyrequestId(migration agent)evaluate_async.py --limit 1, confirmedsessionIdappears in CloudWatch for all loggers (reward,root,__main__,agentcore_rl_toolkit.app) (migration agent)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.