[英]Azure Application Insights implementation angular6
我正在尝试在angular6中实施Azure Application Insights实施,
我得到以下错误:
Failed to initialize AppInsights JS SDK: Cannot load Application Insights SDK, no instrumentationKey was provided.
这意味着我编写的代码正在执行(从这里得到启发)
export class AppInsightsService {
private config: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: AppConfig.configuration ? AppConfig.configuration.applicationInsights.instrumentationKey : null,
};
constructor() {
if (!AppInsights.config) {
AppInsights.downloadAndSetup(this.config);
}
}
加载函数之前:-
{
provide: APP_INITIALIZER,
useFactory: initializeApp,
deps: [AppConfig], multi: true,
},
// Load app-settings which has key also.
export function initializeApp(appConfig: AppConfig): () => Promise<void> {
return () => appConfig.load();
}
load(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.http.get<Configuration>(this.baseUrl + 'api/BackEnd/GetAppSettings').toPromise().then((result) => {
AppConfig.configuration = result; `// here loading key from app settings.`
resolve();
}).catch((response: any) => {
});
});
}
问题:如何加载AppInsights.downloadAndSetup(this.config); 从加载函数响应中获取密钥后?
您最好的建议是什么,如何在应用程序中实现相同的APM?
提前致谢。
免责声明:我自己尚未在一个有角度的项目上设置ApplicationInsights,我只是针对您的帖子研究了这个主题。
关于您的第一个问题:也许您可以在加载函数中将AppConfig的配置修改为主题调用AppConfig.configuration.next(result),在AppInsightsService中您可以拥有以下内容:
constructor() {
AppConfig.configuration.pipe(take(1)).subscribe(
config => AppInsights.downloadAndSetup(config))
}
老实说,这有点混乱,并且100%并不是最干净漂亮的方法,但是它可以工作。
如果您愿意为处理此问题的项目添加依赖项,则可以考虑https://github.com/TrilonIO/angular-application-insights
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.