Repository navigation
fix: honor context.thread_local_storage invocation id in proxy worker logging - #1943
Open
alexcastgonz (pcbeingused333) wants to merge 2 commits into
Open
alexcastgonz (pcbeingused333) wants to merge 2 commits into
alexcastgonz (pcbeingused333) wants to merge 2 commits into
Conversation
… logging Customer threads (e.g. asyncio.to_thread) that follow the documented context.thread_local_storage.invocation_id pattern were not correlated because the proxy only consulted its own thread-local.
alexcastgonz (pcbeingused333)
requested review from
Gavin Aguiar (gavin-aguiar),
hallvictoria and
Varad Meru (vrdmr)
as code owners
November 11, 2026 15:59
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This branch has not been deployed
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.
Description
Fixes #1860
The documented pattern for correlating logs from customer-created threads is to assign
context.thread_local_storage.invocation_idinside the thread.context.thread_local_storageis the runtime's ownthreading.local(bindings.context._invocation_id_local), butproxy_worker.dispatcher.get_current_invocation_id()only checked the asyncio task, the runtime ContextVar, the thread registry and the proxy's separate_invocation_id_local. In an async handler that offloads work withasyncio.to_thread, none of those hold the ID, so the log record had no invocation ID and was dropped from correlation.get_current_invocation_id()now also consults the loaded runtime'sbindings.context._invocation_id_localbefore falling back to the proxy's own local. Existing lookup order is unchanged, so the native path that already sets the ContextVar is unaffected; the lookup resolves the module from the loaded runtime package, so it works for bothazure_functions_runtimeandazure_functions_runtime_v1.Testing
Added
test_get_current_invocation_id_runtime_thread_local_storage, which assigns the ID on a stand-in runtime_invocation_id_localfrom insideasyncio.to_threadand expectsget_current_invocation_id()to return it. It fails without the change and passes with it; the rest oftests/unittest_proxy/test_dispatcher.pypasses (40 passed).Pull Request Checklist
Host-Worker Contract
Worker Execution Logic
Logging correlation only; invocation, bindings and lifecycle are unchanged.
Python Version Coverage
proxy_worker(Python 3.13-3.14).azure_functions_worker(<= 3.12) already correlates these logs, and r2p2 (>= 3.15) already consults the runtime'sbindings.context._invocation_id_localinbridge.py; this change bringsproxy_workerin line with it.Programming Model Compatibility (proxy_worker and r2p2)
bindings.context._invocation_id_localfrom whichever runtime package is loaded, so it covers both.AI assistance: this change and its regression test were prepared using Claude Code.