Skip to content

feat: add Python logging integration with structured events#147

Merged
dgenio merged 7 commits intomainfrom
feat/logging-integration
Mar 10, 2026
Merged

feat: add Python logging integration with structured events#147
dgenio merged 7 commits intomainfrom
feat/logging-integration

Conversation

@dgenio
Copy link
Owner

@dgenio dgenio commented Mar 9, 2026

Summary

Add stdlib logging integration across all four subsystems (context, routing, store, adapters) with structured log messages. Zero runtime dependencies added — uses Python's built-in logging module only.

Fixes #111

Changes

  • Context pipeline (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 usage
  • Routing (routing/router.py): INFO log for route completion with top-k count, candidate count, and top-5 scores
  • Store (store/): DEBUG logs for EventLog.append, ArtifactStore.put, EpisodicStore.add/search, FactStore.put
  • Adapters (adapters/): DEBUG logs for MCP and A2A conversion functions
  • Sensitivity guard: sensitivity_filter never logs text content — only action, floor level, and pass/drop counts
  • Performance: All log calls use lazy %s formatting — zero cost at the default WARNING level
  • Logger hierarchy: contextweaver.context, contextweaver.routing, contextweaver.store, contextweaver.adapters
  • Tests: New tests/test_logging.py with 16 tests covering logger existence, INFO/DEBUG emission, and the sensitivity guard
  • Docs: Updated AGENTS.md and .claude/CLAUDE.md debugging tips; updated CHANGELOG.md

Checklist

  • Tests added or updated for every new/changed public function
  • make ci passes locally (fmt + lint + type + test + example + demo)
  • CHANGELOG.md updated under ## [Unreleased]
  • Docstrings added for all new public APIs (Google-style)
  • Every modified module stays ≤ 300 lines (or a decomposition issue is linked above)
  • Related issue linked in the summary above
  • Agent-facing docs updated if pipeline, API, or conventions changed

Notes for reviewers

  • Sensitivity guard (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.
  • Zero cost at default level: All log calls use logger.debug("...", arg1, arg2) lazy formatting, so string interpolation is skipped entirely when the logger is at the default WARNING level.
  • No new dependencies: Uses only import logging from the standard library.
  • All 535 tests pass, including 16 new logging-specific tests.

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)
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py covering logger existence, emission at correct levels, and the sensitivity guard (no text content in logs)
  • Updated AGENTS.md, .claude/CLAUDE.md, and CHANGELOG.md with 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.

@dgenio dgenio merged commit fed1a7c into main Mar 10, 2026
3 checks passed
@dgenio dgenio deleted the feat/logging-integration branch March 10, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[observability] Add Python logging integration with structured events

2 participants