Skip to content

functions.logger.log crashes function if passed certain objects #737

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

Closed
nikmartin opened this issue Jul 14, 2020 · 4 comments
Closed

functions.logger.log crashes function if passed certain objects #737

nikmartin opened this issue Jul 14, 2020 · 4 comments
Assignees

Comments

@nikmartin
Copy link

[REQUIRED] Version info

node: 10

firebase-functions: 3.7.0

firebase-tools: 8.4.3

firebase-admin: 8.12.1

[REQUIRED] Test case

const functions = require('firebase-functions');
exports.loggerTest = functions.https.onCall((data, context) => {
    functions.logger.log('context:', context);
});

[REQUIRED] Steps to reproduce

I have two scenarios that will reliably crash a firebase function using the logger:

  • log context in a callable
  • log the entire request in an https function

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

1:18:40.769 PM execution took 3196 ms, finished with status code: 500 |  
  at func (/workspace/node_modules/firebase-functions/lib/providers/https.js:272:32) 
  at process._tickCallback (internal/process/next_tick.js:68:7) 
  at exports.assignCard.functions.https.onCall (/workspace/index.js:3591:20) 
  at Object.log (/workspace/node_modules/firebase-functions/lib/logger.js:45:5)
  at write (/workspace/node_modules/firebase-functions/lib/logger.js:12:84) 
  at JSON.stringify (<anonymous>) 
  Unhandled error TypeError: Converting circular structure to JSON

Were you able to successfully deploy your functions?

Yes

@nikmartin
Copy link
Author

Obviously my logging the entire context object is probably incorrect, but it was this way for 2 years until i swapped out all console.log() for functions.logger.log() after upgrading to node 10

@nikmartin
Copy link
Author

I attempted to fix and submit a PR, but I ran out of time. If it's not obvious, objects like requests on https functions, or context in callables have circular references in them, so using nodes util.inspect on them would likely solve the issue. The problem is I'm not great at mocha test writing, and I could not come up with a test for when util inspect returns an object reference named [Circular]. That's the object reference itself, NOT the string '[Circular]', so I couldn't get a test working in the short amount of time I allotted myself to work on it.

@mbleigh
Copy link
Contributor

mbleigh commented Jul 15, 2020

This is a little more complex than just using util.inspect since it's actually important to have valid JSON output for structured logging. We'll need to add circular reference detection to the logger, this is something I'll look into.

@rhodgkins
Copy link
Contributor

@laurenzlong / @mbleigh can we get some movement on this issue please - #776 does fix it but a comment in that PR does raise a concern.

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

Successfully merging a pull request may close this issue.

4 participants