0
votes

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?

1
The ` process.env.FUNCTION_REGION` was available in Node 8 which was deprecated. Which runtime are you using? - vitooh
I use Node 14. Thanks for pointing this out, it's not supported in this runtime. - aprtweone

1 Answers

-1
votes

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.