首页 > 解决方案 > 应用程序洞察不记录请求、页面浏览量、自定义事件

问题描述

我已将我的应用程序从开发人员提升到舞台环境应用程序服务。

但是现在我看不到页面视图,自定义事件被记录在我的 Application Insights 中,这在 Dev 中记录得很好。

为什么会这样?

笔记:

1.我使用正确的仪器密钥

2.Track调用是200

3.该应用程序是使用 React 构建的 Teams 选项卡应用程序,并使用 React 插件获取应用程序洞察力(在开发中运行良好)

4.开发环境的运行时堆栈是Node.Js,但Stage是.NET(这会导致这个问题吗?)

另请注意,我已经经历了故障排除指南中的所有场景

标签: azureazure-application-insightsmonitor

解决方案


问题为您解决了吗?

如果没有,请确保为 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


推荐阅读