fix(logging): prevent verbose/debug logs from leaking to Application Insights#1582
Open
yashkohli88 wants to merge 4 commits into
Open
fix(logging): prevent verbose/debug logs from leaking to Application Insights#1582yashkohli88 wants to merge 4 commits into
yashkohli88 wants to merge 4 commits into
Conversation
…Insights
The logger.on('data') event listener bypassed Winston's transport-level
filtering, forwarding verbose/debug logs to Application Insights even
when the configured level was info.
Replace with a custom ApplicationInsightsTransport extending
winston-transport that participates in Winston's built-in level
filtering. Extract shared format to logger level to avoid duplication.
Refs: clearlydefined/crawler#739
JamieMagee
reviewed
May 15, 2026
Comment on lines
+124
to
+145
| const properties = buildProperties(info) | ||
| if (info.level === 'error') { | ||
| if (info.stack) { | ||
| const exception = info.cause ? new Error(info.message, { cause: info.cause }) : new Error(info.message) | ||
| exception.stack = info.stack | ||
| this.aiClient.trackException({ exception, properties }) | ||
| } else { | ||
| this.aiClient.trackTrace({ | ||
| message: info.message, | ||
| severity: appInsights.KnownSeverityLevel.Error, | ||
| properties | ||
| }) | ||
| } | ||
| } else { | ||
| this.aiClient.trackTrace({ | ||
| message: info.message, | ||
| severity: mapLevel(info.level), | ||
| properties | ||
| }) | ||
| } | ||
|
|
||
| callback() |
Contributor
There was a problem hiding this comment.
If anything in this block throws, callback() never runs. That can leave Winston waiting on the transport for a log write that already failed. Can we wrap the AI tracking work in try/finally and call callback() from finally?
Wrap AI tracking calls in try/finally so callback() always executes. Prevents Winston from hanging on exceptions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ApplicationInsightsTransportreplaces Winstondataevent listenerlevel: 'info'trackException, without →trackTracewith Error severityProblem
Logger forwarding verbose/debug events to Application Insights even when configured as
info:infoWhy
Winston
logger.on('data')fired for ALL logs regardless of configured level. Debug/verbose leaked to Application Insights even when logger set to info/warn.Related
Similar fix for crawler:
Test coverage