ApplicationInsights-node.js
ApplicationInsights-node.js copied to clipboard
Application Insight does not support Azure Function with Service Bus Queue Trigger
For Azure Function with Service Bus Queue trigger, application insight SDK startOperation code (const correlationContext = appInsights.startOperation(context, mySbMsg);) throws below exception
Exception: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined Stack: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined at validateString (internal/validators.js:124:11) at Url.parse (url.js:160:3) at Object.urlParse [as parse] (url.js:155:13) at HttpRequestParser.getOperationName (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\HttpRequestParser.js:120:86) at Function.CorrelationContextManager.startOperation (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\CorrelationContextManager.js:142:26) at Object.startOperation (C:\home\site\wwwroot\node_modules\applicationinsights\out\applicationinsights.js:141:64)
Is there plan for Application Insight NodeJS SDK to support triggers other than HTTP?
Also faced this issue and I found a workaround:
If you pass an object as second parameter of appInsights.startOperation
, the library expects it to be a HTTPRequest and in the case of a service bus message, it is the actual message and not an HTTPRequest.
In order to mitigate that, pass the function name for service bus triggers instead of the sbMsg: it will be reported with the function name on app-insights dashboard.
let correlationContext: CorrelationContext;
if (context.req !== undefined) {
correlationContext = appInsights.startOperation(context, context.req);
} else {
correlationContext = appInsights.startOperation(
context,
context.executionContext.functionName
);
}
Hi Jerome
The walkaround works, thanks.
@jeromewir We recently changed to using OpenTelemetry under the hood for context propagation. As such, this issue may no longer impact you. Please refer to OpenTelemetry JS's docs on context propagation https://opentelemetry.io/docs/languages/js/propagation/. Thank you.