Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically updating config (for extensions in my case) #1427

Closed
mikecabana opened this issue Nov 16, 2020 · 9 comments
Closed

Dynamically updating config (for extensions in my case) #1427

mikecabana opened this issue Nov 16, 2020 · 9 comments

Comments

@mikecabana
Copy link

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
@mikecabana mikecabana changed the title Dynamically updating extensions Dynamically updating config (for extensions in my case) Nov 16, 2020
@MSNev MSNev self-assigned this Nov 16, 2020
@MSNev
Copy link
Collaborator

MSNev commented Nov 16, 2020

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

  • Enable updating / reconfiguring of plugins (and core) after initialization
  • As part of this Investigate potential for dynamically (late loading) of additional plugins after initialization (ideally, this will get included, but needs to be investigated first)

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)

@mikecabana
Copy link
Author

mikecabana commented Nov 16, 2020

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?

@MSNev
Copy link
Collaborator

MSNev commented Nov 16, 2020

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.

@mikecabana
Copy link
Author

@MSNev Gotcha - I'll give it a shot thanks!

@mikecabana
Copy link
Author

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

@MSNev
Copy link
Collaborator

MSNev commented Apr 15, 2022

An update on progress, we originally intended to deliver this as part of the next release v2.8.0 but because of the size of the changes required the next release will only partial support this.

Simplistically, v2.8.0 is going to support completely unloading and re-initializing the SDK (not ideal but a start) and we are planning that the next major release (v3.0.0) will include full support to dynamically update the config on the fly.

Timeline wise apart from bug fixes to the 2.8.0 lineage 3.x will be the next release that we will start working on (initially in the beta branch).

One other planned change to 3.x is that we are currently intending to drop ES3 (IE8) support.

@MSNev
Copy link
Collaborator

MSNev commented Apr 18, 2022

v2.8.0 is now released and published to NPM, because of the size of the change it isn't planned to be fully available on the CDN until April 25th, 2022

@MSNev
Copy link
Collaborator

MSNev commented Apr 22, 2022

Please use v2.8.1 as v2.8.0 had a couple of issue, specifically it disabled automatic exception tracking.

@MSNev MSNev modified the milestones: 3.(beta).x (~v3.0.0), 3.0.0 Apr 11, 2023
@MSNev MSNev added fixed - waiting release PR Committed and waiting deployment released - NPM labels Apr 11, 2023
@MSNev MSNev closed this as completed Apr 12, 2023
@MSNev MSNev removed investigating Investigating the issue fixed - waiting release PR Committed and waiting deployment labels Apr 12, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants