When using context.log.error() in an Azure Function to log a message, the message field in Application Insights entries is allowed to contain line breaks. When this applicationsinsights package is used to intercept console.error() messages, every line break results in an independent entry in Application Insights. For example, consider this simple HTTP trigger function (Node.js):
import { Context, HttpRequest } from "@azure/functions";
module.exports = function (context: Context, request: HttpRequest): void {
try {
throw new Error("Nope, not today.");
} catch (e) {
if (e instanceof Error) {
console.error(`Failed to handle request\nURL: ${request.url}\n${e.stack || ""}`);
}
}
context.res = {};
context.done();
};
The resulting Application Insights log entries are split and the severity level assigned to each also varies:
For comparison, here's the single entry generated when context.log.error() is used instead of console.error():
When using
context.log.error()
in an Azure Function to log a message, themessage
field in Application Insights entries is allowed to contain line breaks. When thisapplicationsinsights
package is used to interceptconsole.error()
messages, every line break results in an independent entry in Application Insights. For example, consider this simple HTTP trigger function (Node.js):The resulting Application Insights log entries are split and the severity level assigned to each also varies:
For comparison, here's the single entry generated when
context.log.error()
is used instead ofconsole.error()
: