php-docs-samples
php-docs-samples copied to clipboard
Cloud function logging error severity
I've run into trouble logging with error severity using cloud functions. Spinning up the example from documentation does not work (logs are displayed with default severity), nor does specifying a severity while using the google/cloud-logging package via composer.
Attached is a screenshot of log output while using the example code from https://github.com/GoogleCloudPlatform/php-docs-samples/blob/HEAD/functions/helloworld_log/index.php
Hmm, this may be an issue with compatibility between Google Cloud Functions and our google/cloud-logging
library. Have you tried using stdout
for logging, instead of using google/cloud-logging
?
I'll look into it...
I've reproduced the problem with the sample, it does not work because some change in the HTTP proxy server in the runtime was changed, and is now prefixing stderr messages with a string that breaks JSON parsing.
Given the logging library uses a different mechanism to ship logs, I'm guessing we have at least two different problems.
When I add cloud/logging to the sample, my local composer v3 is fine but I get the following error on deployment (before even reproducing the reported issue)
gcloud functions deploy --runtime php74 --trigger-http log --entry-point helloLogging
Deploying function (may take a while - up to 2 minutes)...⠹
For Cloud Build Logs, visit: https://console.cloud.google.com/cloud-build/builds;region=us-central1/9651d4e0-15cd-4a3f-b862-079e9447696e?project=[...]
Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: You are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3.
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- psr/cache is locked to version 2.0.0 and an update of this package was not requested.
- psr/cache 2.0.0 requires php >=8.0.0 -> your php version (7.4.27) does not satisfy that requirement.
Problem 2
- psr/log is locked to version 2.0.0 and an update of this package was not requested.
- psr/log 2.0.0 requires php >=8.0.0 -> your php version (7.4.27) does not satisfy that requirement.
Problem 3
- psr/cache 2.0.0 requires php >=8.0.0 -> your php version (7.4.27) does not satisfy that requirement.
- google/grpc-gcp v0.2.0 requires psr/cache ^1.0.1||^2.0.0||^3.0.0 -> satisfiable by psr/cache[2.0.0].
- google/grpc-gcp is locked to version v0.2.0 and an update of this package was not requested.; Error ID: 467317e4
All right, let's run composer update!
composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 2 updates, 0 removals
- Upgrading guzzlehttp/psr7 (2.1.0 => 2.2.1)
- Upgrading symfony/polyfill-php80 (v1.24.0 => v1.25.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 2 updates, 0 removals
- Downloading guzzlehttp/psr7 (2.2.1)
- Downloading symfony/polyfill-php80 (v1.25.0)
- Upgrading guzzlehttp/psr7 (2.1.0 => 2.2.1): Extracting archive
- Upgrading symfony/polyfill-php80 (v1.24.0 => v1.25.0): Extracting archive
Generating autoload files
7 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Deploy fails the same way.
@bshaffer do you have insight into this build problem?
This issue is related to php-fpm. By default decorate_workers_output
is on, which prepends text to all logs written to php://stderr
. This makes it impossible to use structured logs in Cloud Functions (gen2) with php runtime.
To make structured logs work on php runtimes, the value should be changed to off
on container generation done by Cloud Run which means a change of the default Dockerfile related to Cloud Functions php runtimes (7.4 + 8.1).
Ref: https://github.com/docker-library/php/issues/207
any news about it ?