[Bug] context.thread_local_storage.invocation_id does not correlate thread logs in Application Insights on Python 3.13
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- azure, python
- Ambito
- backend, observability-sre
Direzione di ricerca
Inizia riproducendo il trigger HTTP async con asyncio.to_thread su Python 3.12 e 3.13, quindi esamina il workaround invocation_id_cv in azure_functions_runtime.utils.executor e l’uso di context.thread_local_storage.invocation_id. Il lavoro è completato quando i log dei thread in background compaiono in Application Insights con lo stesso InvocationId su Python 3.13 tramite un’API supportata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Expected Behavior
According to the docs, setting context.thread_local_storage.invocation_id
inside a background thread enables log correlation for that thread:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#log-custom-telemetry
After calling:
context.thread_local_storage.invocation_id = context.invocation_id
...all logging.info() calls from that thread should appear in Application
Insights correlated to the function invocation (same InvocationId).
Actual Behavior
On Python 3.13, [THREAD] logs are completely absent from Application Insights.
[MAIN] logs appear correctly. The identical code works on Python 3.12.
Python 3.12 ✅
"Logging from main handler" → appears, InvocationId=37b57bfd-...
"Logging from a background thread" → appears, InvocationId=37b57bfd-...
Python 3.13 ❌
"Logging from main handler" → appears, InvocationId=48b27079-...
"Logging from a background thread" → ABSENT from App Insights entirely
Steps to Reproduce
- Deploy Azure Function App with Python 3.13, Azure Functions Runtime v4, Dedicated plan
- Use the code below (async HTTP trigger + asyncio.to_thread)
- Trigger the function via HTTP
- Check Application Insights traces — background thread log is missing
- Redeploy the same code with Python 3.12 — background thread log appears correctly
Relevant code being tried
import azure.functions as func
import logging
import asyncio
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
def work(context: func.Context):
context.thread_local_storage.invocation_id = context.invocation_id
logging.info("Logging from a background thread")
@app.route(route="test")
async def test_async(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
await asyncio.to_thread(work, context)
logging.info("Logging from main handler")
return func.HttpResponse("ok")
Relevant log output
requirements.txt file
azure-functions
Where are you facing this problem?
Production Environment (explain below)
Function app name
No response
Additional Information
Root cause: azure-functions-runtime (used on Python 3.13) has its own separate
threading.local object for log routing. context.thread_local_storage points to
azure-functions-worker's threading.local — a different object that the new
runtime's logging proxy never reads.
Workaround (confirmed working on Python 3.13):
from azure_functions_runtime.utils.executor import invocation_id_cv
def work():
logging.info("Logging from a background thread")
@app.route(route="test")
async def test_async(req, context):
invocation_id_cv.set(context.invocation_id) # copied by asyncio.to_thread
await asyncio.to_thread(work)
asyncio.to_thread copies ContextVars automatically, so the proxy finds the
invocation_id correctly.
Note: invocation_id_cv is an internal API — a public API for this use case
would be appreciated.
- Lingua principale
- Python
- Stelle
- 357
- Fork
- 117
- Merge medio
- 13g 12h
- PR unite (30g)
- 2
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Azure/azure-functions-python-worker
-
[Bug] ASGI cookie conversion serializes an absent Domain attribute and breaks __Host- cookiesForse già presa @tharun06 l’ha presa 22 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
Azure/azure-functions-python-worker#1908 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
Azure/azure-functions-python-worker#1906 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
[Python 3.14 proxy worker] Missing sys.modules["__main__"] breaks multiprocessing spawnForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
Tutte le issue di Azure/azure-functions-python-worker
Issue simili
-
vis.image() reports "Unsupported number of image channels: 224" for an HxWxC imageForse già presa @piyush182004 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
fossasia/visdom#1997 · 3 commenti ·
I maintainer di solito rispondono entro 6 giorni
-
Byse new domainAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Gujal00/ResolveURL#1525 ·
I maintainer di solito rispondono entro 1 giorno
-
Serialisation fails with pydantic 2.14: wrap serialisers pass SerializationInfo as index_keyForse già presa @hugohills-regnosys l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
finos/rune-python-runtime#45 ·
-
[Bug]: LangGraph Store sync put bypasses namespace validationForse già presa @ktz03 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
volcengine/OpenViking#6050 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
hummingbot/condor#283 ·
I maintainer di solito rispondono entro 1 giorno