Search code examples
google-app-enginegcloud

Deployment issue after setting GOOGLE_APPLICATION_CREDENTIALS=[PATH]


My app engine application deployed fine before setting this variable. Now when I deploy the application the build is looking for this local file. Can i set this as a relative path or can I remove this variable and use new logger({ projectId, relative/path/to/json }) in my logger utils?

const {Logging} = require('@google-cloud/logging');

export const gCloudLogging = new Logging({ ... make this change here });
export const logName = 'API';
export const log = gCloudLogging.log(logName);
export const resource = {
    "type": "global",
    "displayName": "...",
    "description": "..."
};

export const severity = {
    DEFAULT: 'DEFAULT', //(0) The log entry has no assigned severity level.
    DEBUG: 'DEBUG', //(100) Debug or trace information.
    INFO: 'INFO', //(200) Routine information, such as ongoing status or performance.
    NOTICE: 'NOTICE', //(300) Normal but significant events, such as start up, shut down, or a configuration change.
    WARNING: 'WARNING', //(400) Warning events might cause problems.
    ERROR: 'ERROR', //(500) Error events are likely to cause problems.
    CRITICAL: 'CRITICAL', //(600) Critical events cause more severe problems or outages.
    ALERT: 'ALERT', //(700) A person must take an action immediately.
    EMERGENCY: 'EMERGENCY', //(800) One or more systems are unusable.
};

export const writeLog = (severity: string, text: string): void => {
    const metaData = {
        resource,
        severity
    };
    const entry = log.entry(metaData, text);
    log.write(entry);
}

Solution

  • You can remove the environment variable from your App Engine deployment. As you can see in this documentation Google Client libraries support Application Default Credentials (ADC).

    This means that the libraries will attempt to find credentials for you automatically. The Client libraries can then use the environment variable to find the service account to be used on local environment and automatically use the App Engine Default Service Account when deployed.