Repository navigation
fix(py): v1 /api/notify turns on Dev UI log export - #7070
garvitkaushik-123 wants to merge 1 commit into
Conversation
The v2 handshake calls enable_log_export() next to connect_developer_ui_collector(), and its docstring says it is the same wiring as HTTP /api/notify. The v1 /api/notify handler only connected the trace collector, so with the default `genkit start` (v1 reflection) and no GENKIT_TELEMETRY_SERVER in the environment, debug logs never reached the Dev UI. /api/notify now enables log export with the URL it receives. Fixes genkit-ai#6128
There was a problem hiding this comment.
Code Review
This pull request enables log exporting when the v1 /api/notify endpoint is called with a valid telemetry server URL, aligning its behavior with the v2 handshake. It also adds corresponding unit tests to verify this behavior. The feedback suggests using pytest's built-in monkeypatch fixture instead of directly modifying os.environ with pop in the new tests to prevent potential side effects.
| async def test_notify_enables_log_export_when_env_url_missing() -> None: | ||
| """The v1 /api/notify URL turns on log export too, same as the v2 handshake.""" | ||
| os.environ.pop('GENKIT_TELEMETRY_SERVER', None) |
There was a problem hiding this comment.
Modifying os.environ directly using pop can leak side effects to other tests if the surrounding fixture (_dev_env) is ever refactored or if tests are run in a different context. Using pytest's built-in monkeypatch fixture is the idiomatic and safe way to temporarily modify environment variables during a test.
| async def test_notify_enables_log_export_when_env_url_missing() -> None: | |
| """The v1 /api/notify URL turns on log export too, same as the v2 handshake.""" | |
| os.environ.pop('GENKIT_TELEMETRY_SERVER', None) | |
| async def test_notify_enables_log_export_when_env_url_missing(monkeypatch) -> None: | |
| """The v1 /api/notify URL turns on log export too, same as the v2 handshake.""" | |
| monkeypatch.delenv('GENKIT_TELEMETRY_SERVER', raising=False) |
| async def test_notify_without_url_leaves_log_export_off(body: dict[str, str]) -> None: | ||
| os.environ.pop('GENKIT_TELEMETRY_SERVER', None) |
There was a problem hiding this comment.
Modifying os.environ directly using pop can leak side effects to other tests if the surrounding fixture (_dev_env) is ever refactored or if tests are run in a different context. Using pytest's built-in monkeypatch fixture is the idiomatic and safe way to temporarily modify environment variables during a test.
| async def test_notify_without_url_leaves_log_export_off(body: dict[str, str]) -> None: | |
| os.environ.pop('GENKIT_TELEMETRY_SERVER', None) | |
| async def test_notify_without_url_leaves_log_export_off(body: dict[str, str], monkeypatch) -> None: | |
| monkeypatch.delenv('GENKIT_TELEMETRY_SERVER', raising=False) |
|
Closing as already resolved: Python SDK development has moved to https://github.com/genkit-ai/genkit-python, where /api/notify Dev UI log export was enabled in genkit-ai/genkit-python#53. |
Fixes #6128
Problem
#6128 asks for Dev UI log export to be turned on at both collector-URL entry points, not only at provider init. On current
main, two of the three paths already do this:genkit start -- pythonspawn (URL inGENKIT_TELEMETRY_SERVER):_maybe_enable_log_export()in_logger.py.ReflectionServerV2.apply_handshake_telemetry()callsenable_log_export(url=url)next toconnect_developer_ui_collector(url=url).The v1
/api/notifyhandler in_reflection.pyonly calledconnect_developer_ui_collector. The v2 docstring says the handshake is the "same wiring as HTTP/api/notify", but it wasn't. With v1 reflection and noGENKIT_TELEMETRY_SERVERin the environment, traces reached the Dev UI and debug logs did not.Fix
/api/notifynow also callsenable_log_export(url=url)when it receives atelemetryServerUrl, matching the v2 handshake.enable_log_exportalready ignores an empty URL, honoursGENKIT_OTEL_ENABLE_LOGS=false, and retargets an existing exporter instead of starting a second one.reset_instrumentation()still callsreset_log_export(), so tests can reconnect.Testing
py/packages/genkit/tests/genkit/core/telemetry/log_exporter_test.py:/api/notifywith a URL enables log export whenGENKIT_TELEMETRY_SERVERis unset. This test fails without the change./api/notifywith no URL, or an empty one, leaves log export off.py/packagessuite: 6929 passed, 0 failed (IPv6 loopback test deselected; my sandbox has no IPv6).ruff format,ruff check,ty checkandscripts/check_consistency.pypass.Checklist: