Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions providers/logging/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,30 @@ class ApplicationInsightsTransport extends Transport {
return
}

const properties = buildProperties(info)
if (info.level === 'error') {
if (info.stack) {
const err = new Error(info.message)
err.stack = info.stack
this.aiClient.trackException({ exception: err, properties })
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No catch here, so a throw from the AI client still escapes through Winston into the caller. The callback fires, but the calling code crashes. Catch it and drop the telemetry quietly (or console.error it). Losing a log line beats killing the request that produced it.

const properties = buildProperties(info)
if (info.level === 'error') {
if (info.stack) {
const err = new Error(info.message)
err.stack = info.stack
this.aiClient.trackException({ exception: err, properties })
} else {
this.aiClient.trackTrace({
message: info.message,
severity: appInsights.KnownSeverityLevel.Error,
properties
})
}
} else {
this.aiClient.trackTrace({
message: info.message,
severity: appInsights.KnownSeverityLevel.Error,
severity: mapLevel(info.level),
properties
})
}
} else {
this.aiClient.trackTrace({
message: info.message,
severity: mapLevel(info.level),
properties
})
} finally {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a catch paired with this. Without one the exception still propagates after callback() runs, so we get the callback guarantee but lose the safety.

callback()
}

callback()
}
}

Expand Down