ProGirlXOXO
ProGirlXOXO

Reputation: 2300

Why do empty lines appear intermittently in Stackdriver logs?

I'm running a cloud function every minute.

Blank lines (see logs below) appear in Stackdriver logs intermittently.

I don't believe this is due to the function code I have written.

Bug can be recreated with this main.py:

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info(f"Logging {__name__}")


def main(event, context):
    logger.info("Message 1")
    logger.info("Message 2")
    logger.info("Message 3")

This function emitted blanks lines within a couple hours when triggered every minute by Cloud Scheduler.

How can this issue be prevented?

Update: Added two expanded logs

{
 insertId: "000001-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 timestamp: "2019-12-13T23:05:00.344Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"  
}

{
 insertId: "000000-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 textPayload: "Message 2"  
 timestamp: "2019-12-13T23:05:00.345Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0" 

Blank log example

Blank log example 2

Upvotes: 5

Views: 535

Answers (3)

ProGirlXOXO
ProGirlXOXO

Reputation: 2300

This issue seems to have disappeared for us as of 2020-02-03 13:44:20.476 PST

From support engineer on issuetracker.google.com

It seems like stackdriver is logging twice with one of the two logs having empty textpayload.

I also learnt that stackdriver will update their log delivery mechanism in Q1 2020, which will likely address this problem.

I will leave this isuee tracker as is for now. You will be notified when the issue is fixed in Q1 2020.

Upvotes: 0

David
David

Reputation: 9721

One possibility is that your code - or a library that you import - print()s a blank line to stdout or stderr as this is also soent to logs.

Upvotes: 0

marcos
marcos

Reputation: 4510

In the meantime, you can add a filter to stackdriver to skip logs with empty strings.

Upvotes: 1

Related Questions