diff --git a/src/agent/appServicesLoader.ts b/src/agent/appServicesLoader.ts index 10d4cad7..56193e49 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/src/types.ts b/src/types.ts index 68be3fbe..5587689d 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 afc0e858..1a8d1ce3 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, @@ -98,4 +99,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 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"); + 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"); + }); });