Replace diagnostic-channel console collection with @opentelemetry/instrumentation-console - #1511
Merged
Conversation
…trumentation-console - Replace the diagnostic-channel/diagnostic-channel-publishers based console log collection with @opentelemetry/instrumentation-console (ConsoleInstrumentation). - Construct the instrumentation disabled then enable() explicitly, so its saved console originals are retained and shutdown() can restore console. - Add an npm override forcing a single @opentelemetry/api-logs instance so the global logs API singleton is shared with instrumentation-console. - Remove the diagnostic-channel-publishers CI install step; update tests and CHANGELOG. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, re-enable guard - Update functional test ConsoleError severity expectation to Error (instrumentation-console maps console.error to SeverityNumber.ERROR; the old diagnostic-channel publisher mapped stderr writes to WARN) - Rename the /diagChannelConsole functional test route to /console - Drop stale diagnostic-channel-publishers references from README and shim types docs - Unpatch console before re-patching in AutoCollectLogs.enable() so repeated enable() calls cannot leak a patched console Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve package.json/package-lock.json conflicts with microsoft#1510's OpenTelemetry upgrade: keep upstream's newer dependency ranges (api 1.9.1, api-logs 0.220.0, core/sdk 2.9.0, semantic-conventions 1.43.0) while retaining this branch's @opentelemetry/instrumentation-console dependency, the removal of diagnostic-channel/diagnostic-channel-publishers, and the api-logs override that keeps a single shared logs API instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes console log auto-collection by replacing the legacy diagnostic-channel/diagnostic-channel-publishers approach with OpenTelemetry’s @opentelemetry/instrumentation-console, and updates tests/docs/CI accordingly.
Changes:
- Switched console log capture to
ConsoleInstrumentationand removed the diagnostic-channel console subscriber/initializer. - Updated unit + functional tests to drive real
console.*calls, validate severity behavior, and add a regression test for restoringconsoleafter shutdown. - Updated dependencies (including an
@opentelemetry/api-logsoverride) and removed a Windows CI workaround tied to the old publishers package.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/logs/autoCollectLogs.ts |
Replaces diagnostic-channel subscription with ConsoleInstrumentation, adds disable-on-shutdown behavior. |
src/logs/diagnostic-channel/console.sub.ts |
Removed legacy diagnostic-channel console subscriber implementation. |
src/logs/diagnostic-channel/initialization.ts |
Removed legacy diagnostic-channel publisher initialization. |
test/unitTests/logs/console.tests.ts |
Updates unit tests to invoke real console.* and verifies console restoration after shutdown. |
test/unitTests/agent/aksLoader.tests.ts |
Removes legacy diagnostic-channel console cleanup from tests. |
test/functionalTests/runner/testSequence.json |
Renames the functional test route from /diagChannelConsole to /console. |
test/functionalTests/runner/taskExpectations.js |
Updates expected severity for console.error to Error. |
src/shim/types.ts |
Updates config documentation wording from “monkey-patches” to OpenTelemetry “instrumentations”. |
README.md |
Updates documentation to reflect OpenTelemetry instrumentation-based behavior and removes diagnostic-channel-publishers references. |
package.json |
Adds @opentelemetry/instrumentation-console, removes diagnostic-channel deps, adds @opentelemetry/api-logs override. |
package-lock.json |
Lockfile updates reflecting dependency removal/addition and override behavior. |
CHANGELOG.md |
Notes the console collection replacement in Unreleased. |
.github/workflows/node.js-windows.yml |
Removes Windows workflow step that installed diagnostic-channel-publishers ad-hoc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The removed disposeConsole() left initialize() tests leaking patched console methods and global providers into later suites. Shut down Azure Monitor in afterEach when console was patched, which covers both initialize() call sites and any added later. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hectorhdzg
reviewed
Jul 29, 2026
hectorhdzg
reviewed
Jul 29, 2026
hectorhdzg
reviewed
Jul 29, 2026
hectorhdzg
reviewed
Jul 29, 2026
hectorhdzg
reviewed
Jul 29, 2026
rads-1996
reviewed
Jul 29, 2026
Console collection now comes from @azure/monitor-opentelemetry via instrumentationOptions.console instead of a direct @opentelemetry/instrumentation-console dependency, which also removes the @opentelemetry/api-logs override. Deprecates noDiagnosticChannel and noPatchModules, and updates tests for the OpenTelemetry 2.x provider internals. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL previously overwrote a logSendingLevel set in code, so the programmatic option had no effect. It now applies only when the option was not set explicitly, matching the distro's precedence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/main.ts:64
- The console instrumentation options passed by callers (and merged into
internalConfig.instrumentationOptions.console) are being reduced to only{ enabled, logSeverity }when forwarded to the distro. This can silently drop any additional console-instrumentation configuration fields. Consider forwarding all console options and only renaminglogSendingLevel->logSeverity(and omittinglogSendingLevelfrom the forwarded object).
console: {
enabled: consoleOptions?.enabled,
logSeverity: consoleOptions?.logSendingLevel,
} as InstrumentationConfig,
src/main.ts:7
InstrumentationConfigis only used as a compile-time type here; importing it as a value can create an accidental runtime dependency depending on TS emit settings. Use a type-only import to make the intent explicit and avoid emitting a runtime import.
import { InstrumentationConfig } from "@opentelemetry/instrumentation";
hectorhdzg
approved these changes
Jul 31, 2026
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
Replaces the legacy
diagnostic-channel/diagnostic-channel-publishersbased console log collection with the OpenTelemetry@opentelemetry/instrumentation-consolepackage, which is now shipped and configured by the@azure/monitor-opentelemetrydistro.Changes
src/logs/autoCollectLogs.ts,src/logs/diagnostic-channel/console.sub.ts, andsrc/logs/diagnostic-channel/initialization.ts. Console collection is no longer implemented in this repo.package.json: bumped@azure/monitor-opentelemetryto^1.19.0(which pulls in@opentelemetry/instrumentation-console) and dropped thediagnostic-channel/diagnostic-channel-publishersdependencies.src/main.ts: instead of instantiatingAutoCollectLogs,useAzureMonitornow forwards the resolved console options to the distro viainstrumentationOptions.console, mapping the publicconsole.logSendingLeveloption to the package'slogSeverity. TheautoCollectLogs.shutdown()calls were removed — the distro'sshutdownAzureMonitor()disables the instrumentation and restoresconsole.src/types.ts:AzureMonitorOpenTelemetryOptionsnow explicitly declaresinstrumentationOptions.src/shared/configuration/config.ts:APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVELno longer overwrites alogSendingLevelthat was set explicitly in code; the env var is only applied when the code value isundefined.noDiagnosticChannelandnoPatchModulesare marked@deprecatedinsrc/shim/shim-config.tsandsrc/shim/types.ts, and the README wording for those options (plus the "patches" → "instrumentations" language) was updated accordingly.diagnostic-channel-publishersinstall step from the Windows workflow.test/unitTests/logs/console.tests.tswas rewritten to assert on the config forwarded to the distro and to drive realconsole.errorcalls, plus a regression test thatconsoleis restored after shutdown.aksLoader.tests.tsnow shuts down Azure Monitor between tests so the patchedconsoleand global providers don't leak into later suites.main.tests.tsgained agetSpanProcessorshelper for the OpenTelemetry 2.x SDK property move. Functional test expectations were updated (ConsoleErrornow expectsError, and the/diagChannelConsolesequence entry was renamed to/console).Behavioral note
Severity is now derived from the console method (
console.error→ ERROR,console.warn→ WARN,console.log/info→ INFO, etc.) instead of the old message-content /stderrheuristics. Notably,console.errornow producesErrorseverity where it previously producedWarning.Validation
npm run buildandnpm run lintpass with 0 errors.