Fadi
Fadi

Reputation: 13

appInsights.setup().start(); returns an error

I'm using appInsights v2.1.4 in my NodeJs Azure Function. The app key in provided by the APPINSIGHTS_INSTRUMENTATIONKEY variable in the function configuration.

I have setup a class as such

const appInsights = require('applicationinsights');

class AppInsightsLog {
    error (context, eventName, error) {
        context.log.error(error);

        appInsights.setup().start();
        const client = appInsights.defaultClient;
        client.trackEvent({ name: `Catch error: ${eventName}`, properties: error });
    }

    info (context, eventName, extraInfo = null) {
        context.log.info(eventName);

        appInsights.setup().start();
        const client = appInsights.defaultClient;
        client.trackEvent({ name: `Log info: ${eventName}`, properties: extraInfo });
    }
}

module.exports = { AppInsightsLog };

And using it like so

/* ... other imports before it ... */
const { AppInsightsLog } = require('../../../utils/AppInsightsLog');
const appInsightsLog = new AppInsightsLog();

class Post {
    async data (context, feedRow) {
        try {
            ...
            appInsightsLog.info(context, `processing feed: ${feedRow.feedtype}`);
            ....
        } catch (error) {
            appInsightsLog.error(context, 'ProcessRawDataQueue', error);
            return { statusCode: 500, body: error.message };
        }
    }
}

I'm getting this error:

[Error] TypeError: api_1.createContextKey is not a functionat Object. (D:\home\site\wwwroot\node_modules@opentelemetry\core\build\src\trace\suppress-tracing.js:20:36)at Module._compile (internal/modules/cjs/loader.js:999:30)at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)at Module.load (internal/modules/cjs/loader.js:863:32)at Function.Module._load (internal/modules/cjs/loader.js:708:14)at Module.require (internal/modules/cjs/loader.js:887:19)at Module.patchedRequire [as require] (D:\home\site\wwwroot\node_modules\diagnostic-channel\dist\src\patchRequire.js:15:46)at require (internal/modules/cjs/helpers.js:74:18)at Object. (D:\home\site\wwwroot\node_modules@opentelemetry\core\build\src\baggage\propagation\HttpBaggagePropagator.js:20:28)at Module._compile (internal/modules/cjs/loader.js:999:30)

Any ideas what is wrong?

Upvotes: 1

Views: 852

Answers (2)

Pedro Monteagudo
Pedro Monteagudo

Reputation: 416

Just upgrading @azure/storage-blob doesn't neccesarily fix the issue. For me what worked correctly was having these two dependencies with these versions:

    {
      "dependencies": {
        "@azure/storage-blob": "^12.0.1",
        "applicationinsights": "^2.2.1",
      }
    }

I guess there is some incompatibility between some versions

Upvotes: 1

Fadi
Fadi

Reputation: 13

We were using an old version of @azure/storage-blob when I updated it everything worked 👍

Upvotes: 0

Related Questions