microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
324 stars 141 forks source link

Include traces as well as exceptions for bunyan to avoid loss of information in messages #1124

Closed skhilliard closed 1 year ago

skhilliard commented 1 year ago

Please note that the only "real" change is to AutoCollection/diagnostic-channel/bunyan.sub.ts. The other changes (update to gitignore and including output files) were just convenient for us to use this fork for our code until a final solution is implemented in this code base.

For issue: https://github.com/microsoft/ApplicationInsights-node.js/issues/1120

JacksonWeber commented 1 year ago

This PR wont work for the us as it would send all errors/exceptions as traces as well effectively creating duplicate telemetry for everyone using Bunyan.

skhilliard commented 1 year ago

This PR wont work for the us as it would send all errors/exceptions as traces as well effectively creating duplicate telemetry for everyone using Bunyan.

I can understand that.....as a temporary measure for us, I think we may update the code to also check the severity level rather than create duplicate entries....this is what I am considering.

const subscriber = (event: IStandardEvent<bunyan.IBunyanData>) => {
    let message = event.data.result as string;
    clients.forEach((client) => {
        const AIlevel = bunyanToAILevelMap[event.data.level];
        try {
            // Try to parse message as Bunyan log is JSON
            //   Only log as exception for level of Critical
            let log: any = JSON.parse(message);
            if (log.err && AIlevel === SeverityLevel.Critical) {
                let bunyanError = new Error(log.err.message);
                bunyanError.name = log.err.name;
                bunyanError.stack = log.err.stack;
                client.trackException({ exception: bunyanError });
                return;
            }
        }
        catch (err) {
            // Ignore error
        }
        client.trackTrace({ message: message, severity: AIlevel });
    });
};
hectorhdzg commented 1 year ago

Config was added in 2.6.0 to address this, thank you.