Closed
Description
I am not sure if this is a bug or a misconfiguration issue but we are unable to get the execution-id
in our logs. GCP's own function logs like startup/teardown/timeout contain it however our own logs don't. This makes it impossible to correlate all logs from an instance.
Example (GCP function startup log)
{
insertId: "000000-a51b0cd9-1f4d-4396-b812-4b35c8878b69"
labels: {
execution_id: "j57c7yk340qq"
}
logName: "projects/PROJECT-ID/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2021-06-30T17:37:16.202805413Z"
resource: {
labels: {
function_name: "FUNCTION-NAME",
project_id: "PROJECT-ID",
region: "REGION"
}
type: "cloud_function"
}
severity: "DEBUG"
textPayload: "Function execution started"
timestamp: "2021-06-30T17:37:05.341077546Z"
}
We also tried setting a custom label in CloudLoggingHandler
with a trace-id
however GCP's own logs don't reflect the custom trace-id
. This makes me think that GCP is using a separate logger which attaches the execution-id
and our logs are isolated from that logger.
Environment details
- OS type and version: N/A
- Python version: 3.7.9
- pip version: 21.1.2
google-cloud-logging
version: 2.3.1
Steps to reproduce
- Create and attach
CloudLoggingHandler
to a logger in a GCP function - Log an
INFO
message - Verify the log does not contain
execution-id
insidelabels
Code example
A simplified version of our logging setup and a basic event-trigger function.
import logging
import google.cloud.logging
from google.cloud.logging_v2.handlers.handlers import CloudLoggingHandler
class FunctionLogger(logging.Logger):
def __init__(self, level=logging.NOTSET):
super().__init__("logger_name", level)
client = google.cloud.logging.Client()
self._handler = CloudLoggingHandler(client)
self.propagate = False # prevent logging from root logger
self.addHandler(self._handler)
def handler(event, context=None):
"""function entry point"""
logger = FunctionLogger()
logger.info("Test message")
Thanks!!