Extremely cryptic error on FastAPI + Uvicorn application running on Google Cloud Run #2110
-
hi! I have a very low context and cryptic error, not really sure how to debug, will be happy to get more information if anyone has a suggestion how! All I can see in the logs is:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Impossible to help with these logs. |
Beta Was this translation helpful? Give feedback.
-
Hi @ydennisy how did you convert to JSON payload, I have the same error on cloud run and cannot reproduce locally. |
Beta Was this translation helpful? Give feedback.
-
What is the workaround that helped? Is it working for both 1) and 2) ? |
Beta Was this translation helpful? Give feedback.
-
Hi. I've suffered from incorrect logging levels reported in Google Cloud Logging with Uvicorn for a long time. In GCP serverless environments, json logging substantially helps. I rely on a
As for the # Copied from google.cloud.logging_v2.handlers.handlers
"""Exclude internal logs from propagating through handlers"""
EXCLUDED_LOGGER_DEFAULTS = (
"google.cloud",
"google.auth",
"google_auth_httplib2",
"google.api_core.bidi",
"werkzeug",
)
class CustomGoogleCloudStructuredLogHandler(
google.cloud.logging.handlers.StructuredLogHandler
):
def __init__(self, *args, **kwargs):
super().__init__(**kwargs, project_id=settings.GOOGLE_CLOUD_PROJECT)
# self.filters.insert(0, CustomFilter()) You can add custom filters here if you want to
for logger_name in EXCLUDED_LOGGER_DEFAULTS:
# prevent excluded loggers from propagating logs to handler
logger = logging.getLogger(logger_name)
logger.propagate = False And then, when you finally run Logs will start looking a lot more like this. NOTE - This is using a modified StructuredLogHandler suited for environments where GCP picks up logs from stdout. |
Beta Was this translation helpful? Give feedback.
This was an issue with GCP logging - converting to JSON payload printed the stack trace :)