microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
320 stars 138 forks source link

"Failed to propagate context in Azure Functions" due to "Cannot read properties of undefined (reading 'find')" #1191

Open magnus-larsson opened 10 months ago

magnus-larsson commented 10 months ago

Trying to add app insights based monitoring to my Azure Functions following the instructions here https://learn.microsoft.com/en-us/azure/azure-monitor/app/nodejs.

I get the following error in my logs when I call an API exposed by the Azure Function:

2023-08-16T19:05:56Z   [Error]   ApplicationInsights:Failed to propagate context in Azure Functions [
2023-08-16T19:05:56Z   [Error]     TypeError: Cannot read properties of undefined (reading 'find')
2023-08-16T19:05:56Z   [Information]         at AzureFunctionsHook._isHttpTrigger (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:190:39)
2023-08-16T19:05:56Z   [Information]         at AzureFunctionsHook.<anonymous> (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:94:38)
2023-08-16T19:05:56Z   [Information]         at step (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:33:23)
2023-08-16T19:05:56Z   [Information]         at Object.next (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:14:53)
2023-08-16T19:05:56Z   [Information]         at C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:8:71
2023-08-16T19:05:56Z   [Information]         at new Promise (<anonymous>)
2023-08-16T19:05:56Z   [Information]         at __awaiter (C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:4:12)
2023-08-16T19:05:56Z   [Information]         at C:\home\site\wwwroot\node_modules\applicationinsights\out\AutoCollection\AzureFunctionsHook.js:78:136
2023-08-16T19:05:56Z   [Information]         at C:\Program Files (x86)\SiteExtensions\Functions\4.24.3\workers\node\dist\src\worker-bundle.js:2:42651
2023-08-16T19:05:56Z   [Information]         at Generator.next (<anonymous>)
2023-08-16T19:05:56Z   [Information]   ]

The Typescript code looks like:

let appInsights = require('applicationinsights');
appInsights.setup().start();

import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";

export async function service2(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    const name = request.query.get('name') || await request.text() || 'world-2';

    const version='S2, v5';

    return { body: `${version}, response "${name}"` };
};

app.http('service2', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    handler: service2
});

dependencies in package.json:

  "dependencies": {
    "@azure/functions": "^4.0.0-alpha.9",
    "applicationinsights": "^2.7.3"
  },

I have defined APPLICATIONINSIGHTS_CONNECTION_STRING in my config.

Node version:

$ node -v
v18.17.1

Any idea of what I'm doing wrong?

alan-bentley-pgh commented 9 months ago

@magnus-larsson did you ever figure out your issue here? I'm running into the same thing

hectorhdzg commented 9 months ago

@magnus-larsson, @alan-bentley-dsg , we recently update our code to support latest programming model in Azure Functions, we will be releasing a new version of the SDK on Monday, please give it a try when that is available and let us know if the problem persist.

alan-bentley-pgh commented 9 months ago

awesome, thank you @hectorhdzg ! Will retry Monday after the latest SDK release

alan-bentley-pgh commented 9 months ago

@hectorhdzg I retried running with the latest release tag (3.0.0-beta.9) - I'm not seeing that error message from before and now able to see log messages pushed up to my app insights instance, but also seeing some additional "invalid metric" logs:

[2023-09-26T13:17:50.049Z] ApplicationInsights:Invalid metric name: "Request Success Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.049Z] ApplicationInsights:Invalid metric name: "Request Failure Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.049Z] ApplicationInsights:Invalid metric name: "Retry Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.049Z] ApplicationInsights:Invalid metric name: "Throttle Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Exception Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Duration". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Success Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Failure Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Retry Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Throttle Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Exception Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Duration". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Success Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.050Z] ApplicationInsights:Invalid metric name: "Request Failure Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Retry Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Throttle Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Exception Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Request Duration". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:@azure/opentelemetry-instrumentation-azure-sdk [
[2023-09-26T13:17:50.051Z]   'Module @azure/core-tracing has been loaded before @azure/opentelemetry-instrumentation-azure-sdk so it might not work, please initialize it before requiring @azure/core-tracing'
[2023-09-26T13:17:50.051Z] ]
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Request Success Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Request Failure Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Retry Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.051Z] ApplicationInsights:Invalid metric name: "Throttle Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Exception Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Request Duration". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Request Success Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Request Failure Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Retry Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Throttle Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Exception Count". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "Request Duration". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.052Z] ApplicationInsights:Invalid metric name: "\Process(??APP_WIN32_PROC??)\Private Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.053Z] ApplicationInsights:Invalid metric name: "\Memory\Available Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.053Z] ApplicationInsights:Invalid metric name: "\Processor(_Total)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.053Z] ApplicationInsights:Invalid metric name: "\Process(??APP_WIN32_PROC??)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2023-09-26T13:17:50.053Z] no original function multi to wrap
[2023-09-26T13:17:50.106Z] Worker process started and initialized.
JacksonWeber commented 2 months ago

@alan-bentley-pgh Most of these invalid metric logs are resolved as of the latest release. Those related to performance counters (ex: \ASP.NET Aplications...) will be resolved in a later update, but they should have no functionality impact on tracking your application.

JacksonWeber commented 1 month ago

@alan-bentley-pgh All of the invalid metric name warnings are resolved as of 3.1.0.