audit: logging escape hatch — let student devs inject info/debug messages into traces

Open
#30 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
flask, python
Domain
observability

Research direction

Start with src/campus/audit/middleware/tracing.py and trace how RequestWarningCollector stores data in flask.g before build_span_from_context builds a span. The issue offers several possible APIs and capture policies but leaves the design open. Done means agreeing on the API and scope, then adding focused tests for annotations or opt-in INFO/DEBUG capture and verifying the resulting span data.

Written by the indexing model from the issue text.

Description

Part of the audit-middleware reorg (#TBD — will cross-link once filed). Design input from the 2026-11-19 session.

Problem

Student devs have no deliberate way to write into the audit trace:

  • logger.warning/error/exception during a request are captured passively (RequestWarningCollector, flask-campus#26 → tags.warnings, capped 10 records × 500 chars, redacted, tracebacks stripped in prod).
  • logger.info / logger.debug are dropped — the collector hard-filters levelno < WARNING (src/campus/audit/middleware/tracing.py).
  • No annotation API: no way to attach a custom tag to the current span, no way to set error_message (schema field exists, always None today), no structured event emission from consumers.

Exception capture (confirmed, with caveats)

Unhandled exceptions in a view surface as a span with status_code=500; werkzeug logs them at ERROR via the root logger, so the formatted message rides tags.warnings. Caveats: error_message stays None, prod tracebacks are stripped, and a request emitting >10 warning-level records loses the tail (silent cap).

Proposed direction (to design here)

New module home after the reorg: campus.flask_campus.audit. Candidate surface:

  • audit.annotate(message, *, level="info") / audit.span_tag(**tags) — stash into flask.g for the span builder to pick up (the g-stash → build_span_from_context pipeline already exists; tags.warnings uses exactly this path).
  • Optional INFO/DEBUG capture: per-app opt-in flag on init_tracing(app, capture_info=...) or per-view via @journey — default stays WARNING+ to avoid payload bloat (chatty views already need the 10-record cap).
  • Consider actually populating error_message for 4xx/5xx spans (schema field is dead today).

Non-goals: not a general metrics API; no new network calls — everything rides the existing span ingest.

Dominant language
Python
Stars
0
Forks
0
Avg merge
9m
Merged PRs (30d)
40

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nyjc-computing/flask-campus

All issues in nyjc-computing/flask-campus

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.