fix(telemetry): break helpers->core import cycle so metrics plugins register#1180
fix(telemetry): break helpers->core import cycle so metrics plugins register#1180ajbozarth wants to merge 2 commits into
Conversation
…egister mellea/helpers loaded mellea.core at module level, creating a cycle when mellea.core.utils -> mellea.telemetry -> metrics' bottom-of-module registration -> mellea.helpers ran during core init. The except ImportError swallowed the cycle as "plugin framework is not installed", so MELLEA_METRICS_ENABLED=true registered zero plugins in production. Move helpers' core imports under TYPE_CHECKING or into function bodies, and replace the except ImportError with an explicit _HAS_PLUGIN_FRAMEWORK check so future cycle-shape regressions surface loudly. Closes generative-computing#1079. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
|
So while wrapping up work on phase 1 of #444 I discovered a chicken and egg issue with registering plugins that makes fully lazy init not work. In addition I found that this bug also affected the tracing work. So I decided to quickly open this bug fix since it was more severe than I thought (essentially metrics has been non-functional since I switched it to use hooks). The remaining items in #1079 are now |
planetf1
left a comment
There was a problem hiding this comment.
LGTM — reproduced on the parent (0 plugins), confirmed all 8 register here.
Two non-blocking follow-ups:
metrics_plugins.py:18importsfrom mellea.core.base import GenerationMetadataat module level — the same cycle this PR fixes, safe only becausecore/__init__.pyimports.basebefore.utils. If that order ever changes the cycle reopens, now silently (since this PR removes the loud failure). Worth a follow-up to make plugin registration lazy and drop the dependency on import order.- A regression test in
test/package/test_dependency_isolation.py(already runs isolated interpreters) asserting the plugin count is non-zero with metrics enabled would help — the existing plugin tests use mocks, so they couldn't catch this failure mode.
Addresses non-blocking review feedback on generative-computing#1180. - metrics_plugins.py: move `GenerationMetadata` import out of module level (TYPE_CHECKING for the annotation, function-local for the one runtime use). Removes the latent cycle that was previously safe only because of import order in `mellea/core/__init__.py`. - test_dependency_isolation.py: add `test_telemetry_metrics_plugins_register` that runs in an isolated uv env with `MELLEA_METRICS_ENABLED=true` and asserts `plugin_count > 0`. Catches the silent-zero-plugins failure mode from generative-computing#1079 that the existing mock-based plugin tests missed. Factor the `uv run --isolated` plumbing out of `_run_check` into `_run_isolated_script` so both call sites share it. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
|
Thanks @planetf1 |
Issue
Fixes #1079
Description
mellea/helpers loaded mellea.core at module level, creating a cycle when
mellea.core.utils -> mellea.telemetry -> metrics' bottom-of-module registration -> mellea.helpersran during core init. Theexcept ImportErrorswallowed the cycle as "plugin framework is not installed", soMELLEA_METRICS_ENABLED=trueregistered zero plugins in production.helpers/async_helpers.pyandopenai_compatible_helpers.py: move core imports underTYPE_CHECKINGor into function bodies.telemetry/metrics.py: replaceexcept ImportErrorwith explicit_HAS_PLUGIN_FRAMEWORKcheck; move registration block below__all__.The lazy-init migration originally scoped in #1079 is declined in favor of eager-parity with the upcoming tracing plugin design.
Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.