Open JudithvW opened 11 months ago
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?
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;
What was the solution to this? I am facing a similar issue
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 Example of default google logging (console.log), which shows the Cloud Run labels and an instanceId.
Example of logging with this package, which removed the original labels and only added the labels set by this package.