feat: add Python logging integration with structured events#147
Merged
Conversation
Add stdlib logging across all four subsystems (context, routing, store, adapters) with structured log messages: - context pipeline: DEBUG for each stage (candidates, scoring, dedup, selection, firewall, sensitivity), INFO for build completion - routing: INFO for route completion with top-k scores - store: DEBUG for append/put/add/search operations - adapters: DEBUG for MCP and A2A conversions Safety: sensitivity filter never logs text content (sensitivity guard). Performance: lazy %s formatting zero cost at default WARNING level. Also updates: - CHANGELOG.md with [Unreleased] entry - AGENTS.md and .claude/CLAUDE.md debugging tips - New test file: tests/test_logging.py (16 tests)
There was a problem hiding this comment.
Pull request overview
This PR adds Python standard library logging integration across all four contextweaver subsystems — context pipeline, routing, store, and adapters — to address the lack of runtime observability (issue #111). It uses lazy %s formatting for zero string-interpolation cost at the default WARNING level, and the sensitivity module deliberately logs only structural metadata (never text content).
Changes:
- Added DEBUG-level log messages at each of the 8 context pipeline stages, store operations, and adapter conversions, plus INFO-level summaries for context builds and route completions
- Added 15 new tests in
tests/test_logging.pycovering logger existence, emission at correct levels, and the sensitivity guard (no text content in logs) - Updated
AGENTS.md,.claude/CLAUDE.md, andCHANGELOG.mdwith debugging tips and release notes
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/contextweaver/context/manager.py |
DEBUG logs for ingest, ingest_tool_result; INFO log for build completion |
src/contextweaver/context/candidates.py |
DEBUG logs for generate_candidates and dependency_closure |
src/contextweaver/context/scoring.py |
DEBUG log for score_candidates with top/bottom scores |
src/contextweaver/context/dedup.py |
DEBUG log for deduplicate_candidates |
src/contextweaver/context/selection.py |
DEBUG log for select_and_pack |
src/contextweaver/context/sensitivity.py |
DEBUG log for sensitivity filter (action, floor, counts only) |
src/contextweaver/context/firewall.py |
DEBUG logs for single-item and batch firewall |
src/contextweaver/routing/router.py |
INFO log for route completion with scores |
src/contextweaver/store/event_log.py |
DEBUG log for append |
src/contextweaver/store/artifacts.py |
DEBUG log for put |
src/contextweaver/store/episodic.py |
DEBUG logs for add and search |
src/contextweaver/store/facts.py |
DEBUG log for put |
src/contextweaver/adapters/mcp.py |
DEBUG logs for mcp_tool_to_selectable and mcp_result_to_envelope |
src/contextweaver/adapters/a2a.py |
DEBUG logs for a2a_agent_to_selectable and a2a_result_to_envelope |
tests/test_logging.py |
15 new tests for logging across all subsystems |
CHANGELOG.md |
Unreleased entry for logging integration |
AGENTS.md |
Debugging tips for enabling subsystem loggers |
.claude/CLAUDE.md |
Debugging tips (mirrored from AGENTS.md) |
You can also share your feedback on Copilot code review. Take the survey.
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.
Summary
Add stdlib
loggingintegration across all four subsystems (context, routing, store, adapters) with structured log messages. Zero runtime dependencies added — uses Python's built-inloggingmodule only.Fixes #111
Changes
context/): DEBUG logs for each pipeline stage —generate_candidates,dependency_closure,sensitivity_filter,apply_firewall,score_candidates,deduplicate_candidates,select_and_pack; INFO log for build completion with phase, included/dropped counts, and token usagerouting/router.py): INFO log for route completion with top-k count, candidate count, and top-5 scoresstore/): DEBUG logs forEventLog.append,ArtifactStore.put,EpisodicStore.add/search,FactStore.putadapters/): DEBUG logs for MCP and A2A conversion functionssensitivity_filternever logs text content — only action, floor level, and pass/drop counts%sformatting — zero cost at the default WARNING levelcontextweaver.context,contextweaver.routing,contextweaver.store,contextweaver.adapterstests/test_logging.pywith 16 tests covering logger existence, INFO/DEBUG emission, and the sensitivity guardAGENTS.mdand.claude/CLAUDE.mddebugging tips; updatedCHANGELOG.mdChecklist
make cipasses locally (fmt + lint + type + test + example + demo)CHANGELOG.mdupdated under## [Unreleased]Notes for reviewers
context/sensitivity.py): The sensitivity filter deliberately logs only the action, floor level, and pass/drop counts — never the text content of items. This preserves the security-grade invariant.logger.debug("...", arg1, arg2)lazy formatting, so string interpolation is skipped entirely when the logger is at the default WARNING level.import loggingfrom the standard library.