Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cloud Run Jobs log format not well implemented #663

Copy link
Copy link
Closed
@guillaumeblaquiere

Description

@guillaumeblaquiere
Issue body actions

Environment details

  • OS type and version: Cloud Run Jobs
  • Python version: 3.10
  • pip version: Not relevant (in the container, I don't know the version!)
  • google-cloud-logging version: Latest (no version mentioned in the requirements.txt)

Steps to reproduce

  1. Use this code for a working example in Cloud Run
    Main.py
import os
from flask import Flask

app = Flask(__name__)

import google.cloud.logging

# Instantiates a client
client = google.cloud.logging.Client()

# Retrieves a Cloud Logging handler based on the environment
# you're running in and integrates the handler with the
# Python logging module. By default this captures all logs
# at INFO level and higher
client.setup_logging()
# [END logging_handler_setup]

# [START logging_handler_usage]
# Imports Python standard library logging
import logging

@app.route('/')
def call_function():
    # The data to log
    text = "Hello, world!"

    # Emits the data using the standard logging module
    logging.warning(text)
    # [END logging_handler_usage]

    print("Logged: {}".format(text))
    return text


# For local execution
if __name__ == "__main__":
    app.run(host='0.0.0.0',port=int(os.environ.get('PORT',8080)))

Requirements.txt

flask
google-cloud-logging

Dockerfile

FROM python:3.10-slim

ENV PYTHONUNBUFFERED True

WORKDIR /app

COPY requirements.txt .

RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .
ENV PORT 8080

CMD python3 main.py

Deploy on cloud run and call the URL. The log is well mentioned in Cloud Logging, with that label part

resource: {
labels: {
configuration_name: "log-format"
location: "us-central1"
project_id: "gdglyon-cloudrun"
revision_name: "log-format-00003-dof"
service_name: "log-format"
}
type: "cloud_run_revision"
}
severity: "WARNING"

Now, do the same thing with Cloud Run Jobs
Main.py (change only the main part)

import os
from flask import Flask

app = Flask(__name__)

import google.cloud.logging

# Instantiates a client
client = google.cloud.logging.Client()

# Retrieves a Cloud Logging handler based on the environment
# you're running in and integrates the handler with the
# Python logging module. By default this captures all logs
# at INFO level and higher
client.setup_logging()
# [END logging_handler_setup]

# [START logging_handler_usage]
# Imports Python standard library logging
import logging

@app.route('/')
def call_function():
    # The data to log
    text = "Hello, world!"

    # Emits the data using the standard logging module
    logging.warning(text)
    # [END logging_handler_usage]

    print("Logged: {}".format(text))
    return text


# For local execution
if __name__ == "__main__":
    call_function()

same Requitements.txt and same Dockerfile

This time the logs are present but not visible in the Cloud Run Jobs logs section. Why? Because the label is not correct:

resource: {
labels: {
instance_id: "001c9ea28b559541e3331ae5c4bef37c4b465860f0a985296835c80be9a949d42cb3505efcd10650f3848ad942b2b46bf120c93f4dfc15eef489ce8cd0db1012b3"
project_id: "gdglyon-cloudrun"
zone: "projects/751286965207/zones/us-central1-1"
}
type: "gce_instance"
}
severity: "WARNING"

The Cloud Logging Library doesn't correctly detect the Cloud Run Jobs runtime environment and don't put the correct values in the logs that cause a filtering issue in the Cloud Run Jobs UI.

(Cloud Run team is aware of that issue)

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.Issues related to the googleapis/python-logging API.customeropened by an external useropened by an external userpriority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.