From 9a9be0c18e610709c8d4cbb0ebed177947527aa6 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 12 Nov 2025 14:49:05 -0800 Subject: [PATCH 1/2] Auto-enable console in app service auto-instrumentation. --- src/agent/appServicesLoader.ts | 8 ++++++++ .../agent/appServicesLoader.tests.ts | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/agent/appServicesLoader.ts b/src/agent/appServicesLoader.ts index 10d4cad70..56193e49d 100644 --- a/src/agent/appServicesLoader.ts +++ b/src/agent/appServicesLoader.ts @@ -14,12 +14,20 @@ import { EtwDiagnosticLogger } from './diagnostics/etwDiagnosticLogger'; import { FileWriter } from "./diagnostics/writers/fileWriter"; import { StatusLogger } from "./diagnostics/statusLogger"; import { AgentLoader } from "./agentLoader"; +import { InstrumentationOptions } from '../types'; export class AppServicesLoader extends AgentLoader { constructor() { super(); if (this._canLoad) { + (this._options.instrumentationOptions as InstrumentationOptions) = { + ...this._options.instrumentationOptions, + console: { enabled: true }, + bunyan: { enabled: true }, + winston: { enabled: true }, + } + // Azure App Services specific configuration const resourceAttributes: Attributes = {}; if (process.env.WEBSITE_SITE_NAME) { diff --git a/test/unitTests/agent/appServicesLoader.tests.ts b/test/unitTests/agent/appServicesLoader.tests.ts index afc0e8582..c46060a91 100644 --- a/test/unitTests/agent/appServicesLoader.tests.ts +++ b/test/unitTests/agent/appServicesLoader.tests.ts @@ -98,4 +98,23 @@ describe("agent/AppServicesLoader", () => { "testRole" ); }); + + it("should enable console, bunyan, and winston logging instrumentations", () => { + const env = { + ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", + ["HOME"]: "c:", + }; + process.env = env; + const agent = new AppServicesLoader(); + + // Verify that logging instrumentations are enabled + const instrumentationOptions = agent["_options"].instrumentationOptions; + assert.ok(instrumentationOptions, "instrumentationOptions should be present"); + assert.ok(instrumentationOptions.console, "console instrumentation should be present"); + assert.equal(instrumentationOptions.console.enabled, true, "console instrumentation should be enabled"); + assert.ok(instrumentationOptions.bunyan, "bunyan instrumentation should be present"); + assert.equal(instrumentationOptions.bunyan.enabled, true, "bunyan instrumentation should be enabled"); + assert.ok(instrumentationOptions.winston, "winston instrumentation should be present"); + assert.equal(instrumentationOptions.winston.enabled, true, "winston instrumentation should be enabled"); + }); }); From a217326a4622b78bbdf3fdee410b3a2dcf6fbedf Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 12 Nov 2025 17:05:50 -0800 Subject: [PATCH 2/2] Fix tests. --- src/types.ts | 4 ++++ test/unitTests/agent/appServicesLoader.tests.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 68be3fbe4..5587689d4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -38,6 +38,10 @@ export interface AzureMonitorOpenTelemetryOptions extends DistroOptions { export interface InstrumentationOptions extends DistroInstrumentationOptions { /** Console Instrumentation Config */ console?: InstrumentationConfig & { logSendingLevel?: SeverityNumber }; + /** Bunyan Instrumentation Config */ + bunyan?: InstrumentationConfig; + /** Winston Instrumentation Config */ + winston?: InstrumentationConfig; } /** diff --git a/test/unitTests/agent/appServicesLoader.tests.ts b/test/unitTests/agent/appServicesLoader.tests.ts index c46060a91..1a8d1ce36 100644 --- a/test/unitTests/agent/appServicesLoader.tests.ts +++ b/test/unitTests/agent/appServicesLoader.tests.ts @@ -4,6 +4,7 @@ import sinon from "sinon"; import { AppServicesLoader } from "../../../src/agent/appServicesLoader"; import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger"; import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter"; +import { InstrumentationOptions } from "../../../src/types"; import { SEMRESATTRS_SERVICE_INSTANCE_ID, SEMRESATTRS_SERVICE_NAME, @@ -108,7 +109,7 @@ describe("agent/AppServicesLoader", () => { const agent = new AppServicesLoader(); // Verify that logging instrumentations are enabled - const instrumentationOptions = agent["_options"].instrumentationOptions; + const instrumentationOptions = agent["_options"].instrumentationOptions as InstrumentationOptions; assert.ok(instrumentationOptions, "instrumentationOptions should be present"); assert.ok(instrumentationOptions.console, "console instrumentation should be present"); assert.equal(instrumentationOptions.console.enabled, true, "console instrumentation should be enabled");