Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep original labels like "instanceId" #1451

Open
JudithvW opened this issue Sep 13, 2023 · 3 comments
Open

Keep original labels like "instanceId" #1451

JudithvW opened this issue Sep 13, 2023 · 3 comments
Assignees
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@JudithvW
Copy link

Is your feature request related to a problem? Please describe.
A Cloud Run instance can handle multiple requests. Also, multiple Cloud Run instances could be running.
It is currently not visible which Cloud Run instance is logging.

Describe the solution you'd like
If I use console.log in my NodeJS application, the labels in the log will show the labels of the Cloud Run Service, as well as an "instanceId". When I use this package, those 'default' labels in the logging disappear.
I want those labels to be present, even when I add other labels.

Additional context
image
Example of default google logging (console.log), which shows the Cloud Run labels and an instanceId.

image
Example of logging with this package, which removed the original labels and only added the labels set by this package.

@JudithvW JudithvW added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Sep 13, 2023
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/nodejs-logging API. label Sep 13, 2023
@daniel-sanche daniel-sanche removed their assignment Oct 20, 2023
@cindy-peng cindy-peng self-assigned this Jan 18, 2024
@cindy-peng
Copy link
Contributor

Hi @JudithvW, looks like I don't have access to your screenshot. Could you provide a sample code how you write log so I can try repro?

@JudithvW
Copy link
Author

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

class Logger {
  constructor() {
    this.logging = new Logging({
      projectId: process.env.GCP_PROJECT,
    });

    this.log = this.logging.log("microservices");

    this.metadata = {
      labels: {},
    };
  }

  setMetadataField(fieldName, fieldValue) {
    this.metadata.labels[fieldName] = fieldValue;
  }

  // NB: message can be a string, but can also be a JSON object (not an Array!)

  async debug(message) {
    const entry = this.log.entry(this.metadata, message);

    await this.log.debug(entry);
  }

  async info(message) {
    const entry = this.log.entry(this.metadata, message);

    await this.log.info(entry);
  }

  async warn(message) {
    const entry = this.log.entry(this.metadata, message);

    await this.log.warning(entry);
  }

  async error(message) {
    const entry = this.log.entry(this.metadata, message);

    await this.log.error(entry);
  }
}

module.exports = Logger;

@ali-yunes
Copy link

What was the solution to this? I am facing a similar issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants