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

Logging not working for synchronous path operations #11

Open
ManelBH opened this issue Dec 12, 2022 · 15 comments
Open

Logging not working for synchronous path operations #11

ManelBH opened this issue Dec 12, 2022 · 15 comments

Comments

@ManelBH
Copy link

ManelBH commented Dec 12, 2022

This issue is for a: (mark with an x)

- [x] bug report
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  • Define a synchronous path operation with logging:
@app.get("/sample")
def index():
    logging.info("sample")
    return {
        "info": "Try /hello/Shivani for parameterized route.",
    }
  • Start the function and call the operation with an http request

Expected/desired behavior

Expected: A line with the logged text appears in the logs (same behaviour as with async operations)
Actual: Nothing is logged.

OS and Version?

Windows 10

Versions

Python version: 3.9.10
Core Tools Version: 4.0.4704
Function Runtime Version: 4.7.3.18953
azure-functions==1.12.0
fastapi==0.88.0

@ManelBH
Copy link
Author

ManelBH commented Dec 23, 2022

@bhagyshricompany
Copy link

bhagyshricompany commented Dec 27, 2022

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?

@bhagyshricompany
Copy link

@Qmatteo its in progress

@Qmatteo
Copy link

Qmatteo commented Jan 18, 2023

@bhagyshricompany any idea on the timeline?

@bhagyshricompany
Copy link

will update

@Qmatteo
Copy link

Qmatteo commented Jan 24, 2023

@bhagyshricompany "will update" ???

@hashPhoeNiX
Copy link

@bhagyshricompany Any update yet?

@GiuseppeChiesa-TomTom
Copy link

I'm facing the same issue, I see another linked issue has a merged PR but I'm still observing the problem with fastapi

@ajstewart
Copy link

Another "I'm facing the same issue" post, would it be possible for someone to give an update please so we don't have to guess?

As Giuseppe said above I can see that Azure/azure-functions-python-worker#1171 has been merged 2 weeks ago but there has not been a core tools release yet. This issue is still open: Azure/azure-functions-python-worker#1158 so it's hard to know what the status of this is.

It would be much appreciated! Without the logging on these synchronous defined functions suddenly the overall Azure Function I was building becomes impossible to monitor.

@asalogni
Copy link

@bhagyshricompany any update on this? The fix described in this thread Azure/azure-functions-python-worker#1158 doesn't seem to work for me

@Qmatteo
Copy link

Qmatteo commented May 17, 2023

@bhagyshricompany ANY UPDATES ON THIS, PLEASE?

@EvanR-Dev
Copy link

EvanR-Dev commented Jun 19, 2023

Hi, I just wanted to add a solution to this. We can fetch the current logger with getLogger() and use it accordingly. Here is a sample:

# logger.py
import logging

loggers = {}

def myLogger(name):
    global loggers
    
    if loggers.get(name):
        return loggers.get(name)
    else:
        logger = logging.getLogger(name)
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        logger.addHandler(handler)
        loggers[name] = logger
                       
        return logger
# app.py
from logger import myLogger
# and your other imports

@api_router.get(
    "/hello/{name}",
    description="Get name"
)
def get_name(name: str):
    logger = myLogger(__name__)
    logger.info(f"/hello/ endpoint. Name: {name}.")

    return {
        "name": name,
    }

The log in get_name() shows up upon execution as intended. Note that there may be issues with tracking as handle() (non-async) is deprecated

@nikie
Copy link

nikie commented Apr 10, 2024

I have posted a workaround in the Azure/azure-functions-python-worker#1158 thread's comment

@anguspmitchell
Copy link

To anyone else here, @nikie 's solution worked for me, although not out-of-the-box (makes some assumptions about the server you're using)

Also found that certain types of logging didn't work for me on Azure. More here - @nikie your solution worked for me, although not out of the box, since I was using some custom middleware written a couple years ago.

I also experienced some other quirks with Azure logging. I expanded upon it here - https://stackoverflow.com/a/78738009/5469472

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

No branches or pull requests

10 participants