gpt4 book ai didi

typescript - VSC 扩展的 Application Insights 遥测收集

转载 作者:行者123 更新时间:2023-12-03 02:00:07 25 4
gpt4 key购买 nike

我正在 Visual Studio Code 中开发一个扩展(适用于 Visual Studio Code),并使用 Application Insights 来收集遥测数据。

我想在 Application Insights 退出 session 之前将我收集的所有信息发送到它们。

我尝试使用以下代码(在 Typescript 中)来执行此操作,但它不起作用:

context.subscriptions.push(
//First apporach that didn't work
// new vscode.Disposable(() => {
// telemetryInst.sendExperiment();
// telemetryInst.sendData(trial);
// console.log("Sent Telemetry");
// })

//second approach
{
dispose: () => {
telemetryInst.sendExperiment();
telemetryInst.sendData(trial);
console.log("Sent Telemetry");
}
}
);

我不知道在用户退出 session (他们使用我的扩展程序的 session )之前可以采取任何其他方法将数据发送到 Application Insights。

最佳答案

import  {  ApplicationInsights  }  from  '@microsoft/applicationinsights-web';
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: 'd03e30b9-6973-4f6c-8a3c-e9f2cf5a8ec1',

},
});

appInsights.loadAppInsights();
appInsights.trackPageView();

Application Insights
function sendCustomEvent(eventName: string, properties?: { [key: string]: any }) {
appInsights.trackEvent({ name: eventName, properties });
}
sendCustomEvent("CustomEvent", { key1: "2", key2: "3" });
console.log("Sent Telemetry...");

enter image description here

异常(exception):


appInsights.loadAppInsights();

try {

const someUndefinedVariable: any = undefined; // Placeholder variable

const result = someUndefinedVariable.undefinedFunction();

} catch (error) {

appInsights.trackException({ exception: error });

}

enter image description here

成功:

const  someVariable: any = 'Hello, World!';  
console.log(someVariable);
appInsights.trackEvent({ name: 'OperationSuccess', properties: { message: 'Operation succeeded' } });

enter image description here

自定义消息和安全级别:

appInsights.trackTrace({ message: 'Operation succeeded: Hello, World!', severityLevel: 1 });

enter image description here

有关更多详细信息,请参阅此 azure-docs用于自定义事件和指标的 Application Insights API。

关于typescript - VSC 扩展的 Application Insights 遥测收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76542871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com