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

Read log entries from jsonPayload and protoPayload. #3539

Merged
merged 5 commits into from Jul 7, 2021
Merged

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 joehan and inlined 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.

None yet

2 participants