【问题标题】:appInsights.setup().start(); returns an errorappInsights.setup().start();返回错误
【发布时间】:2021-11-17 01:52:06
【问题描述】:

我在我的 NodeJs Azure 函数中使用 appInsights v2.1.4。 函数配置中的APPINSIGHTS_INSTRUMENTATIONKEY变量提供的app key。

我已经设置了一个这样的类

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 };

然后像这样使用它

/* ... 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 };
        }
    }
}

我收到此错误:

[错误] TypeError: api_1.createContextKey 不是对象的函数。 (D:\home\site\wwwroot\node_modules@opentelemetry\core\build\src\trace\suppress-tracing.js:20:36) 在 Module._compile (internal/modules/cjs/loader.js:999:30 ) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) 在 Module.load (internal/modules/cjs/loader.js:863:32) 在 Function.Module._load (internal/modules/cjs/loader.js:708:14) 在 Module.require (internal/modules/cjs/loader.js:887:19) 在 Module.patchedRequire [as require] (D:\home\site\ wwwroot\node_modules\diagnostic-channel\dist\src\patchRequire.js:15:46) 在需要 (internal/modules/cjs/helpers.js:74:18) 在对象。 (D:\home\site\wwwroot\node_modules@opentelemetry\core\build\src\baggage\propagation\HttpBaggagePropagator.js:20:28) 在 Module._compile (internal/modules/cjs/loader.js:999:30 )

有什么想法吗?

【问题讨论】:

    标签: node.js azure-functions azure-application-insights


    【解决方案1】:

    当我更新它时,我们使用的是旧版本的 @azure/storage-blob,一切正常 ?

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2018-09-30
    • 2019-05-13
    • 2019-06-22
    • 2019-05-23
    • 2021-05-30
    • 2015-03-19
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多