[Bug] context.thread_local_storage.invocation_id does not correlate thread logs in Application Insights on Python 3.13
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- azure, python
- Lĩnh vực
- backend, observability-sre
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện HTTP trigger async với asyncio.to_thread trên Python 3.12 và 3.13, sau đó kiểm tra workaround invocation_id_cv trong azure_functions_runtime.utils.executor và việc sử dụng context.thread_local_storage.invocation_id. Công việc được xem là hoàn tất khi log từ các background thread xuất hiện trong Application Insights với cùng InvocationId trên Python 3.13 thông qua một API được hỗ trợ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 357
- Fork
- 118
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Azure/azure-functions-python-worker
-
[Bug] ASGI cookie conversion serializes an absent Domain attribute and breaks __Host- cookiesCó thể đã có người làm @tharun06 đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Azure/azure-functions-python-worker#1902 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
Azure/azure-functions-python-worker#1908 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Azure/azure-functions-python-worker#1906 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Azure/azure-functions-python-worker#1904 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Python 3.14 proxy worker] Missing sys.modules["__main__"] breaks multiprocessing spawnCó thể đã có người làm @Fire162 đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Azure/azure-functions-python-worker#1903 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của Azure/azure-functions-python-worker
Issue tương tự
-
`image_generation`: `max_retries` is ignored for OpenAI-compatible providers (always 2 retries)Có thể đã có người làm @ericz7900 đã nhận hôm nay. Đang mởllm translation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rheeloaded/paperpull#117 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
agenda-tech-brasil/agenda-tech-brasil#1619 · 1 bình luận ·
-
process
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 76/100
pyrite-wiki/pyrite#1036 ·
Maintainer thường phản hồi trong vòng 1 ngày