0

I am using background_thread from google.appengine.api in an app engine standard application to create a thread that polls a pull task queue every 30 seconds for new tasks. App engine is grouping the logs per run into /_ah/background entries on stack driver with everything logged by the application grouped inside that entry.

The problem is all the /_ah/background logged have the same timestamp which is of the first entry created but the application logs that are grouped under it show correct timestamp. This also results in stack driver not logging logs after a day's run as it reaches the limit (probably as all entries are logged with same timestamp).

Any ideas on why the /_ah/background entries have same timestamp ?

JourneyMan
  • 21
  • 1

1 Answers1

0

Whenever a background thread is started, a special request to /_ah/background is made. That is, the background thread works as if it would be serving a request to /_ah/background. All logs coming from the background thread are recorded to that particular request. While the background thread is running, labels like "active start=2013-08-21,11:15:17.586" will be recorded instead of HTTP response code and the elapsed time. If it terminates, the log shows the response code and the actual elapsed time.

However, every operation running within the same thread will have the same timestamp as of the main operation. Hence, the same timestamps will be seen for all background operations running under the same background main operation. Drilling down the logs of each operations in Stackdriver will give more details about the exact timestamps and other details about the tasks.

With this in mind, please note that the entries.write API calls limit is 1000 writes per second, per project. Hence, this might not necessary be the reason for the logging to be stopped.

oakinlaja
  • 826
  • 6
  • 10
  • Is there a way to make the background threads log the current time for the _ah/background rather than the time the request arrived ? – JourneyMan Mar 26 '18 at 03:56
  • Unfortunately, as confirmed in the [link](https://issuetracker.google.com/issues/70605915#comment2), the design is to clutter up every background processes. However, you can manage manually what exactly you want to log by using the [Logging](https://cloud.google.com/logging/docs/how-to) API. Likewise, you can [programmatically](https://cloud.google.com/appengine/docs/standard/python/logs/#writing_application_logs) write application logs from your application. – oakinlaja Mar 28 '18 at 16:32