azure - 应用程序洞察不记录请求、页面浏览量、自定义事件
问题描述
我已将我的应用程序从开发人员提升到舞台环境应用程序服务。
但是现在我看不到页面视图,自定义事件被记录在我的 Application Insights 中,这在 Dev 中记录得很好。
为什么会这样?
笔记:
1.我使用正确的仪器密钥
2.Track调用是200
3.该应用程序是使用 React 构建的 Teams 选项卡应用程序,并使用 React 插件获取应用程序洞察力(在开发中运行良好)
4.开发环境的运行时堆栈是Node.Js,但Stage是.NET(这会导致这个问题吗?)
另请注意,我已经经历了故障排除指南中的所有场景
解决方案
问题为您解决了吗?
如果没有,请确保为 React.js 安装 npm 包,
npm install @microsoft/applicationinsights-react-js
npm install @microsoft/applicationinsights-web
初始化与 Application Insights 的连接:
在 AppInsights.js 中
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { ReactPlugin } from '@microsoft/applicationinsights-react-js';
import { createBrowserHistory } from 'history';
const browserHistory = createBrowserHistory({ basename: '' });
const reactPlugin = new ReactPlugin();
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE',
extensions: [reactPlugin],
extensionConfig: {
[reactPlugin.identifier]: { history: browserHistory }
}
}
});
appInsights.loadAppInsights();
export { reactPlugin, appInsights };
然后用高阶组件函数包装您的组件以启用 Application Insights:
import React from 'react';
import { withAITracking } from '@microsoft/applicationinsights-react-js';
import { reactPlugin, appInsights } from './AppInsights';
// To instrument various React components usage tracking, apply the `withAITracking` higher-order
// component function.
class MyComponent extends React.Component {
...
}
// withAITracking takes 4 parameters ( reactPlugin, Component, ComponentName, className)
// the first two are required and the other two are optional.
export default withAITracking(reactPlugin, MyComponent);
这将帮助您跟踪所有请求、页面浏览量和自定义事件。
另请查看此文档以获取更多参考:Javascript React SDK Plugin
推荐阅读
- javascript - 有没有办法在 javascript 类中创建一个方法来创建变量?
- javascript - 编写此代码的更好方法?我试图避免双重返回语句
- django - Django Unittest 无法运行 TypeError: isinstance() arg 2 must be a type or tuple of types on a machine but not others
- javascript - 我的反应表代码有问题吗?我看不到我的桌子
- python - 如何通过构造解析bin文件?
- abap - 如何在运行时检查应用程序服务器上的文件大小?
- swift - 在 tabBarController 上隐藏图像
- javascript - 处理从交易结果中分析命令的最佳方法是什么?
- azure - 您如何明确放弃从主题消息/订阅触发的 azure 函数中的消息?
- python - 用平均值减去矩阵的每个元素,而不导入模块