microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
320 stars 138 forks source link

[BUG] Calling the global "dispose" method prevents the express server from running #1195

Closed Apokalypt closed 10 months ago

Apokalypt commented 10 months ago

Context

I'm currently developing an API that will, potentially, call the dispose method in order to stop all collectors temporarily. However, once the dispose method has been called, the server will no longer respond to requests.

Code to reproduce

const ai = require('applicationinsights');
const express = require('express');

const app = express();
app.post('/log/start', (req, res) => {
    ai.setup('<valid-key>')
        .setAutoDependencyCorrelation(true)
        .setAutoCollectRequests(true)
        .setAutoCollectPerformance(false)
        .setAutoCollectExceptions(true)
        .setAutoCollectDependencies(true)
        .setUseDiskRetryCaching(true)
        .setSendLiveMetrics(false)
        .setDistributedTracingMode(ai.DistributedTracingModes.AI_AND_W3C)
        .setAutoCollectConsole(true, true);
    ai.start();

    res.status(200).send('OK');
});
app.post('/log/stop', (req, res) => {
    ai.dispose();

    res.status(200).send('OK');
});
app.listen(3000, () => console.log('Example app listening on port 3000!'));

Steps to reproduce

  1. Create a project with the code above (install dependencies required)
  2. Start the server
  3. Call the route '/log/stop'
  4. Try to call the route '/log/start' -> You will never have an answer

Environment

Apokalypt commented 9 months ago

@hectorhdzg Sorry to bother you, but do you know when the version with the fix will be released? The latest available version is still 2.7.3, released on August 16

hectorhdzg commented 9 months ago

@Apokalypt we are planning on releasing tomorrow