GoogleCloudPlatform / functions-framework-python

FaaS (Function as a service) framework for writing portable Python functions
https://pypi.org/p/functions-framework/
Apache License 2.0
827 stars 120 forks source link

Version 3.8.0 breaks logging #337

Open alta-atc opened 6 days ago

alta-atc commented 6 days ago

When using version 3.8.0 none of my logging statements make it into the cloud logs. Reverting to version 3.7.0 fixed this issue.

Example of implementation:

(imports:)

import logging
logging.basicConfig(level=logging.INFO)

(Within function:) logging.info(f"Deletion Execution completed.")

Please feel free to suggest improved logging implementation if mine is incorrect.

alta-atc commented 6 days ago

Oh,

I should also add that the issue was not confined to logging, my entire function was non-functional. It was as if the cloud event could not be interpreted and converted to a dict. Here is an example of my code. None of the called functions were executed, and the lack of logging made diagnosing the issue very difficult.

I eventually converted my logging state


import logging
logging.basicConfig(level=logging.INFO)

from cloudevents.http import CloudEvent
import functions_framework
from google.events.cloud import firestore
from google.protobuf.json_format import MessageToDict

from library.execution import id
from library.conditions import deleted, created, updated
from library.salesforce import process_salesforce, salesforce_delete

@functions_framework.cloud_event
def fs_users(cloud_event: CloudEvent) -> None:

    try:

        data_pb = firestore.DocumentEventData()
        data_pb._pb.ParseFromString(cloud_event.data)
        data = MessageToDict(data_pb._pb)
        logging.info(f"{id()} Data: {data}")

        if deleted(data):
            salesforce_delete(data)
            logging.info(f"{id()} Deletion Execution completed.")
            return

    except Exception as e:
        logging.error(f"{id()} An error has occured in fs_users: {e}", exc_info=True)
        raise e