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

Allow properly disposing AI #1667

Closed
olee opened this issue Sep 12, 2021 · 3 comments
Closed

Allow properly disposing AI #1667

olee opened this issue Sep 12, 2021 · 3 comments
Assignees
Milestone

Comments

@olee
Copy link

olee commented Sep 12, 2021

I am using application insights through npm in a web application and also running the project in nodejs for jest tests.
However, because AppInsightsCore.pollInternalLogs creates a setInterval which handle is never stored and there is no way to dispose of it, jest never manages to shut down properly.

Would you mind properly storing the returned handle from the setInterval and provide some kind of dispose function to stop this polling?

Alternatively, could it be possible to add an option by eg. setting diagnosticLogInterval to 0 to completely disable this polling?
From my tests I noticed that this internal queue never seems to be used anyway and always stays empty.

EDIT: For now I managed to disable this feature by executing this code before AI initialization:

        const ai = new ApplicationInsights({ config: { /* ... */ } });
        // Disable pollInternalLogs to prevent jest from properly shutting down
        ai.pollInternalLogs = () => undefined;
        ai.loadAppInsights();
@kryalama
Copy link
Contributor

Setting the interval to 0 might not solve the problem. setInterval actually has a minimum amount which is implicit, and depends on the browser. I believe it is around 10ms. We can just return without creating a setInterval when diagnosticLogInterval is set to 0.

@kryalama kryalama self-assigned this Sep 16, 2021
@kryalama kryalama added the keep Do not Mark as Stale and close label Sep 16, 2021
@olee
Copy link
Author

olee commented Sep 18, 2021

@kryalama that was of course what I was implying.
If it worked that way, I would have solved it by setting it to 0 of course 😂

@MSNev MSNev added this to the 2.x.x (Future Release) milestone Sep 30, 2021
@kryalama kryalama added fixed - waiting release PR Committed and waiting deployment and removed keep Do not Mark as Stale and close labels Oct 1, 2021
@MSNev MSNev closed this as completed Nov 10, 2021
@github-actions
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 Nov 11, 2022
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

3 participants