refactor(otel): extract telemetry setup out of app.py into a package MAPCO-11286 - #94
Open
razbroc wants to merge 3 commits into
Open
refactor(otel): extract telemetry setup out of app.py into a package MAPCO-11286#94razbroc wants to merge 3 commits into
razbroc wants to merge 3 commits into
Conversation
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.
CL-SHLOMIKONCHA
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/app.pywas 577 lines, almost all OTel provider setup, four instrumentation guard blocks, aFileCachemonkeypatch, and a logging bootstrap — only ~6 lines were the actual WSGI app. Everything but app construction, CORS, and two telemetry calls is now extracted intosrc/telemetry/:telemetry/_logging.py— leaf module: log bootstrap,otel_logloggertelemetry/instrumentation.py— redis/sql/boto/http guard blocks, moved verbatimtelemetry/mapproxy_cache.py—FileCachetile-tracing patch, moved verbatimtelemetry/__init__.py— providers,install_instrumentation(), andinit_when_safe()(the postfork/worker_id dispatch), now guarded against a second callDockerfilenowCOPYssrc/telemetry/alongsideapp.pysoimport telemetryresolves at runtime.pull_request.yamlgets apython-smoke-checkjob (py_compile+ a realimport appagainst 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
init_when_safe()twice directly — second call logs and no-ops instead of re-initializingmaster=true,processes=2) — instrumentors install once pre-fork, each of the 2 forked workers independently logs its own provider-init pair, no export errors/code-review(Standards + Spec axes) — Spec clean; Standards raised 3 non-blocking judgement calls, all tracing back to structure the source tickets explicitly specified