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

message is empty when using jsonPayload with functions.logger #1404

Closed
nilsreichardt opened this issue May 24, 2023 · 2 comments · Fixed by #1416
Closed

message is empty when using jsonPayload with functions.logger #1404

nilsreichardt opened this issue May 24, 2023 · 2 comments · Fixed by #1416

Comments

@nilsreichardt
Copy link

nilsreichardt commented May 24, 2023

Related issues

[REQUIRED] Version info

node: 16

firebase-functions: 4.4.0

firebase-tools: 11.24.1

firebase-admin: 10.3.0

[REQUIRED] Test case

exports.loggingtest = functions.https.onRequest((req, res) => {
  functions.logger.info({
    message: "we are healthy",
    userId: "123",
  });
  res.status(200).send("OK");
});

[REQUIRED] Steps to reproduce

  1. Use code from "Test case"
  2. Call the function
  3. Open Cloud Logging Explorer

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

message is an empty string.

image

Were you able to successfully deploy your functions?

Yes

Additional

When using @google-cloud/logging, everything works:

// Imports the Google Cloud client library
import { Logging } from "@google-cloud/logging";

async function quickstart(
  projectId = "PROJECT_ID", // Your Google Cloud Platform project ID
  logName = "my-log" // The name of the log to write to
) {
  // Creates a client
  const logging = new Logging({ projectId });

  // Selects the log to write to
  const log = logging.log(logName);

  // The metadata associated with the entry
  const metadata = {
    resource: { type: "global" },
    // See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity
    severity: "INFO",
  };

  const json = {
    message: "Hello, world!",
    userId: "123",
  };

  // Prepares a log entry
  const entry = log.entry(metadata, json);

  async function writeLog() {
    // Writes the log entry
    await log.write(entry);
    console.log(`Logged: ${JSON.stringify(json)}`);
  }

  // eslint-disable-next-line @typescript-eslint/no-floating-promises
  writeLog();
}


// eslint-disable-next-line @typescript-eslint/no-floating-promises
quickstart();

image

@Berlioz
Copy link
Contributor

Berlioz commented Jun 8, 2023

Pretty sure the string message has to be the first parameter of the function call, and then the structured payload as the second one? Like you'd want to be doing

  functions.logger.info("we are healthy", {
    userId: "123",
  });

I'll definitely pass on the comment that our docs could be better about this.

@nilsreichardt
Copy link
Author

Yes, this work @Berlioz, thanks! 👍 But also thanks to @mbleigh for fixing this so both solutions work 🎉 Because the way described in this issue is how Cloud Logging shows it in their documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants