Skip to content

Replace diagnostic-channel console collection with @opentelemetry/instrumentation-console - #1511

Merged
JacksonWeber merged 7 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/replace-diagnostic-channel-with-instrumentation-console
Jul 31, 2026
Merged

Replace diagnostic-channel console collection with @opentelemetry/instrumentation-console#1511
JacksonWeber merged 7 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/replace-diagnostic-channel-with-instrumentation-console

Conversation

@JacksonWeber

@JacksonWeber JacksonWeber commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the legacy diagnostic-channel / diagnostic-channel-publishers based console log collection with the OpenTelemetry @opentelemetry/instrumentation-console package, which is now shipped and configured by the @azure/monitor-opentelemetry distro.

Changes

  • Removed src/logs/autoCollectLogs.ts, src/logs/diagnostic-channel/console.sub.ts, and src/logs/diagnostic-channel/initialization.ts. Console collection is no longer implemented in this repo.
  • package.json: bumped @azure/monitor-opentelemetry to ^1.19.0 (which pulls in @opentelemetry/instrumentation-console) and dropped the diagnostic-channel / diagnostic-channel-publishers dependencies.
  • src/main.ts: instead of instantiating AutoCollectLogs, useAzureMonitor now forwards the resolved console options to the distro via instrumentationOptions.console, mapping the public console.logSendingLevel option to the package's logSeverity. The autoCollectLogs.shutdown() calls were removed — the distro's shutdownAzureMonitor() disables the instrumentation and restores console.
  • src/types.ts: AzureMonitorOpenTelemetryOptions now explicitly declares instrumentationOptions.
  • src/shared/configuration/config.ts: APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL no longer overwrites a logSendingLevel that was set explicitly in code; the env var is only applied when the code value is undefined.
  • Deprecations / docs: noDiagnosticChannel and noPatchModules are marked @deprecated in src/shim/shim-config.ts and src/shim/types.ts, and the README wording for those options (plus the "patches" → "instrumentations" language) was updated accordingly.
  • CI: removed the diagnostic-channel-publishers install step from the Windows workflow.
  • Tests: test/unitTests/logs/console.tests.ts was rewritten to assert on the config forwarded to the distro and to drive real console.error calls, plus a regression test that console is restored after shutdown. aksLoader.tests.ts now shuts down Azure Monitor between tests so the patched console and global providers don't leak into later suites. main.tests.ts gained a getSpanProcessors helper for the OpenTelemetry 2.x SDK property move. Functional test expectations were updated (ConsoleError now expects Error, and the /diagChannelConsole sequence entry was renamed to /console).
  • Added a CHANGELOG entry.

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 / stderr heuristics. Notably, console.error now produces Error severity where it previously produced Warning.

Validation

  • npm run build and npm run lint pass with 0 errors.
  • Full unit suite passes, including the new console forwarding + shutdown-restore coverage.
  • All CI checks (build on Node 20/22/24, Windows + Ubuntu, integration, perf-regression) are green.

…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>
@JacksonWeber JacksonWeber reopened this Jul 29, 2026
JacksonWeber and others added 2 commits July 29, 2026 13:26
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>

Copilot AI left a comment

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.

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 ConsoleInstrumentation and 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 restoring console after shutdown.
  • Updated dependencies (including an @opentelemetry/api-logs override) 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.

Comment thread test/unitTests/agent/aksLoader.tests.ts Outdated
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>
Comment thread package.json Outdated
Comment thread package.json
Comment thread package.json Outdated
Comment thread README.md Outdated
Comment thread test/unitTests/agent/aksLoader.tests.ts
Comment thread test/functionalTests/runner/taskExpectations.js
JacksonWeber and others added 2 commits July 30, 2026 14:19
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>

Copilot AI left a comment

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.

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 renaming logSendingLevel -> logSeverity (and omitting logSendingLevel from the forwarded object).
        console: {
            enabled: consoleOptions?.enabled,
            logSeverity: consoleOptions?.logSendingLevel,
        } as InstrumentationConfig,

src/main.ts:7

  • InstrumentationConfig is 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";

@JacksonWeber
JacksonWeber merged commit 1e6ed63 into microsoft:main Jul 31, 2026
13 checks passed
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.

4 participants