Repository: microsoft/ApplicationInsights-node.js
Pull request #1088 (2023-02-27 19:05:41)

[Beta] Agent updates
Add Azure Functions writer
Added default configuration for all environments
Added node.js runtime check to validate if SDK can be initialized



Patch:
diff --git a/src/agent/agentLoader.ts b/src/agent/agentLoader.ts
index 8b5bd0f..100b70f 100644
--- a/src/agent/agentLoader.ts
+++ b/src/agent/agentLoader.ts
@@ -1,8 +1,9 @@
 import { ManagedIdentityCredential } from "@azure/identity";
-
 import { ApplicationInsightsClient } from "../applicationInsightsClient";
 import { ApplicationInsightsConfig } from "../shared";
 import { Util } from "../shared/util";
+import { ConsoleWriter } from "./diagnostics/writers/consoleWriter";
+import { DiagnosticLogger } from "./diagnostics/diagnosticLogger";
 import { StatusLogger } from "./diagnostics/statusLogger";
 import { DiagnosticMessageId, IDiagnosticLog, IDiagnosticLogger, NODE_JS_RUNTIME_MAJOR_VERSION } from "./types";
 
@@ -10,22 +11,58 @@ import { DiagnosticMessageId, IDiagnosticLog, IDiagnosticLogger, NODE_JS_RUNTIME
 const forceStart = process.env.APPLICATIONINSIGHTS_FORCE_START === "true";
 
 export class AgentLoader {
-    private _config: ApplicationInsightsConfig;
-    private _diagnosticLogger: IDiagnosticLogger;
-    private _statusLogger: StatusLogger;
+    private _canLoad: boolean;
+    protected _config: ApplicationInsightsConfig;
+    protected _instrumentationKey: string;
+    protected _diagnosticLogger: IDiagnosticLogger;
+    protected _statusLogger: StatusLogger;
     private _aadCredential: any; // Types not available as library should not be loaded in older versions of Node.js runtime
 
-    constructor(statusLogger: StatusLogger, diagnosticLogger: IDiagnosticLogger, config: ApplicationInsightsConfig) {
-        this._statusLogger = statusLogger;
-        this._diagnosticLogger = diagnosticLogger;
-        this._config = config;
-        // AAD Identity package no supported in older version of Node.js runtime
-        if (NODE_JS_RUNTIME_MAJOR_VERSION > 8) {
+    constructor() {
+        // Open Telemetry and AAD packages unsusable in older versions of Node.js runtime
+        if (NODE_JS_RUNTIME_MAJOR_VERSION <= 8) {
+            this._canLoad = false;
+        }
+        else {
+            this._canLoad = true;
             this._aadCredential = this._getAuthenticationCredential();
+            // Default config
+            this._config = new ApplicationInsightsConfig();
+            this._instrumentationKey = this._config.getInstrumentationKey();
+            this._config.disableOfflineStorage = false;
+            this._config.enableAutoCollectExceptions = true;
+            this._config.enableAutoCollectHeartbeat = true;
+            this._config.enableAutoCollectPerformance = true;
+            this._config.enableAutoCollectStandardMetrics = true;
+            this._config.samplingRate = 100;
+            this._config.instrumentations.azureSdk.enabled = true;
+            this._config.instrumentations.http.enabled = true;
+            this._config.instrumentations.mongoDb.enabled = true;
+            this._config.instrumentations.mySql.enabled = true;
+            this._config.instrumentations.postgreSql.enabled = true;
+            this._config.instrumentations.redis4.enabled = true;
+            this._config.instrumentations.redis.enabled = true;
+            this._config.logInstrumentations.bunyan.enabled = true;
+            this._config.logInstrumentations.console.enabled = true;
+            this._config.logInstrumentations.winston.enabled = true;
+
+            //Default diagnostic using console
+            this._diagnosticLogger = new DiagnosticLogger(this._instrumentationKey, new ConsoleWriter());
+            this._statusLogger = new StatusLogger(this._instrumentationKey, new ConsoleWriter());
         }
     }
 
+    // Exposed so ETW logger could be provider in IPA code
+    public setLogger(logger: IDiagnosticLogger) {
+        this._diagnosticLogger = logger;
+    }
+
     public initialize(): void {
+        if (!this._canLoad) {
+            const msg = `Cannot load Azure Monitor Application Insights Distro because of unsupported Node.js runtime, currently running in version ${NODE_JS_RUNTIME_MAJOR_VERSION}`;
+            console.log(msg);
+            return;
+        }
         if (this._validate()) {
             try {
                 // TODO: Set Prefix 
diff --git a/src/agent/aksLoader.ts b/src/agent/aksLoader.ts
index 36a1709..f3b401f 100644
--- a/src/agent/aksLoader.ts
+++ b/src/agent/aksLoader.ts
@@ -1,29 +1,44 @@
-import { ApplicationInsightsConfig } from "../shared";
-import { ConsoleWriter } from "./diagnostics/consoleWriter";
+import * as os from 'os';
+import * as path from 'path';
 import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
+import { FileWriter } from "./diagnostics/writers/fileWriter";
 import { StatusLogger } from "./diagnostics/statusLogger";
 import { AgentLoader } from "./agentLoader";
-import { IDiagnosticLogger } from "./types";
 
 
-export class AKSLoader {
-    private _config: ApplicationInsightsConfig;
-    private _diagnosticLogger: IDiagnosticLogger;
-    private _statusLogger: StatusLogger;
-    private _loader: AgentLoader;
+export class AKSLoader extends AgentLoader {
 
     constructor() {
-        this._config = new ApplicationInsightsConfig();
-        const instrumentationKey = this._config.getInstrumentationKey();
-        this._statusLogger = new StatusLogger(instrumentationKey, new ConsoleWriter());
+        super();
+        const isWindows = process.platform === 'win32';
+        let statusLogDir = '/var/log/applicationinsights/';
+        if (isWindows) {
+            if (process.env.HOME) {
+                statusLogDir = path.join(process.env.HOME, "LogFiles", "ApplicationInsights", "status");
+            }
+            else {
+                statusLogDir = path.join(os.tmpdir(), "Microsoft", "ApplicationInsights", "StatusMonitor", "LogFiles", "ApplicationInsights", "status");
+            }
+        }
+        this._statusLogger = new StatusLogger(this._instrumentationKey, new FileWriter(statusLogDir, 'status_nodejs.json', {
+            append: false,
+            deleteOnExit: false,
+            renamePolicy: 'overwrite',
+            sizeLimit: 1024 * 1024,
+        }));
+
         this._diagnosticLogger = new DiagnosticLogger(
-            instrumentationKey,
-            new ConsoleWriter(),
+            this._instrumentationKey,
+            new FileWriter(
+                statusLogDir,
+                'applicationinsights-extension.log',
+                {
+                    append: true,
+                    deleteOnExit: false,
+                    renamePolicy: 'overwrite',
+                    sizeLimit: 1024 * 1024, // 1 MB
+                }
+            )
         );
-        this._loader= new AgentLoader(this._statusLogger, this._diagnosticLogger, this._config);
-    }
-
-    public initialize(): void {
-        this._loader.initialize();
     }
 }
diff --git a/src/agent/appServicesLoader.ts b/src/agent/appServicesLoader.ts
index 9f7cd75..0b2830c 100644
--- a/src/agent/appServicesLoader.ts
+++ b/src/agent/appServicesLoader.ts
@@ -1,23 +1,15 @@
 import * as os from 'os';
 import * as path from 'path';
-import { ApplicationInsightsConfig } from "../shared";
 import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
-import { EtwDiagnosticLogger } from "./diagnostics/etwDiagnosticLogger";
-import { FileWriter } from "./diagnostics/fileWriter";
+import { FileWriter } from "./diagnostics/writers/fileWriter";
 import { StatusLogger } from "./diagnostics/statusLogger";
 import { AgentLoader } from "./agentLoader";
-import { IDiagnosticLogger } from "./types";
 
 
-export class AppServicesLoader {
-    private _config: ApplicationInsightsConfig;
-    private _diagnosticLogger: IDiagnosticLogger;
-    private _statusLogger: StatusLogger;
-    private _loader: AgentLoader;
+export class AppServicesLoader extends AgentLoader {
 
     constructor() {
-        this._config = new ApplicationInsightsConfig();
-        const instrumentationKey = this._config.getInstrumentationKey();
+        super();
         const isWindows = process.platform === 'win32';
         let statusLogDir = '/var/log/applicationinsights/';
         if (isWindows) {
@@ -28,39 +20,25 @@ export class AppServicesLoader {
                 statusLogDir = path.join(os.tmpdir(), "Microsoft", "ApplicationInsights", "StatusMonitor", "LogFiles", "ApplicationInsights", "status");
             }
         }
-        this._statusLogger = new StatusLogger(instrumentationKey, new FileWriter(statusLogDir, 'status_nodejs.json', {
+        this._statusLogger = new StatusLogger(this._instrumentationKey, new FileWriter(statusLogDir, 'status_nodejs.json', {
             append: false,
             deleteOnExit: false,
             renamePolicy: 'overwrite',
             sizeLimit: 1024 * 1024,
         }));
 
-        if (isWindows) {
-            const etwLogger = new EtwDiagnosticLogger(instrumentationKey);
-            if (etwLogger.isLoaded()) {
-                this._diagnosticLogger = etwLogger;
-            }
-        }
-
-        if (!this._diagnosticLogger) {
-            this._diagnosticLogger = new DiagnosticLogger(
-                instrumentationKey,
-                new FileWriter(
-                    statusLogDir,
-                    'applicationinsights-extension.log',
-                    {
-                        append: true,
-                        deleteOnExit: false,
-                        renamePolicy: 'overwrite',
-                        sizeLimit: 1024 * 1024, // 1 MB
-                    }
-                )
-            );
-        }
-        this._loader = new AgentLoader(this._statusLogger, this._diagnosticLogger, this._config);
-    }
-
-    public initialize(): void {
-        this._loader.initialize();
+        this._diagnosticLogger = new DiagnosticLogger(
+            this._instrumentationKey,
+            new FileWriter(
+                statusLogDir,
+                'applicationinsights-extension.log',
+                {
+                    append: true,
+                    deleteOnExit: false,
+                    renamePolicy: 'overwrite',
+                    sizeLimit: 1024 * 1024, // 1 MB
+                }
+            )
+        );
     }
 }
diff --git a/src/agent/azureFunctionsLoader.ts b/src/agent/azureFunctionsLoader.ts
index c82ba61..1f570bf 100644
--- a/src/agent/azureFunctionsLoader.ts
+++ b/src/agent/azureFunctionsLoader.ts
@@ -1,32 +1,19 @@
-import { ApplicationInsightsConfig } from "../shared";
-import { ConsoleWriter } from "./diagnostics/consoleWriter";
-import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
-import { StatusLogger } from "./diagnostics/statusLogger";
 import { AgentLoader } from "./agentLoader";
-import { IDiagnosticLogger } from "./types";
+import { DiagnosticLogger } from "./diagnostics/diagnosticLogger";
+import { StatusLogger } from "./diagnostics/statusLogger";
+import { AzureFunctionsWriter } from "./diagnostics/writers/azureFunctionsWriter";
 
 
-export class AzureFunctionsLoader {
-    private _config: ApplicationInsightsConfig;
-    private _diagnosticLogger: IDiagnosticLogger;
-    private _statusLogger: StatusLogger;
-    private _loader: AgentLoader;
+export class AzureFunctionsLoader extends AgentLoader {
 
     constructor() {
-        this._config = new ApplicationInsightsConfig();
-        const instrumentationKey = this._config.getInstrumentationKey();
-        this._statusLogger = new StatusLogger(instrumentationKey, new ConsoleWriter());
-        this._diagnosticLogger = new DiagnosticLogger(
-            instrumentationKey,
-            new ConsoleWriter(),
-        );
+        super();
         // Azure Fn specific configuration
         this._config.enableAutoCollectPerformance = false;
         this._config.enableAutoCollectStandardMetrics = false;
-        this._loader= new AgentLoader(this._statusLogger, this._diagnosticLogger, this._config);
-    }
-
-    public initialize(): void {
-        this._loader.initialize();
+        
+        const writer = new AzureFunctionsWriter(this._instrumentationKey);
+        this._diagnosticLogger = new DiagnosticLogger(this._instrumentationKey, writer);
+        this._statusLogger = new StatusLogger(this._instrumentationKey, writer)
     }
 }
diff --git a/src/agent/diagnostics/etwDiagnosticLogger.ts b/src/agent/diagnostics/etwDiagnosticLogger.ts
deleted file mode 100644
index b724483..0000000
--- a/src/agent/diagnostics/etwDiagnosticLogger.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import * as fs from 'fs';
-import * as path from 'path';
-import type * as etwTypes from '@microsoft/typescript-etw';
-import { BaseDiagnosticLogger } from './baseDiagnosticLogger';
-import { IDiagnosticLog, NODE_JS_RUNTIME_MAJOR_VERSION } from '../types';
-import { EtwWriter } from './etwWriter';
-
-
-export class EtwDiagnosticLogger extends BaseDiagnosticLogger {
-
-    private _isLoaded: boolean;
-
-    constructor(instrumentationKey: string) {
-        super(instrumentationKey);
-        this._isLoaded = false;
-        let etwModule: typeof etwTypes | undefined;
-        try {
-            etwModule = this._loadEtwModule(NODE_JS_RUNTIME_MAJOR_VERSION);
-            if (etwModule) {
-                this._agentLogger = new EtwWriter();
-                this._isLoaded = true
-                console.log('AppInsightsAgent: Successfully loaded ETW');
-            } else {
-                console.log('AppInsightsAgent: ETW could not be loaded');
-            }
-        } catch (e) {
-            console.log('AppInsightsAgent: ETW could not be loaded');
-        }
-    }
-
-    public isLoaded(): boolean {
-        return this._isLoaded;
-    }
-
-    public logMessage(diagnosticLog: IDiagnosticLog): void {
-        try {
-            console.log('AppInsightsAgent ETWLogger', diagnosticLog.message);
-            const metaData = this._getMetadata();
-            metaData.push(diagnosticLog.messageId || "");
-            const message: string = diagnosticLog.message;
-            this._agentLogger.log(message, metaData);
-        }
-        catch (ex) {
-            console.error("Failed to log Message in ETW", ex);
-        }
-    }
-
-    private _loadEtwModule(nodeMajVer: number): typeof etwTypes | undefined {
-        // Try to load precompiled ETW module if it exists and is "importable"
-        const dirname = path.join(__dirname, '../etw', `etw_${nodeMajVer}`);
-        try {
-            // throws an error if directory is not readable / does not exist
-            fs.accessSync(dirname, fs.constants.R_OK);
-            // eslint-disable-next-line @typescript-eslint/no-var-requires
-            return require(dirname) as typeof etwTypes;
-        } catch (e) {
-            // Could not load ETW, return nothing
-            return undefined;
-        }
-    }
-
-    private _getMetadata(): [string, string, string, string, string] {
-        // Must return strings in this exact order!
-        return [this._extensionVersion, this._subscriptionId, this._siteName, this._sdkVersion, this._instrumentationKey];
-    }
-}
\ No newline at end of file
diff --git a/src/agent/diagnostics/etwWriter.ts b/src/agent/diagnostics/etwWriter.ts
deleted file mode 100644
index 8787ee0..0000000
--- a/src/agent/diagnostics/etwWriter.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import type * as etwTypes from '@microsoft/typescript-etw';
-import { IAgentLogger } from "../types";
-
-
-export class EtwWriter implements IAgentLogger {
-    log(message: any, params: any[]) {
-        let etwModule: typeof etwTypes | undefined;
-        (etwModule.logInfoEvent as (msg: any, ...params: any[]) => void)(message, ...params);
-    }
-}
diff --git a/src/agent/diagnostics/statusLogger.ts b/src/agent/diagnostics/statusLogger.ts
index 91afda7..5834f39 100644
--- a/src/agent/diagnostics/statusLogger.ts
+++ b/src/agent/diagnostics/statusLogger.ts
@@ -1,5 +1,5 @@
 import * as os from "os";
-import { FileWriter } from "./fileWriter";
+import { FileWriter } from "./writers/fileWriter";
 import { IAgentLogger, IStatusContract, LOGGER_LANGUAGE } from "../types";
 import { APPLICATION_INSIGHTS_SDK_VERSION } from "../../declarations/constants";
 
diff --git a/src/agent/diagnostics/writers/azureFunctionsWriter.ts b/src/agent/diagnostics/writers/azureFunctionsWriter.ts
new file mode 100644
index 0000000..47aa78f
--- /dev/null
+++ b/src/agent/diagnostics/writers/azureFunctionsWriter.ts
@@ -0,0 +1,29 @@
+import { APPLICATION_INSIGHTS_SDK_VERSION } from "../../../declarations/constants";
+import { AZURE_APP_NAME, IAgentLogger } from "../../types";
+
+const AZURE_FUNCTIONS_DIAGNOSTIC_PREFIX = "LanguageWorkerConsoleLogMS_APPLICATION_INSIGHTS_LOGS";
+
+export class AzureFunctionsWriter implements IAgentLogger {
+    private _appName: string;
+    private _instrumentationKey: string;
+    private _agentVersion: string;
+
+    constructor(instrumentationKey: string) {
+        this._instrumentationKey = instrumentationKey;
+        this._appName = AZURE_APP_NAME;
+        this._agentVersion = APPLICATION_INSIGHTS_SDK_VERSION;
+    }
+
+    public log(log: any) {
+        console.info(this._getAzureFnLog(log));
+    }
+
+    public error(log: any) {
+        console.error(this._getAzureFnLog(log));
+    }
+
+    private _getAzureFnLog(log: any): string {
+        let output = `${AZURE_FUNCTIONS_DIAGNOSTIC_PREFIX} ${log.time},${log.level},${log.logger},\"${log.message}\",${this._appName},${this._instrumentationKey},${this._agentVersion},node.js`;
+        return output;
+    }
+}
diff --git a/src/agent/diagnostics/consoleWriter.ts b/src/agent/diagnostics/writers/consoleWriter.ts
similarity index 85%
rename from src/agent/diagnostics/consoleWriter.ts
rename to src/agent/diagnostics/writers/consoleWriter.ts
index ba4b564..f4b1d46 100644
--- a/src/agent/diagnostics/consoleWriter.ts
+++ b/src/agent/diagnostics/writers/consoleWriter.ts
@@ -1,4 +1,4 @@
-import { IAgentLogger } from "../types";
+import { IAgentLogger } from "../../types";
 
 
 export class ConsoleWriter implements IAgentLogger {
diff --git a/src/agent/diagnostics/fileHelpers.ts b/src/agent/diagnostics/writers/fileHelpers.ts
similarity index 100%
rename from src/agent/diagnostics/fileHelpers.ts
rename to src/agent/diagnostics/writers/fileHelpers.ts
diff --git a/src/agent/diagnostics/fileWriter.ts b/src/agent/diagnostics/writers/fileWriter.ts
similarity index 99%
rename from src/agent/diagnostics/fileWriter.ts
rename to src/agent/diagnostics/writers/fileWriter.ts
index 6c590b0..9631765 100644
--- a/src/agent/diagnostics/fileWriter.ts
+++ b/src/agent/diagnostics/writers/fileWriter.ts
@@ -3,7 +3,7 @@
 import * as path from "path";
 import * as fs from "fs";
 import { makeStatusDirs, renameCurrentFile } from "./fileHelpers";
-import { IAgentLogger } from "../types";
+import { IAgentLogger } from "../../types";
 
 export interface FileWriterOptions {
     append: boolean; // Overwrite or append on file write (false)
diff --git a/src/agent/scripts/aks.ts b/src/agent/scripts/aks.ts
deleted file mode 100644
index 6b274b9..0000000
--- a/src/agent/scripts/aks.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { AKSLoader } from "../aksLoader";
-
-const loader = new AKSLoader();
-loader.initialize();
-export = loader;
diff --git a/src/agent/scripts/appServices.ts b/src/agent/scripts/appServices.ts
deleted file mode 100644
index 87f7fd2..0000000
--- a/src/agent/scripts/appServices.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { AppServicesLoader } from "../appServicesLoader";
-
-const loader = new AppServicesLoader();
-loader.initialize();
-export = loader;
diff --git a/src/agent/scripts/azureFunctions.ts b/src/agent/scripts/azureFunctions.ts
deleted file mode 100644
index 7a7e48f..0000000
--- a/src/agent/scripts/azureFunctions.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { AzureFunctionsLoader } from "../azureFunctionsLoader";
-
-const loader = new AzureFunctionsLoader();
-loader.initialize();
-export = loader;
diff --git a/src/agent/types.ts b/src/agent/types.ts
index 36f3117..eb8ac83 100644
--- a/src/agent/types.ts
+++ b/src/agent/types.ts
@@ -1,6 +1,7 @@
 export const LOGGER_NAME = "applicationinsights.extension.diagnostics";
 export const LOGGER_LANGUAGE = "nodejs";
 export const NODE_JS_RUNTIME_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
+export const AZURE_APP_NAME = process.env.WEBSITE_SITE_NAME || 'unknown';
 
 export interface IAgentLogger {
     log(message: any, ...optional: any[]): void;


Test patch:
diff --git a/test/unitTests/agent/aksLoader.tests.ts b/test/unitTests/agent/aksLoader.tests.ts
index 51a46c0..b672f9b 100644
--- a/test/unitTests/agent/aksLoader.tests.ts
+++ b/test/unitTests/agent/aksLoader.tests.ts
@@ -2,8 +2,8 @@ import * as assert from "assert";
 import * as sinon from "sinon";
 
 import { AKSLoader } from "../../../src/agent/aksLoader";
-import { ConsoleWriter } from "../../../src/agent/diagnostics/consoleWriter";
 import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
+import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter";
 
 describe("agent/AKSLoader", () => {
     let originalEnv: NodeJS.ProcessEnv;
@@ -31,18 +31,18 @@ describe("agent/AKSLoader", () => {
         let diagnosticLogger: any = agent["_diagnosticLogger"];
         assert.equal(diagnosticLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
         assert.ok(diagnosticLogger instanceof DiagnosticLogger);
-        assert.ok(diagnosticLogger["_agentLogger"] instanceof ConsoleWriter);
+        assert.ok(diagnosticLogger["_agentLogger"] instanceof FileWriter);
         let statusLogger: any = agent["_statusLogger"];
         assert.equal(statusLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
-        assert.ok(statusLogger["_agentLogger"] instanceof ConsoleWriter);
+        assert.ok(statusLogger["_agentLogger"] instanceof FileWriter);
         // Loader is using correct diagnostics
-        assert.equal(agent["_loader"]["_diagnosticLogger"], diagnosticLogger, "Wrong diagnosticLogger");
-        assert.equal(agent["_loader"]["_statusLogger"], statusLogger, "Wrong statusLogger");
+        assert.equal(agent["_diagnosticLogger"], diagnosticLogger, "Wrong diagnosticLogger");
+        assert.equal(agent["_statusLogger"], statusLogger, "Wrong statusLogger");
     });
 
     it("initialize", () => {
         const agent = new AKSLoader();
-        let stub = sandbox.stub(agent["_loader"], "initialize");
+        let stub = sandbox.stub(agent, "initialize");
         agent.initialize();
         // Agent Loader called
         assert.ok(stub.calledOnce);
diff --git a/test/unitTests/agent/appServicesLoader.ts b/test/unitTests/agent/appServicesLoader.ts
index 7788d09..f7ebedf 100644
--- a/test/unitTests/agent/appServicesLoader.ts
+++ b/test/unitTests/agent/appServicesLoader.ts
@@ -2,10 +2,8 @@ import * as assert from "assert";
 import * as sinon from "sinon";
 
 import { AppServicesLoader } from "../../../src/agent/appServicesLoader";
-import { ConsoleWriter } from "../../../src/agent/diagnostics/consoleWriter";
 import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
-import { EtwDiagnosticLogger } from "../../../src/agent/diagnostics/etwDiagnosticLogger";
-import { FileWriter } from "../../../src/agent/diagnostics/fileWriter";
+import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter";
 
 describe("agent/AppServicesLoader", () => {
     let originalEnv: NodeJS.ProcessEnv;
@@ -53,13 +51,13 @@ describe("agent/AppServicesLoader", () => {
             assert.equal(statusLogger["_agentLogger"]["_filepath"], "/var/log/applicationinsights/");
         }
         // Loader is using correct diagnostics
-        assert.equal(agent["_loader"]["_diagnosticLogger"], diagnosticLogger, "Wrong diagnosticLogger");
-        assert.equal(agent["_loader"]["_statusLogger"], statusLogger, "Wrong statusLogger");
+        assert.equal(agent["_diagnosticLogger"], diagnosticLogger, "Wrong diagnosticLogger");
+        assert.equal(agent["_statusLogger"], statusLogger, "Wrong statusLogger");
     });
 
     it("initialize", () => {
         const agent = new AppServicesLoader();
-        let stub = sandbox.stub(agent["_loader"], "initialize");
+        let stub = sandbox.stub(agent, "initialize");
         agent.initialize();
         // Agent Loader called
         assert.ok(stub.calledOnce);
diff --git a/test/unitTests/agent/azureFunctionsLoader.ts b/test/unitTests/agent/azureFunctionsLoader.ts
index b4d239d..0cb3af3 100644
--- a/test/unitTests/agent/azureFunctionsLoader.ts
+++ b/test/unitTests/agent/azureFunctionsLoader.ts
@@ -2,8 +2,8 @@ import * as assert from "assert";
 import * as sinon from "sinon";
 
 import { AzureFunctionsLoader } from "../../../src/agent/azureFunctionsLoader";
-import { ConsoleWriter } from "../../../src/agent/diagnostics/consoleWriter";
 import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
+import { AzureFunctionsWriter } from "../../../src/agent/diagnostics/writers/azureFunctionsWriter";
 
 describe("agent/AzureFunctionsLoader", () => {
     let originalEnv: NodeJS.ProcessEnv;
@@ -31,18 +31,18 @@ describe("agent/AzureFunctionsLoader", () => {
         let diagnosticLogger: any = agent["_diagnosticLogger"];
         assert.equal(diagnosticLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
         assert.ok(diagnosticLogger instanceof DiagnosticLogger);
-        assert.ok(diagnosticLogger["_agentLogger"] instanceof ConsoleWriter);
+        assert.ok(diagnosticLogger["_agentLogger"] instanceof AzureFunctionsWriter);
         let statusLogger: any = agent["_statusLogger"];
         assert.equal(statusLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
-        assert.ok(statusLogger["_agentLogger"] instanceof ConsoleWriter);
+        assert.ok(statusLogger["_agentLogger"] instanceof AzureFunctionsWriter);
         // Loader is using correct diagnostics
-        assert.equal(agent["_loader"]["_diagnosticLogger"], diagnosticLogger);
-        assert.equal(agent["_loader"]["_statusLogger"], statusLogger);
+        assert.equal(agent["_diagnosticLogger"], diagnosticLogger);
+        assert.equal(agent["_statusLogger"], statusLogger);
     });
 
     it("initialize", () => {
         const agent = new AzureFunctionsLoader();
-        let stub = sandbox.stub(agent["_loader"], "initialize");
+        let stub = sandbox.stub(agent, "initialize");
         agent.initialize();
         // Agent Loader called
         assert.ok(stub.calledOnce);