Open JPStrydom opened 6 months ago
@JPStrydom I was able to fix your example by modifying your index.js
to be the following:
let appInsights = require('applicationinsights');
appInsights.setup("your-instrumentation-key")
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setAutoCollectPreAggregatedMetrics(true)
.setSendLiveMetrics(false)
.setInternalLogging(false, true)
.enableWebInstrumentation(false)
.start()
const { createLogger, transports } = require('winston');
const logger = createLogger({
transports: [new transports.Console()]
})
async function test () {
logger.info('Info Test');
logger.warn('Warn Test');
logger.error('Error Test');
await appInsights.defaultClient.flush();
}
test();
The modification just ensures that the application waits to exit until the Application Insights SDK has gotten a chance to export the Winston logs. Please let me know if this example makes sense or if you have any other questions. Thanks!
Hi @JacksonWeber !
Thanks for taking the time to reach out.
I tried your example and I managed to get a few logs, but still received many of the error logs:
Was your thinking that the client needs to be flushed after every log? I'm just scared that this makes our logging asynchronous, which we've not currently catered for.
@JPStrydom It's great you were able to see the Winston logs! Those other logs you're seeing are warnings and they come from a few sources. The "accessing resource attributes" warning is from OpenTelemetry and reports this warning because we have a VM resource detector that makes an API call to a VM metadata service. Given that you're not running in that environment, the call times out, but using the SDK before that timeout generates this warning for now. It won't impact functionality for you.
The warning regarding extended metrics is because you're attempting to set a configuration option that used to modify the behavior of collection of extended metrics. However, like the warning mentions, we don't support extended metrics in versions greater than or equal to 3.0.0.
Hi @JacksonWeber
Thanks again!
Given the setup config we have:
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setAutoCollectPreAggregatedMetrics(true)
.setSendLiveMetrics(false)
.setInternalLogging(false, true)
.enableWebInstrumentation(false)
Is there anything we need to change to get rid of the errors/warnings you mentioned?
I'd also just like some clarification on when exactly we need to call the appInsights.defaultClient.flush()
function:
@JPStrydom For removing the extended metrics warning, simply change .setAutoCollectPerformance(true, true)
to .setAutoCollectPerformance(true)
. You'll still auto collect performance counters, but the second parameter is for setting auto collection of extended metrics (which isn't supported).
As for the resource attributes warning, this isn't currently ignorable because we turn on resource detection by default for popular Azure Resources.
Regarding on when to use flush()
. It entirely depends on your application. If Node.js process flow ends quickly after a call to log telemetry, then it may make sense to await a flush()
however, in most cases, such as a long running Node.js server application there typically isn't any need to asynchronously await a flush.
@JPStrydom Please let me know if this has been able to resolve your issue, thanks!
@JPStrydom Please let me know if this has been able to resolve your issue, thanks!
We've temporarily paused development on the AppInsights integration, but as soon as we resume, I'll test and let you know. Thanks!
Issue
We're unable to get
applicationinsights
to communicate with our AppInsights instance viawinston
.Versions
Steps to reporduce
I've attached a minimum reproduceable example here: applicationinsights-winston-issue.zip
In the example, we currently have the following
package.json
file:And the following
index.js
file:npm i
npm t
See the errors and logs in the terminal:
What else we've tried
We've also tried manually sending the logs to AppInsights with:
When running like this, then we get the following logs:
This appears to work, but then we get an additional
info
log (bottom of the above example image) and a few of theAccessing resource attributes before async attributes settled []
error logs (top and 2nd from the bottom of the above example image) as well.This solution also requires us to install the
stream
package, which is not ideal.How to fix?
We are receiving logs from our other applications, so AppInsights appears to be working, but we're unable to communicate via Winston from on NodeJS app.
How can we go about integrating with Winston?