Preethi Vaidyanathan
Preethi Vaidyanathan

Reputation: 1322

No logs available for google cloud tasks?

I have a very basic Flask app set up in a Google App Engine:

from flask import Flask
app = Flask(__name__)

@app.route("/<id>")
def hello(id):
    print("Got this id: {}".format(id))
    return "Hello World: {}".format(id)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080, debug=True)

I have enabled logging by running this in my terminal: gcloud beta tasks queues update [QUEUE_ID] --log-sampling-ratio=1.0

I am intentionally triggering an error by adding a POST request to my Flask endpoint. I see in my queue that this task retries many times, but when I click on the logs, I see this (task name and queue name intentionally modified for this screenshot): enter image description here

I am expecting to see the error that I get from gcloud app logs read, which is: 2019-11-18 16:27:59 default[20191118t002408] "POST /example_task_handler" 405

What am I doing wrong?

Update: I do see the logs I am looking for in the Google App Engine logs, but I don't see anything when I click on the logs for the individual failing POST Request task that gets retried.

Upvotes: 4

Views: 2574

Answers (2)

Preethi Vaidyanathan
Preethi Vaidyanathan

Reputation: 1322

It turns out the issue was twofold.

  1. I needed to use the python logging library, so I switched to logging.info('Got this id: {}'.format(id))
  2. The default logging for python is warning and higher, so I needed to specify that it should print everything, which I did with:
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

(this works because DEBUG is the lowest logging level).

Upvotes: 3

Averi Kitsch
Averi Kitsch

Reputation: 921

  1. Did you sub your queue's name ("my-queue-name") into for [QUEUE_ID] in gcloud beta tasks queues update [QUEUE_ID] --log-sampling-ratio=1.0?
  2. In the tasks console, do you seen that there has been an attempt? enter image description here
  3. Have you tried to load older or newer logs?
  4. Are you using an App Engine target for your task?

Another way of finding logs is with the Cloud Tasks Queue selector in Stackdriver. enter image description here

Upvotes: 2

Related Questions