I'm using Firebase functions along with Stackdriver.
Stackdriver is very well integrated with Firebase functions, so I can easily log errors with the console.error
command.
But, I want to record not only about error object but also query parameters.
If I can record error object and query paramters in the same log line, they can be easily grouped and exported.
Is there a easy way to add information to error log on Stackdriver like below?
console.error(new Error('Invalid query'), req.query)
Thanks.
--- edit
I tried the following code. This can add a query parameter to the log entry, but unfortunately Stackdriver puts all the errors in one group as shown in the screenshot below. All errors are grouped together even though each error is different type and occurs in different file. I expect Stackdriver Error Reporting to group errors by error type or stack trace as usual.
index.js
const functions = require('firebase-functions')
const raiseReferenceError = require('./raiseReferenceError')
const raiseSyntaxError = require('./raiseSyntaxError')
const raiseTypeError = require('./raiseTypeError')
exports.stackdriverErrorLogging = functions.https.onRequest((req, res) => {
try {
switch (Math.round(Math.random() * 2)) {
case 0:
raiseReferenceError()
break
case 1:
raiseSyntaxError()
break
default:
raiseTypeError()
break
}
} catch (error) {
console.error({
error: error,
method: req.method,
query: req.query
})
}
res.send('Hello from Firebase!')
})
raiseReferenceError.js
module.exports = () => {
console.log(foo)
}
raiseSyntaxError.js
module.exports = () => {
eval(',')
}
raiseTypeError.js
module.exports = () => {
const foo = null
foo()
}
Screenshot of results of 10 runs:
Stackdriver Error Reporting error summary page Stackdriver Error Reporting error details page