Skip to content

refactor(otel): extract telemetry setup out of app.py into a package MAPCO-11286 - #94

Open
razbroc wants to merge 3 commits into
masterfrom
refactor/telemetry-package-split
Open

refactor(otel): extract telemetry setup out of app.py into a package MAPCO-11286#94
razbroc wants to merge 3 commits into
masterfrom
refactor/telemetry-package-split

Conversation

@razbroc

@razbroc razbroc commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • src/app.py was 577 lines, almost all OTel provider setup, four instrumentation guard blocks, a FileCache monkeypatch, and a logging bootstrap — only ~6 lines were the actual WSGI app. Everything but app construction, CORS, and two telemetry calls is now extracted into src/telemetry/:
    • telemetry/_logging.py — leaf module: log bootstrap, otel_log logger
    • telemetry/instrumentation.py — redis/sql/boto/http guard blocks, moved verbatim
    • telemetry/mapproxy_cache.pyFileCache tile-tracing patch, moved verbatim
    • telemetry/__init__.py — providers, install_instrumentation(), and init_when_safe() (the postfork/worker_id dispatch), now guarded against a second call
  • Dockerfile now COPYs src/telemetry/ alongside app.py so import telemetry resolves at runtime.
  • pull_request.yaml gets a python-smoke-check job (py_compile + a real import app against a throwaway MapProxy config) so a broken import introduced by the split fails CI before merge.

This is a lift-and-shift with no behavior change: no automated tests, no pyproject.toml/pytest, and no collapsing of the four instrumentation guard blocks — all deliberate, per the design discussion this came out of (tracked as local tickets under .scratch/telemetry-package-split/issues/, not GitHub issues).

Test plan

  • Diffed baseline vs. split startup logs line-by-line (timestamps aside) — identical
  • Called init_when_safe() twice directly — second call logs and no-ops instead of re-initializing
  • Built the image locally and booted it under real uWSGI (master=true, processes=2) — instrumentors install once pre-fork, each of the 2 forked workers independently logs its own provider-init pair, no export errors
  • Ran the new CI smoke-check commands locally against the fixture config — pass
  • /code-review (Standards + Spec axes) — Spec clean; Standards raised 3 non-blocking judgement calls, all tracing back to structure the source tickets explicitly specified

razbroc added 3 commits August 9, 2026 11:47
app.py was 577 lines, almost all OTel provider setup, four instrumentation
guard blocks, a FileCache monkeypatch, and a logging bootstrap, with only ~6
lines being the actual WSGI app. Split everything but app construction, CORS,
and two telemetry calls into src/telemetry/ so app.py reads as what it is.

- telemetry/_logging.py: leaf module (log bootstrap, otel_log logger)
- telemetry/instrumentation.py: redis/sql/boto/http guard blocks, verbatim
- telemetry/mapproxy_cache.py: FileCache tile-tracing patch, verbatim
- telemetry/__init__.py: providers, install_instrumentation(), and
  init_when_safe() (the postfork/worker_id dispatch), now idempotent

Wire the new package into the image and CI: Dockerfile COPYs src/telemetry/
alongside app.py, and pull_request.yaml gets a python-smoke-check job
(py_compile + a real `import app` against a throwaway MapProxy config) so a
broken import fails CI before merge.

Lift-and-shift only, no behavior change: verified the built image's startup
log sequence is identical to the pre-split baseline under a real uWSGI
master+2-worker boot (one provider-init per worker, no export errors).
The module only wraps FileCache methods for OTel tracing; it doesn't hold or
implement a cache. The old name read like a caching concern rather than the
tracing concern it actually is.
The prior commit renamed mapproxy_cache.py but git add silently dropped the
matching import-name updates in __init__.py and _logging.py, leaving
`from telemetry import ... mapproxy_cache` pointing at a module that no
longer exists.
@razbroc razbroc changed the title refactor(otel): extract telemetry setup out of app.py into a package refactor(otel): extract telemetry setup out of app.py into a package MAPCO-11286 Aug 9, 2026
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.

2 participants