Search code examples
google-cloud-logging

FUNCTION_REGION env variable in Nodejs is differenrent than GCP set automatically for logs


I programmatically write the logs from the function using such code:

import {Logging} from '@google-cloud/logging';

const logging = new Logging();
const log = logging.log('log-name');

const metadata = {
  type: 'cloud_function',
  labels: {
    function_name: process.env.FUNCTION_NAME,
    project: process.env.GCLOUD_PROJECT,
    region: process.env.FUNCTION_REGION
  },
};

log.write(
  log.entry(metadata, "some message")
);

Later in Logs Explorer I get the log message where labels.region is us1 whereas standard logs that GCP adds, e.g. "Function execution started", contains us-central1 value.

Should not they be the same? Maybe I missed something or if it was done intentionally what is the reason behind it?


Solution

  • process.env.FUNCTION_REGION is supported only in Node 8 runtime. In newer runtimes it was deprecated. More info in documentation.

    If your function requires one of the environment variables from an older runtime, you can set the variable when deploying your function.