Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions .github/workflows/node.js-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ jobs:
- name: Install dependencies
run: |
npm i
if (!(Test-Path -Path node_modules/diagnostic-channel-publishers)) {
npm i diagnostic-channel-publishers --no-save
}
- run: npm run build --if-present
- run: npm run lint
- name: Run tests with mocks
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

#### Other Changes

- Replaced the `diagnostic-channel`/`diagnostic-channel-publishers` console log collection with the `@opentelemetry/instrumentation-console` package.

### 3.15.1 (2026-06-24)

#### Other Changes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ separately from clients created with `new appInsights.TelemetryClient()`.
| enableInternalDebugLogging | Enables debug and warning logging for AppInsights itself. If true, enables debug logging |
| enableInternalWarningLogging | Enables debug and warning logging for AppInsights itself. If true, enables warning logging |
| enableSendLiveMetrics | Enables communication with Application Insights Live Metrics. If true, enables communication with the live metrics service |
| noDiagnosticChannel | In order to track context across asynchronous calls, some changes are required in third party libraries such as mongodb and redis. By default ApplicationInsights will use diagnostic-channel-publishers to monkey-patch some of these libraries. This property is to disable the feature. Note that by setting this flag, events may no longer be correctly associated with the right operation. |
| noPatchModules | Disable individual monkey-patches. Set `noPatchModules` to a comma separated list of packages to disable. e.g. `"noPatchModules": "console,redis"` to avoid patching the console and redis packages. The following modules are available: `azuresdk, bunyan, console, mongodb, mongodb-core, mysql, redis, winston, pg`, and `pg-pool`. Visit the [diagnostic-channel-publishers' README](https://github.com/microsoft/node-diagnostic-channel/blob/master/src/diagnostic-channel-publishers/README.md) for information about exactly which versions of these packages are patched. |
| noDiagnosticChannel | **Deprecated.** Context propagation and library instrumentation are handled by OpenTelemetry instrumentations, not `diagnostic-channel`. Setting this to true still disables every instrumentation except HTTP, but configure `instrumentationOptions` on the Azure Monitor OpenTelemetry distro instead. Note that by setting this flag, events may no longer be correctly associated with the right operation. |
| noPatchModules | **Deprecated.** Use `instrumentationOptions` on the Azure Monitor OpenTelemetry distro to disable individual instrumentations. Set `noPatchModules` to a comma separated list of packages to disable. e.g. `"noPatchModules": "console,redis"` to avoid instrumenting the console and redis packages. The following modules are available: `azuresdk, bunyan, console, mongodb, mongodb-core, mysql, redis, winston, pg`, and `pg-pool`. |
| aadTokenCredential| Azure Credential instance to be used to authenticate the App. [AAD Identity Credential Classes](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#credential-classes)
| enableWebInstrumentation | Sets the state of automatic web Instrumentation (Optional, disabled by default). If true, web instrumentation will be enabled on valid node server http response with the connection string used for SDK initialization
| webInstrumentationConnectionString | Sets connection string used for web Instrumentation (Optional, Default undefined)|
Expand Down Expand Up @@ -239,7 +239,7 @@ The following modules are available: `azuresdk`, `bunyan`, `console`, `mongodb`,
Automatic instrumentation for several Azure SDKs is also enabled.
[Javascript Azure SDKs](https://azure.github.io/azure-sdk/releases/latest/index.html#javascript)

The `bunyan`, `winston`, and `console` patches will generate Application Insights Trace events based on whether `setAutoCollectConsole` is enabled.
The `bunyan`, `winston`, and `console` instrumentations will generate Application Insights Trace events based on whether `setAutoCollectConsole` is enabled.
The rest will generate Application Insights Dependency events based on whether `setAutoCollectDependencies` is enabled. Make sure that `applicationinsights` is imported **before** any 3rd-party packages for them to be instrumented successfully.

### Live Metrics
Expand Down
2,317 changes: 423 additions & 1,894 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@azure/core-auth": "^1.9.0",
"@azure/functions": "^4.11.2",
"@azure/identity": "^4.13.1",
"@azure/monitor-opentelemetry": "^1.18.1",
"@azure/monitor-opentelemetry": "^1.19.0",
"@azure/monitor-opentelemetry-exporter": ">=1.0.0-beta.41 <1.0.0-c || ^1.0.0",
"@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7",
"@opentelemetry/api": "^1.9.1",
Expand All @@ -83,9 +83,7 @@
"@opentelemetry/sdk-metrics": "^2.9.0",
"@opentelemetry/sdk-trace-base": "^2.9.0",
"@opentelemetry/sdk-trace-node": "^2.9.0",
"@opentelemetry/semantic-conventions": "^1.43.0",
"diagnostic-channel": "1.1.1",
"diagnostic-channel-publishers": "1.0.8"
"@opentelemetry/semantic-conventions": "^1.43.0"
},
"overrides": {
"mocha": {
Expand Down
26 changes: 0 additions & 26 deletions src/logs/autoCollectLogs.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/logs/diagnostic-channel/console.sub.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/logs/diagnostic-channel/initialization.ts

This file was deleted.

16 changes: 10 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
import { shutdownAzureMonitor as distroShutdownAzureMonitor, useAzureMonitor as distroUseAzureMonitor } from "@azure/monitor-opentelemetry";
import { ProxyTracerProvider, diag, metrics, trace } from "@opentelemetry/api";
import { logs } from "@opentelemetry/api-logs";
import { InstrumentationConfig } from "@opentelemetry/instrumentation";
import { MeterProvider } from "@opentelemetry/sdk-metrics";
import { BatchLogRecordProcessor, LoggerProvider } from "@opentelemetry/sdk-logs";
import { BasicTracerProvider, BatchSpanProcessor, SpanProcessor } from "@opentelemetry/sdk-trace-node";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { AutoCollectLogs } from "./logs/autoCollectLogs";
import { AutoCollectExceptions } from "./logs/exceptions";
import { AzureMonitorOpenTelemetryOptions } from "./types";
import { ApplicationInsightsConfig } from "./shared/configuration/config";
import { LogApi } from "./shim/logsApi";
import { StatsbeatFeature } from "./shim/types";
import { StatsbeatFeaturesManager } from "./shared/util/statsbeatFeaturesManager";

let autoCollectLogs: AutoCollectLogs;
let exceptions: AutoCollectExceptions;

/**
Expand Down Expand Up @@ -55,25 +54,30 @@ export function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions) {
options.logRecordProcessors.push(otlpLogProcessor);
}

const consoleOptions = internalConfig.instrumentationOptions.console;
options.instrumentationOptions = {
...options.instrumentationOptions,
console: {
enabled: consoleOptions?.enabled,
logSeverity: consoleOptions?.logSendingLevel,
} as InstrumentationConfig,
};

// Clean up previous instances to prevent listener accumulation on repeated calls
autoCollectLogs?.shutdown();
exceptions?.shutdown();

distroUseAzureMonitor(options);
const logApi = new LogApi(logs.getLogger("ApplicationInsightsLogger"));
autoCollectLogs = new AutoCollectLogs();
if (internalConfig.enableAutoCollectExceptions) {
exceptions = new AutoCollectExceptions(logApi);
}
autoCollectLogs.enable(internalConfig.instrumentationOptions);
}

/**
* Shutdown Azure Monitor
*/
export async function shutdownAzureMonitor() {
await distroShutdownAzureMonitor();
autoCollectLogs.shutdown();
exceptions?.shutdown();
}

Expand Down
4 changes: 2 additions & 2 deletions src/shared/configuration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class ApplicationInsightsConfig {
this.resource = Object.assign(this.resource, options.resource);
this.samplingRatio = options.samplingRatio !== undefined ? options.samplingRatio : this.samplingRatio;

// Set console logging level from env var
if (process.env[loggingLevel]) {
// Set console logging level from env var, unless it was set explicitly in code
if (process.env[loggingLevel] && this.instrumentationOptions.console?.logSendingLevel === undefined) {
this.instrumentationOptions = {
...this.instrumentationOptions,
console: {
Expand Down
2 changes: 2 additions & 0 deletions src/shim/shim-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class Config implements IConfig {
public webInstrumentationConfig: IWebInstrumentationConfig[];
public webInstrumentationSrc: string;
public webInstrumentationConnectionString?: string;
/** @deprecated Use `instrumentationOptions` on the Azure Monitor OpenTelemetry distro instead. */
public noPatchModules: string;
/** @deprecated Use `instrumentationOptions` on the Azure Monitor OpenTelemetry distro instead. */
public noDiagnosticChannel: boolean;

// Expose Distro config for further customization, other conflicting configs will take precedence over this.
Expand Down
8 changes: 5 additions & 3 deletions src/shim/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,18 @@ export interface IEnvironmentConfig {
/**
* In order to track context across asynchronous calls,
* some changes are required in third party libraries such as mongodb and redis.
* By default ApplicationInsights will use diagnostic-channel-publishers to monkey-patch some of these libraries.
* By default ApplicationInsights will use the appropriate OpenTelemetry instrumentation for each library.
* This property is to disable the feature.
* Note that by setting this flag, events may no longer be correctly associated with the right operation.
* @deprecated Use `instrumentationOptions` on the Azure Monitor OpenTelemetry distro instead.
*/
noDiagnosticChannel: boolean;
/**
* Disable individual monkey-patches.
* Disable individual instrumentations.
* Set `noPatchModules` to a comma separated list of packages to disable.
* e.g. `"noPatchModules": "console,redis"` to avoid patching the console and redis packages.
* e.g. `"noPatchModules": "console,redis"` to avoid instrumenting the console and redis packages.
* The following modules are available: `azuresdk, bunyan, console, mongodb, mongodb-core, mysql, redis, winston, pg`, and `pg-pool`.
* @deprecated Use `instrumentationOptions` on the Azure Monitor OpenTelemetry distro instead.
*/
noPatchModules: string;
/**
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface AzureMonitorOpenTelemetryOptions extends DistroOptions {
enableAutoCollectPerformance?: boolean;
enableAutoCollectDependencies?: boolean;
enableAutoCollectRequests?: boolean;
/** OpenTelemetry Instrumentations options included as part of Azure Monitor */
instrumentationOptions?: InstrumentationOptions;
}

export interface InstrumentationOptions extends DistroInstrumentationOptions {
Expand Down
2 changes: 1 addition & 1 deletion test/functionalTests/runner/taskExpectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
"MessageData",
(telemetry) => {
return telemetry.data.baseData.message === "Test console.error" &&
telemetry.data.baseData.severityLevel === "Warning";
telemetry.data.baseData.severityLevel === "Error";
Comment thread
JacksonWeber marked this conversation as resolved.
}
),
"ConsoleWarn": outputContract(
Expand Down
2 changes: 1 addition & 1 deletion test/functionalTests/runner/testSequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{"path": "/mongo", "steps": ["MongoInsert", "MongoInsertMany", "MongoUpdateOne", "MongoCreateIndex", "MongoFind"]},
{"path": "/mySql", "steps": ["MySQLQuery", "Timeout"]},
{"path": "/redis", "steps": ["RedisGet", "RedisSet", "RedisHset", "RedisHkeys", "RedisHincrby"]},
{"path": "/diagChannelConsole", "steps": ["ConsoleLog", "ConsoleWarn", "ConsoleError", "ConsoleInfo"]}
{"path": "/console", "steps": ["ConsoleLog", "ConsoleWarn", "ConsoleError", "ConsoleInfo"]}
]
16 changes: 12 additions & 4 deletions test/unitTests/agent/aksLoader.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import { logs } from "@opentelemetry/api-logs";
import { AKSLoader } from "../../../src/agent/aksLoader";
import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter";
import { dispose as disposeConsole } from "../../../src/logs/diagnostic-channel/console.sub";
import { shutdownAzureMonitor } from "../../../src";

describe("agent/AKSLoader", () => {
let originalEnv: NodeJS.ProcessEnv;
let sandbox: sinon.SinonSandbox;
let originalConsoleLog: typeof console.log;

before(() => {
sandbox = sinon.createSandbox();
});

beforeEach(() => {
originalEnv = process.env;
originalConsoleLog = console.log;
});

afterEach(() => {
disposeConsole();
afterEach(async () => {
// initialize() installs global providers and patches console; both leak into later suites without a shutdown.
if (console.log !== originalConsoleLog) {
Comment thread
JacksonWeber marked this conversation as resolved.
await shutdownAzureMonitor();
}
process.env = originalEnv;
sandbox.restore();
});
Expand Down Expand Up @@ -57,7 +62,10 @@ describe("agent/AKSLoader", () => {
assert.ok(exporterName.startsWith("AzureMonitorMetricExporter"), `Expected exporter name to start with 'AzureMonitorMetricExporter', but got '${exporterName}'`);

let tracerProvider = ((trace.getTracerProvider() as ProxyTracerProvider).getDelegate()) as any;
assert.equal(tracerProvider.constructor.name, "NodeTracerProvider");
assert.ok(
/^(Node)?TracerProvider$/.test(tracerProvider.constructor.name),
`Expected a tracer provider, but got '${tracerProvider.constructor.name}'`
);
let loggerProvider = logs.getLoggerProvider() as any;
assert.equal(loggerProvider.constructor.name, "LoggerProvider");
});
Expand Down
Loading
Loading