Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Logging not working from other threads #1158

Closed
ManelBH opened this issue Dec 23, 2022 · 14 comments
Closed

[BUG] Logging not working from other threads #1158

ManelBH opened this issue Dec 23, 2022 · 14 comments

Comments

@ManelBH
Copy link

ManelBH commented Dec 23, 2022

Investigative information

Python version: 3.9.10
Core Tools Version: 4.0.4915
Function Runtime Version: 4.14.0.19631

Repro steps

dispatch a function that uses logging to a background thread

Expected behavior

The logged text appears in the logs

Actual behavior

The text isn't logged

Example:

import logging
from concurrent.futures import ThreadPoolExecutor
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    with ThreadPoolExecutor() as pool:
        pool.submit(foo)

    return func.HttpResponse(
        "This HTTP triggered function executed successfully",
        status_code=200
    )


def foo():
    logging.info("Hello from foo")
    print("foo completed")

When I trigger this, In the console I can see "foo completed" but not "Hello from foo".

Contents of the requirements.txt file:

azure-functions==1.12.0

@ManelBH
Copy link
Author

ManelBH commented Dec 23, 2022

@bhagyshricompany
Copy link

Thanks for reporting we will discuss this feature issue and update you on the inputs soon.

@Qmatteo
Copy link

Qmatteo commented Jan 3, 2023

@bhagyshricompany Any update on this?

@YunchuWang
Copy link
Member

@Qmatteo we have looked and identified the cause, within python function worker there is a managed threadpoolexecutor which wraps cx's sync function by assigning function invocation id to thread_local. This does not apply to cx managed threadpoolexecutor and thread without function invocation id assigned will not be logged

def _run_sync_func(self, invocation_id, context, func, params):

we are working on the fix and will let you know

@asalogni
Copy link

@YunchuWang how long do you think it will take to fix the problem?

@bhagyshricompany
Copy link

@vrdmr please comment on this

@EvanR-Dev
Copy link
Contributor

Hi, a potential fix is currently under review. Thank you for your patience, and we will keep you updated on this.

@Qmatteo
Copy link

Qmatteo commented Feb 8, 2023

@EvanR-Dev ok. Any ideas on the timeline?
Coz I think that the PR must be reviewed, approved, completed and released.
But right now we have some functions in production that we are not able to monitor since we don't see any logs

@EvanR-Dev
Copy link
Contributor

I understand. It will be merged by the end of this week and part of the next release. The release will take time as we are doing hot fixes and could take by the end of March by the time it is finally out. We thank you for your patience once again.

@GiuseppeChiesa-TomTom
Copy link

has this fix been released?

@gavin-aguiar
Copy link
Contributor

This fix will be released with runtime version 4.19. ETA mid-April

@Marco-Santoni
Copy link

Hi @gavin-aguiar ,

how can we track when the 4.19 is going live?

@gavin-aguiar
Copy link
Contributor

gavin-aguiar commented Apr 22, 2023

@Marco-Santoni 4.19 is already deployed for dedicated plan in all regions. Consumption plan deployment has started and should be done in a week.

@Eusinho1985
Copy link

Investigative information

Python version: 3.9.10 Core Tools Version: 4.0.4915 Function Runtime Version: 4.14.0.19631

Repro steps

dispatch a function that uses logging to a background thread

Expected behavior

The logged text appears in the logs

Actual behavior

The text isn't logged

Example:

import logging
from concurrent.futures import ThreadPoolExecutor
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    with ThreadPoolExecutor() as pool:
        pool.submit(foo)

    return func.HttpResponse(
        "This HTTP triggered function executed successfully",
        status_code=200
    )


def foo():
    logging.info("Hello from foo")
    print("foo completed")

When I trigger this, In the console I can see "foo completed" but not "Hello from foo".

Contents of the requirements.txt file:

azure-functions==1.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests