Skip to content

Conversation

@taeold
Copy link
Contributor

@taeold taeold commented Jun 30, 2021

Today, function logs with structured data (e.g. those generated using firebase-functions SDK's logger api) do not show up in firebase functions:log command:

// index.js
exports.hello = functions.https.onRequest((request, response) => {
  info("Hello logs!", {structuredData: true});
  info("hello world!");
  response.send("Hello from Firebase!");
});
$ firebase functions:log
2021-06-30T12:47:42.955491814Z D hello: Function execution started
2021-06-30T12:47:43.050Z I hello: # LOOK HERE: where's the message?
2021-06-30T12:47:43.050Z I hello: hello world!
2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200

This happens because structured log entries are stored in jsonPayload field, not textPayload field.

In addition to correctly parsing jsonPayload field, we will also correctly parse log entries with protoPayload fields (in most cases, these log entries come from audit logs).

After

2021-06-30T12:47:42.955491814Z D hello: Function execution started
2021-06-30T12:47:43.050Z I hello: {"message":"Hello logs!","structuredData":true}
2021-06-30T12:47:43.050Z I hello: hello world!
2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200

@taeold taeold requested review from inlined and joehan June 30, 2021 12:54
@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Jun 30, 2021
@taeold taeold changed the title Read function log from jsonPayload or protoPayload. Read log entry from jsonPayload and protoPayload. Jun 30, 2021
@taeold taeold changed the title Read log entry from jsonPayload and protoPayload. Read log entries from jsonPayload and protoPayload. Jun 30, 2021
@taeold taeold merged commit bd98505 into master Jul 7, 2021
@taeold taeold deleted the dl-cf3-logs branch July 7, 2021 22:45
devpeerapong pushed a commit to devpeerapong/firebase-tools that referenced this pull request Dec 14, 2021
Today, function logs with structured data (e.g. those generated using firebase-functions SDK's logger api) do not show up in `firebase functions:log` command:

```js
// index.js
exports.hello = functions.https.onRequest((request, response) => {
  info("Hello logs!", {structuredData: true});
  info("hello world!");
  response.send("Hello from Firebase!");
});
```

```bash
$ firebase functions:log
2021-06-30T12:47:42.955491814Z D hello: Function execution started
2021-06-30T12:47:43.050Z I hello: # LOOK HERE: where's the message?
2021-06-30T12:47:43.050Z I hello: hello world!
2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200
```

This happens because structured log entries are stored in [`jsonPayload` field](https://cloud.google.com/logging/docs/structured-logging), not `textPayload` field.

In addition to correctly parsing `jsonPayload` field, we will also correctly parse log entries with `protoPayload` fields (in most cases, these log entries come from audit logs).

*After*
```bash
2021-06-30T12:47:42.955491814Z D hello: Function execution started
2021-06-30T12:47:43.050Z I hello: {"message":"Hello logs!","structuredData":true}
2021-06-30T12:47:43.050Z I hello: hello world!
2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Manual indication that this has passed CLA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants