googleapis / nodejs-logging-bunyan

Node.js client integration between Stackdriver Logging and Bunyan.
https://cloud.google.com/logging/
Apache License 2.0
63 stars 34 forks source link

Gcloud resource not detected in Cloud Run #557

Closed philsch closed 2 years ago

philsch commented 3 years ago

Environment details

Expected behavior

As stated in /@google-cloud/logging-bunyan/build/src/types/core.d.ts

/**
   * The monitored resource that the log stream corresponds to. On Google Cloud
   * Platform, this is detected automatically, but you may optionally specify a
   * specific monitored resource. For more information, see the
   * [official documentation]{@link https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource}
   */
  resource?: MonitoredResource;

The Gcloud resource should be detected automatically. This is however not the case for Google Cloud Run.

Steps to reproduce

  1. Create a logger as described in the example code, including a stdout and bunyanLogger.stream.
    
    import bunyan from 'bunyan';
    import { LoggingBunyan } from '@google-cloud/logging-bunyan';
    const PACKAGE_NAME = 'service-proxy-logger';

const bunyanLogger = new LoggingBunyan(); const logger = bunyan.createLogger({ name: PACKAGE_NAME, streams: [ // Log to the console at 'info' and above { stream: process.stdout, level: 'info' }, // And log to Stackdriver Logging, logging at 'info' and above bunyanLogger.stream('info'), ], });

export default logger;


  2. Create some code calling different log levels, for example `logger.warn('DEMO warn');`
  3. Deploy as Cloud Run function
  4. Opening the Logs in the Cloud Run web interface will only show the stdout and therefore plain JSON -> this also means the log severity is not shown correctly. Note that opening the Logs applies this default log filter

resource.type = "cloud_run_revision" resource.labels.service_name = "service-proxy-logger" resource.labels.location = "europe-west3" severity>=DEFAULT

![Screenshot 2021-08-09 at 15 54 17](https://user-images.githubusercontent.com/5527838/128717952-06c1fdf8-a490-4792-9ad6-5a23e662ccca.png)

However the correct parsed bunyan log can be found when adjusting the filter to:

logName: "projects/usercentrics-playground/logs/bunyan_log"

![Screenshot 2021-08-09 at 15 44 37](https://user-images.githubusercontent.com/5527838/128716544-c2661a88-76cf-4ea7-aa83-1faecdacc98d.png)

  5. Set the resource manually in the LoggingBunyan constructor as follows and redeploy

const bunyanLogger = new LoggingBunyan({ resource: { type: "cloud_run_revision", labels: { location: "europe-west3", service_name: PACKAGE_NAME } } });



  6. Opening the Cloud Run logs, the correct parsed bunyan log stream is now visible as the resource has been set correctly

![Screenshot 2021-08-09 at 15 39 59](https://user-images.githubusercontent.com/5527838/128716836-480a57b9-1cee-457e-bec7-17427c69b200.png)
minherz commented 3 years ago

@philsch thank you for letting us know and the detailed report. the described issue duplicates the problem with the resource type auto capturing in googleapis/nodejs-logging#1127.

daniel-sanche commented 2 years ago

@minherz Is this safe to close? I believe this was addressed in https://github.com/googleapis/nodejs-logging/pull/1145

minherz commented 2 years ago

Verified. Thank you, @daniel-sanche