Skip to content

missing label run.googleapis.com/execution_name instantiation on cloudrun job environment  #867

@helldrum

Description

@helldrum

This issue is probably related to this one #854

the librairie doesn't add label run.googleapis.com/execution_name on logs metadata, this label is required because the cloudrun job cloudlogging filter use it on interface to take track of job instance logs.

If this label is not set, the logs are put on default location. The label content exists on job environment vars CLOUD_RUN_EXECUTION and should be added as a build in feature to prevent to do it manually.

I provide you a snippet to show you how I add the label.

Thanks for you help

Environment details

  • OS type and version:
  • Python version: 3.11.8
  • pip version: pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
  • google-cloud-logging version:
    Name: google-cloud-logging
    Version: 3.9.0
    Summary: Stackdriver Logging API client library
    Home-page: https://github.com/googleapis/python-logging
    Author: Google LLC
    Author-email: [email protected]
    License: Apache 2.0
    Location: /usr/local/lib/python3.11/site-packages
    Requires: google-api-core, google-cloud-appengine-logging, google-cloud-audit-log, google-cloud-core, grpc-google-iam-v1, proto-plus, proto-plus, protobuf
    Required-by:

Steps to reproduce

  1. run code snippet without added label on cloudrun job environnement (appli logs are not present on job log explorer )
  2. add label on code and try again to see logs on logs explorer

Code example

import logging
import os

import google.cloud.logging
from google.cloud.logging.handlers 
import CloudLoggingHandler

client = google.cloud.logging.Client()
handler = CloudLoggingHandler(
  client,
  labels={
    "run.googleapis.com/execution_name": os.environ.get(
      "CLOUD_RUN_EXECUTION", "unknown"
    )
  },
)
logger = logging.getLogger(D"cloudLogger")
logger.setLevel(logging.INFO)
logger.addHandler(handler)

logger.error("error")
logger.info("info")
logger.warning("warning")

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions