logging: integrate consumer-app logging with campus.auth (startup config, auth-flow records, trace ids)

Open
#46 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
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
flask, python

Research direction

Start with login_manager.py, context.py, audit/tracing.py, and propagation.py; compare their logging behavior with the referenced campus/logging_config.py and the SDK’s campus_python/__init__.py. Decide how startup configuration should preserve tracing handlers and where the shared helper belongs. Done means consumer and auth-flow logs have consistent setup, trace and journey IDs, and exception details, with migration and logging guidance documented.

Written by the indexing model from the issue text.

Description

enhancement

Consumer apps get no logging setup from flask_campus, and flask_campus's own
auth-flow records are emitted into whatever configuration happens to be in
the process. Nothing lines an app's logs up with campus.auth's, so a failed
sign-in has to be pieced together from stderr lines on one side and audit
traces on the other.

Worked example: nyjc-computing/nyxchange-timetable-v2#168 (verdict:
logger.exception() wherever a traceback is needed). ttv2 pins
flask-campus 0.1.21 and configures no logging of its own; the startup-config
follow-up it still owes is nyjc-computing/nyxchange-timetable-v2#93. The
facts below were checked on 2026-11-25 against main (0.2.6) and the wheels
ttv2 installs.

Today

  1. The only logging configuration in a consumer's process comes from the
    SDK: campus_python/__init__.py calls
    logging.basicConfig(level=logging.INFO) at import, and importing
    flask_campus is itself enough to trigger it (__init__ imports
    login_manager, which imports campus_python). That is the process's
    sole handler (stderr, %(levelname)s:%(name)s:%(message)s, INFO on),
    and it turns any later basicConfig in the app into a silent no-op,
    because basicConfig only acts when the root logger has no handlers.
    On Railway every such line is error, INFO narrations included.
  2. Records are filed under two naming conventions: login_manager.py logs
    through flask.current_app.logger (:115, :322), so the record carries
    the consumer's logger name, while context.py, circles.py and
    audit/tracing.py use campus.flask_campus.* module loggers. Filtering
    by logger name cannot separate the library's records from the app's.
  3. Three broad except Exception handlers drop the traceback:
    context.py:213 and :243 (session resolution degrades to signed-out,
    #28) and :395 (revocation failure). Each logs the exception's type and
    message at WARNING and continues, so an unexpected failure in session
    resolution is indistinguishable from "signed out". By the ttv2#168
    verdict these want exc_info=True.
  4. Log records carry no ids. propagation.request_context_headers() already
    stamps the app's trace_id / journey_id on every campus.auth call, so
    campus.auth's audit spans join back to the app's request. The app's
    log lines do not, and neither do campus.auth's own: there is no logging
    filter on either side.

Proposal: three pieces

  • Startup config. A helper giving consumers what campus.auth gives
    itself (campus-suite's campus/logging_config.py: root logger to
    stdout, fleet format, level from an env knob, noisy third-party
    loggers quieted, idempotent). Open question: whether init_app applies it
    when the app has configured nothing, or only exposes it for the app to
    call.
  • Auth-flow records. One naming convention (campus.flask_campus.*
    module loggers; library code stays off app.logger), conventional levels,
    and exc_info=True wherever a broad except handles an unknown failure.
    Typed, expected errors stay message-only; the two existing
    login_manager.py sites are already the model.
  • Ids that join logs to traces. A logging Filter stamping each record
    emitted during a request with the ids propagation.py already sends, so
    one logger.exception line can be looked up in the same journey's
    campus.auth spans.

Layering note: the config helper is not auth-specific. campus-common is
its natural home, with campus.auth's logging_config collapsing onto the
same code so the service and its consumers log identically; flask_campus
owns only the auth-flow vocabulary, the filter, and calling the helper. The
SDK's import-time basicConfig has to go for any of this to hold (library
code should not configure the root logger). That change belongs in
campus-api-python and has no issue yet.

Two traps to design around

  • basicConfig without force is a no-op once the SDK's handler exists,
    so the helper must run before the SDK is imported or replace root handlers
    explicitly.
  • init_tracing attaches RequestWarningCollector to the root logger
    (audit/tracing.py:275), and basicConfig(force=True) removes existing
    root handlers. A helper applied after init_tracing silently stops
    WARNING+ records riding into traces (#26). Ordering, or handler
    preservation, needs specifying.

Deployment semantics: Railway assigns level by stream, not by text:
stderr lines are error, stdout lines are info, and a plain-text traceback
is one entry per line (single-line JSON keeps level and whole stack
traces). So stdout is the floor; whether the fleet moves to JSON is worth
deciding once, here.

Relation to #30: #30 is about writing into the audit trace; this is
about the process log stream. They share the root-logger touchpoint, so
they should be designed in one pass.

Migration: consumers delete hand-rolled startup config once they pin the
release (ttv2 is the first candidate, via ttv2#93); the three context.py
handlers ship in the same release. Docs: a Logging page on the MkDocs site
carrying the logger.exception vs logger.error rule.

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.