Is your feature request related to a problem? Please describe.
I'd like to be able to update the configuration of application insights after it has already been initialized. I've wrapped the package in an Angular Library using APP_INITIALIZER so using ai is much more straight forward for my team. The only issue is that something like the Angular plugin requires to run an init step. Not really compatible with passing config using forRoot({...})
Describe the solution you'd like
I'd like to be able to do something like
addExtension(extension: ITelemetryPlugin, config?: { [extKey: string]: { [configKey: string]: any } }): void {
const extensions = [...this.config.extensions, extension];
this.config = { ...this.config, extensions };
let extensionConfig = this.config.extensionConfig;
if (config) {
extensionConfig = { ...extensionConfig, config };
}
this.appInsights = new ApplicationInsights({
config: this.config
});
this.appInsights.reLoadAppInsights(); // <--- new function to update config
}
Running the above code of course errors out with
ERROR Error: Core should not be initialized more than once
Hi @mikecabana, yes 100% agree, this is one of the enhancements that we will be looking at creating next year (based on current planning). It may not be exactly as you have described, but the high level design is
We can't commit to a timeframe just yet as there are some other largish features ahead of this work and this has implications on minification / tree shaking efforts (i.e. it's going to add more code)
Hey @MSNev that's awesome to hear. Looking forward to using this enhancement when it's released!!
It's not really a show stopper for now on my end but would you have any suggestions or workarounds that can get me going in the meantime?
At this point no, the only suggestion I can immediately think of would be to create a lazy initialization layer. I assume your not using the snippet, in which case as part of that layer you would have to cache (save into an array -- the same way as the ai queue ) any calls you have and replay them one you initialize.
@MSNev Gotcha - I'll give it a shot thanks!
In case anyone comes across this thread, I think I came up with a decent workaround that's not to hard on the eyes ;).
Improvements are welcome.
https://stackblitz.com/edit/angular-ivy-iujyla?devtoolsheight=33&file=src/app/app.module.ts
Most helpful comment
Hi @mikecabana, yes 100% agree, this is one of the enhancements that we will be looking at creating next year (based on current planning). It may not be exactly as you have described, but the high level design is
We can't commit to a timeframe just yet as there are some other largish features ahead of this work and this has implications on minification / tree shaking efforts (i.e. it's going to add more code)