Skip to content

[FDE-360] Add stdlib JSON formatter and configure_logging to pylogtracer#158

Merged
HarvWorks merged 2 commits intomainfrom
feat/FDE-360-stdlib-json-log-formatter
Mar 2, 2026
Merged

[FDE-360] Add stdlib JSON formatter and configure_logging to pylogtracer#158
HarvWorks merged 2 commits intomainfrom
feat/FDE-360-stdlib-json-log-formatter

Conversation

@HarvWorks
Copy link
Member

Summary

  • Adds JSONLogFormatter — stdlib-only logging.Formatter that outputs one JSON object per line matching the Go zap logger schema (timestamp, level, msg, caller, logger, stacktrace)
  • Adds configure_logging() — one-call root logger setup with dev/prod dual mode via DEVELOPMENT_MODE env var
  • Makes loguru and opentelemetry optional extras — core has zero dependencies
  • Fixes pyproject.toml packages config (was ["agents", "models_python"]) and lowers requires-python to >=3.11
  • Extracts OpenTelemetry init into tracing_setup.py, lazy-loads optional modules via __getattr__
  • Uses single-arg traceback.format_exception() for Python 3.14 compatibility
  • Adds 21 tests (formatter + config) with CI workflow and Makefile targets

Addresses reviewer feedback from Hyperdrive PR #1953 to move the JSON log formatter into pylogtracer.

Test plan

  • make lint-python passes (ruff format + check)
  • make test-python passes (21 tests)
  • CI workflow runs and passes
  • Verify no internal service names or secrets in any new files (public repo)

Claude

🤖 Generated with Claude Code

…gtracer

- Add JSONLogFormatter: stdlib-only structured JSON formatter matching
  Go zap logger schema (timestamp, level, msg, caller, logger, stacktrace)
- Add configure_logging(): one-call root logger setup with dev/prod dual
  mode via DEVELOPMENT_MODE env var, langfuse suppression, log level control
- Make loguru and opentelemetry optional extras — core has zero dependencies
- Fix pyproject.toml packages config and lower requires-python to >=3.11
- Extract OpenTelemetry init into tracing_setup.py, lazy-load via __getattr__
- Use single-arg traceback.format_exception() (Python 3.14 compatible)
- Add 21 tests (formatter + config) and CI workflow + Makefile targets

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HarvWorks HarvWorks marked this pull request as ready for review February 27, 2026 05:11
vik-nullify
vik-nullify previously approved these changes Feb 27, 2026
- Replace __getattr__ magic with explicit get_structured_logger() and
  get_tracer() functions
- Replace getattr(logging, ...) with logging.getLevelNamesMapping()
- Add boto3 to [tracing] optional dependency
- Rename get_secret_from_param_store to private _get_secret_from_param_store
- Replace print() with logging.exception() for proper error visibility
- Rename create_exporter to private _create_exporter
- Remove module-level tracer initialization (callers use get_tracer())

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HarvWorks
Copy link
Member Author

Addressed all review comments:

  1. __init__.py — Removed __getattr__ magic: Replaced with explicit get_structured_logger() and get_tracer() functions that do lazy imports internally.

  2. config.py — Removed getattr(logging, ...): Now uses logging.getLevelNamesMapping().get(level_str, logging.INFO).

  3. tracing_setup.py — Added boto3 to deps: boto3>=1.35.0 added to the [tracing] optional dependency group in pyproject.toml.

  4. tracing_setup.py — Made functions private: Renamed to _get_secret_from_param_store and _create_exporter.

  5. tracing_setup.py — Use logging not print: All print() calls replaced with logging.exception() so errors and tracebacks surface in logs. Functions still return None on failure (graceful degradation for non-critical tracing setup), but errors are now clearly visible rather than silently swallowed.

Claude

@HarvWorks HarvWorks requested a review from dnjg February 27, 2026 07:06
@HarvWorks HarvWorks enabled auto-merge March 2, 2026 04:10
@HarvWorks HarvWorks added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit 346ccc0 Mar 2, 2026
3 checks passed
@HarvWorks HarvWorks deleted the feat/FDE-360-stdlib-json-log-formatter branch March 2, 2026 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants