node.js - appInsights.setup().start(); 返回错误
问题描述
我在我的 NodeJs Azure 函数中使用 appInsights v2.1.4。由函数配置中的 APPINSIGHTS_INSTRUMENTATIONKEY 变量提供的应用密钥。
我已经设置了一个这样的类
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 )
有什么想法有什么问题吗?
解决方案
仅仅升级@azure/storage-blob
并不一定能解决问题。对我来说,正确工作的是这些版本具有这两个依赖项:
{
"dependencies": {
"@azure/storage-blob": "^12.0.1",
"applicationinsights": "^2.2.1",
}
}
我猜有些版本之间存在一些不兼容
推荐阅读
- javascript - 无法让 audio.play() 和 audio.pause() 工作
- html - 使用 CSS 的响应式侧边栏交互
- regex - 用正则表达式匹配ruby中的字符串后获取数字
- python - 优化 numpy 数组创建
- php - Cors 在 Laravel 6 和 vue js 2 中不起作用
- jquery - Jquery获取下拉标签并制作默认选择选项项目占位符
- azure-devops - nuget.build.tasks.pack - 需要构建错误作者
- python - 请解释这段代码的结论
- tensorflow - clamp_ 在 pytorch 中做了什么以及如何将其更改为 tensorflow 2.0?
- automata - 需要更好地解释这个冗长的 DFA 单词问题(CS : Formal Language & Automata course)