Skip to content

fix(logging): prevent verbose/debug logs from leaking to Application Insights#1582

Open
yashkohli88 wants to merge 4 commits into
clearlydefined:masterfrom
yashkohli88:fix/logger-transport-level-filtering
Open

fix(logging): prevent verbose/debug logs from leaking to Application Insights#1582
yashkohli88 wants to merge 4 commits into
clearlydefined:masterfrom
yashkohli88:fix/logger-transport-level-filtering

Conversation

@yashkohli88

@yashkohli88 yashkohli88 commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Custom ApplicationInsightsTransport replaces Winston data event listener
  • Transport respects logger level config — verbose/debug blocked when level: 'info'
  • Errors with stack → trackException, without → trackTrace with Error severity
  • Console format includes timestamp, AI transport doesn't duplicate it

Problem

Logger forwarding verbose/debug events to Application Insights even when configured as info:

  • Configured level: info
  • Unexpected behavior: verbose/debug entries still appear in telemetry
  • Result: telemetry volume increases, signal-to-noise degrades

Why

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

  • Verifies debug/verbose blocked at info level
  • Confirms error routing (stack → exception, plain → trace)
  • Validates severity mapping (warn → Warning)

…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
@qtomlinson qtomlinson requested a review from JamieMagee May 13, 2026 14:19
Comment thread providers/logging/winstonConfig.ts Outdated
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()

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.

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?

yashkohli88 and others added 2 commits May 19, 2026 17:42
Wrap AI tracking calls in try/finally so callback() always executes.
Prevents Winston from hanging on exceptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants