google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

[Logging] Resource type and other metadata not auto-populated on Cloud Run

Open mjpvandenberg opened this issue 5 years ago • 0 comments

On https://cloud.google.com/run/docs/logging#container-logs it says

The container logs written to these supported locations are automatically associated with the Cloud Run service, revision, and location.

However, the log entries from my PHP app, running on Cloud Run and using PHP client library v1.21.0 (currently the latest), show up in Google Cloud Logging with resource.type=global.

Minimum steps to reproduce:

Create a folder with the following 3 files.

composer.json

{
    "name": "test/gcp-logging",
    "type": "project",
    "require": {
        "ext-json": "*",
        "google/cloud-logging": "1.21.0"
    }
}

Dockerfile

FROM php:7.4-apache
COPY . /var/www/html

index.php

<?php
require 'vendor/autoload.php';

use Google\Cloud\Logging\LoggingClient;

$logging = new LoggingClient();

$logging->logger('app')->write('This is a test.');

Run composer install, build the Docker image, push it to Google Container Registry, deploy it as a revision on Cloud Run with port 80, and go to the service's URL. You'll get a blank page. Go to Google Cloud Logging. There will be a new log entry with message=This is a test. and resource.type=global (plus some other details). I was expecting resource.type=cloud_run_revision as well as resource.labels.location=..., resource.labels.service_name=..., resource.labels.revision_name=... etc.

mjpvandenberg avatar Jan 24 '21 20:01 mjpvandenberg