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

ApplicationInsights blocks scripts from exiting #390

Closed
richardspence opened this issue May 3, 2018 · 3 comments
Closed

ApplicationInsights blocks scripts from exiting #390

richardspence opened this issue May 3, 2018 · 3 comments
Labels

Comments

@richardspence
Copy link

I'm using application insights to instrument a gulp build script, and it blocks gulp from exiting when started.

I manually need to run client.dispose() after each entry task's exit point (on finish, on error) and the error handlers of all the dependencies.

I'm guessing the architecture has a log collector agent that is running in the background. It would be good to have a synchronous mode where that's not created, and flush the events on process exit.

@OsvaldoRosado
Copy link
Member

OsvaldoRosado commented May 3, 2018

Linking some related issues: #54, #220, #310, #331

Are you calling start()? This initializes quite a few background loops (such as for autocollection of cpu and memory usage). In scenarios like this I would suggest not calling start() to disable these background loops. You'll also need to actively disable disk retry caching, as this is known to impact script exit (see https://stackoverflow.com/a/49441135 for an example)

Without start() or disk retry caching, the primary thing that's going to delay your process exit is the loop for batching events (though this should be only a delay and not a permanent no-exit). If the delay isn't acceptable (default 15 seconds), and you are firing very few telemetry events(batching isn't necessary), you can disable it in the configuration either by changing client.config.maxBatchSize or client.config.maxBatchInterval. If you do need batching, the easiest solution here is call client.flush

@OsvaldoRosado
Copy link
Member

As an extra note, it's definitely a bug if this SDK keeps you from exiting after all batched items have been sent (when no extra collection features are enabled), rather than a missing mode. This should be covered in this test, but perhaps it's missing something:

https://github.com/Microsoft/ApplicationInsights-node.js/blob/develop/Tests/js/endToEnd.js

@richardspence
Copy link
Author

Yes I was using client.start() as I thought it was required.

Changing my configuration to this, solves my issue:

const appInsights = require('applicationinsights');
appInsights.setup("...")
    .setAutoCollectExceptions(true)
    .setAutoCollectConsole(true)

appInssights.defaultClient.config.maxBatchIntervalMs = 100;

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants