Repository: microsoft/ApplicationInsights-node.js
Pull request #1159 (2023-06-09 18:08:11)

[Beta] Update default cloud role name and instance ID
Use Azure env variables only in Agent code, use OpenTelemetry defaults


Patch:
diff --git a/src/agent/agentLoader.ts b/src/agent/agentLoader.ts
index 5a48f31..8ec8648 100644
--- a/src/agent/agentLoader.ts
+++ b/src/agent/agentLoader.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import { ManagedIdentityCredential } from "@azure/identity";
 import { ApplicationInsightsClient } from "../applicationInsightsClient";
 import { ApplicationInsightsConfig } from "../shared";
diff --git a/src/agent/aksLoader.ts b/src/agent/aksLoader.ts
index 7bcdca5..17f3ac4 100644
--- a/src/agent/aksLoader.ts
+++ b/src/agent/aksLoader.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import * as os from 'os';
 import * as path from 'path';
 import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
diff --git a/src/agent/appServicesLoader.ts b/src/agent/appServicesLoader.ts
index 33880cc..94584f6 100644
--- a/src/agent/appServicesLoader.ts
+++ b/src/agent/appServicesLoader.ts
@@ -1,5 +1,11 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import * as os from 'os';
 import * as path from 'path';
+import { Attributes } from '@opentelemetry/api';
+import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
+import { Resource } from '@opentelemetry/resources';
 import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
 import { FileWriter } from "./diagnostics/writers/fileWriter";
 import { StatusLogger } from "./diagnostics/statusLogger";
@@ -12,6 +18,19 @@ export class AppServicesLoader extends AgentLoader {
     constructor() {
         super();
         if (this._canLoad) {
+            // Azure App Services specific configuration
+            const resourceAttributes: Attributes = {};
+            if (process.env.WEBSITE_SITE_NAME) {
+                resourceAttributes[SemanticResourceAttributes.SERVICE_NAME] =
+                    process.env.WEBSITE_SITE_NAME;
+            }
+            if (process.env.WEBSITE_INSTANCE_ID) {
+                resourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
+                    process.env.WEBSITE_INSTANCE_ID;
+            }
+            const resource = new Resource(resourceAttributes);
+            this._config.resource = resource;
+
             let statusLogDir = '/var/log/applicationinsights/';
             if (this._isWindows) {
                 if (process.env.HOME) {
diff --git a/src/agent/azureFunctionsLoader.ts b/src/agent/azureFunctionsLoader.ts
index a2b6df5..b809e3e 100644
--- a/src/agent/azureFunctionsLoader.ts
+++ b/src/agent/azureFunctionsLoader.ts
@@ -1,23 +1,40 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
+import { Resource } from "@opentelemetry/resources";
 import { AgentLoader } from "./agentLoader";
 import { DiagnosticLogger } from "./diagnostics/diagnosticLogger";
 import { StatusLogger } from "./diagnostics/statusLogger";
 import { AzureFunctionsWriter } from "./diagnostics/writers/azureFunctionsWriter";
 import { AgentResourceProviderType, AZURE_MONITOR_AGENT_PREFIX } from "./types";
-
+import { Attributes } from "@opentelemetry/api";
+import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
 
 export class AzureFunctionsLoader extends AgentLoader {
-
     constructor() {
         super();
         if (this._canLoad) {
             // Azure Fn specific configuration
             this._config.enableAutoCollectPerformance = false;
             this._config.enableAutoCollectStandardMetrics = false;
+            const resourceAttributes: Attributes = {};
+            if (process.env.WEBSITE_SITE_NAME) {
+                resourceAttributes[SemanticResourceAttributes.SERVICE_NAME] =
+                    process.env.WEBSITE_SITE_NAME;
+            }
+            if (process.env.WEBSITE_INSTANCE_ID) {
+                resourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
+                    process.env.WEBSITE_INSTANCE_ID;
+            }
+            const resource = new Resource(resourceAttributes);
+            this._config.resource = resource;
 
             const writer = new AzureFunctionsWriter(this._instrumentationKey);
             this._diagnosticLogger = new DiagnosticLogger(this._instrumentationKey, writer);
             this._statusLogger = new StatusLogger(this._instrumentationKey, writer);
-            process.env[AZURE_MONITOR_AGENT_PREFIX] = this._getVersionPrefix(AgentResourceProviderType.azureFunctions);
+            process.env[AZURE_MONITOR_AGENT_PREFIX] = this._getVersionPrefix(
+                AgentResourceProviderType.azureFunctions
+            );
         }
     }
 }
diff --git a/src/agent/diagnostics/baseDiagnosticLogger.ts b/src/agent/diagnostics/baseDiagnosticLogger.ts
index 09d038b..370a119 100644
--- a/src/agent/diagnostics/baseDiagnosticLogger.ts
+++ b/src/agent/diagnostics/baseDiagnosticLogger.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import { IAgentLogger, IDiagnosticLog, IDiagnosticLogger, LOGGER_LANGUAGE, LOGGER_NAME } from "../types";
 import { AZURE_MONITOR_DISTRO_VERSION } from "../../declarations/constants";
 
diff --git a/src/agent/diagnostics/diagnosticLogger.ts b/src/agent/diagnostics/diagnosticLogger.ts
index bb99824..4516e2e 100644
--- a/src/agent/diagnostics/diagnosticLogger.ts
+++ b/src/agent/diagnostics/diagnosticLogger.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import { IAgentLogger, IDiagnosticLog } from "../types";
 import { BaseDiagnosticLogger } from "./baseDiagnosticLogger";
 
diff --git a/src/agent/diagnostics/statusLogger.ts b/src/agent/diagnostics/statusLogger.ts
index 847c469..ec84784 100644
--- a/src/agent/diagnostics/statusLogger.ts
+++ b/src/agent/diagnostics/statusLogger.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import * as os from "os";
 import { FileWriter } from "./writers/fileWriter";
 import { IAgentLogger, IStatusContract, LOGGER_LANGUAGE } from "../types";
diff --git a/src/agent/diagnostics/writers/azureFunctionsWriter.ts b/src/agent/diagnostics/writers/azureFunctionsWriter.ts
index 9ba72ba..fb9a90f 100644
--- a/src/agent/diagnostics/writers/azureFunctionsWriter.ts
+++ b/src/agent/diagnostics/writers/azureFunctionsWriter.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import { AZURE_MONITOR_DISTRO_VERSION } from "../../../declarations/constants";
 import { AZURE_APP_NAME, IAgentLogger } from "../../types";
 
diff --git a/src/agent/diagnostics/writers/consoleWriter.ts b/src/agent/diagnostics/writers/consoleWriter.ts
index f4b1d46..f1d8f88 100644
--- a/src/agent/diagnostics/writers/consoleWriter.ts
+++ b/src/agent/diagnostics/writers/consoleWriter.ts
@@ -1,5 +1,7 @@
-import { IAgentLogger } from "../../types";
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
 
+import { IAgentLogger } from "../../types";
 
 export class ConsoleWriter implements IAgentLogger {
     log(message?: any, ...optional: any[]) {
diff --git a/src/agent/diagnostics/writers/fileHelpers.ts b/src/agent/diagnostics/writers/fileHelpers.ts
index 69d63c5..ded3f80 100644
--- a/src/agent/diagnostics/writers/fileHelpers.ts
+++ b/src/agent/diagnostics/writers/fileHelpers.ts
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+
 import * as path from "path";
 import * as fs from "fs";
 import * as os from "os";
diff --git a/src/agent/diagnostics/writers/fileWriter.ts b/src/agent/diagnostics/writers/fileWriter.ts
index 9631765..1b7fc18 100644
--- a/src/agent/diagnostics/writers/fileWriter.ts
+++ b/src/agent/diagnostics/writers/fileWriter.ts
@@ -1,4 +1,5 @@
-"use strict";
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
 
 import * as path from "path";
 import * as fs from "fs";
diff --git a/src/shared/configuration/applicationInsightsConfig.ts b/src/shared/configuration/applicationInsightsConfig.ts
index 48b2477..6ec3293 100644
--- a/src/shared/configuration/applicationInsightsConfig.ts
+++ b/src/shared/configuration/applicationInsightsConfig.ts
@@ -15,11 +15,10 @@ import {
 import { JsonConfig } from "./jsonConfig";
 import { Logger } from "../logging";
 import { Resource, ResourceDetectionConfig, detectResourcesSync, envDetectorSync } from "@opentelemetry/resources";
-import { SemanticResourceAttributes, TelemetrySdkLanguageValues } from "@opentelemetry/semantic-conventions";
+
 
 // Azure Connection String
 const ENV_connectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING";
-const DEFAULT_ROLE_NAME = "Web";
 
 
 export class ApplicationInsightsConfig implements IConfig {
@@ -162,31 +161,13 @@ export class ApplicationInsightsConfig implements IConfig {
     }
 
     private _getDefaultResource(): Resource {
-        let resource = Resource.EMPTY;
+        let resource = Resource.default();
         // Load resource attributes from env
         const detectResourceConfig: ResourceDetectionConfig = {
             detectors: [envDetectorSync]
         };
         const envResource = detectResourcesSync(detectResourceConfig);
         resource = resource.merge(envResource);
-
-        resource.attributes[SemanticResourceAttributes.SERVICE_NAME] = resource.attributes[SemanticResourceAttributes.SERVICE_NAME] || DEFAULT_ROLE_NAME;
-        if (process.env.WEBSITE_SITE_NAME) {
-            // Azure Web apps and Functions
-            resource.attributes[SemanticResourceAttributes.SERVICE_NAME] =
-                process.env.WEBSITE_SITE_NAME;
-        }
-        resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] || os && os.hostname();
-        if (process.env.WEBSITE_INSTANCE_ID) {
-            resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
-                process.env.WEBSITE_INSTANCE_ID;
-        }
-        const sdkVersion = Constants.AZURE_MONITOR_DISTRO_VERSION;
-        resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE] =
-            TelemetrySdkLanguageValues.NODEJS;
-        resource.attributes[
-            SemanticResourceAttributes.TELEMETRY_SDK_VERSION
-        ] = `node:${sdkVersion}`;
         return resource;
     }
 


Test patch:
diff --git a/test/unitTests/agent/appServicesLoader.ts b/test/unitTests/agent/appServicesLoader.ts
index 7625b15..3d21a85 100644
--- a/test/unitTests/agent/appServicesLoader.ts
+++ b/test/unitTests/agent/appServicesLoader.ts
@@ -4,6 +4,7 @@ import * as 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 { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
 
 describe("agent/AppServicesLoader", () => {
     let originalEnv: NodeJS.ProcessEnv;
@@ -68,4 +69,26 @@ describe("agent/AppServicesLoader", () => {
         // Agent Loader called
         assert.ok(stub.calledOnce);
     });
+
+    it("should correctly set Azure Resource Attributes", () => {
+        const env = <{ [id: string]: string }>{};
+        const originalEnv = process.env;
+        env.WEBSITE_SITE_NAME = "testRole";
+        env.WEBSITE_INSTANCE_ID = "testRoleInstanceId";
+        process.env = env;
+        const agent = new AppServicesLoader();
+        let stub = sandbox.stub(agent, "initialize");
+        agent.initialize();
+        process.env = originalEnv;
+        // Agent Loader called
+        assert.ok(stub.calledOnce);
+        assert.equal(
+            agent["_config"].resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
+            "testRoleInstanceId"
+        );
+        assert.equal(
+            agent["_config"].resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
+            "testRole"
+        );
+    });
 });
diff --git a/test/unitTests/agent/azureFunctionsLoader.ts b/test/unitTests/agent/azureFunctionsLoader.ts
index 71ff6cb..5298402 100644
--- a/test/unitTests/agent/azureFunctionsLoader.ts
+++ b/test/unitTests/agent/azureFunctionsLoader.ts
@@ -4,6 +4,7 @@ import * as sinon from "sinon";
 import { AzureFunctionsLoader } from "../../../src/agent/azureFunctionsLoader";
 import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
 import { AzureFunctionsWriter } from "../../../src/agent/diagnostics/writers/azureFunctionsWriter";
+import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
 
 describe("agent/AzureFunctionsLoader", () => {
     let originalEnv: NodeJS.ProcessEnv;
@@ -24,12 +25,16 @@ describe("agent/AzureFunctionsLoader", () => {
 
     it("constructor", () => {
         const env = {
-            ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333",
+            ["APPLICATIONINSIGHTS_CONNECTION_STRING"]:
+                "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333",
         };
         process.env = env;
         const agent = new AzureFunctionsLoader();
         let diagnosticLogger: any = agent["_diagnosticLogger"];
-        assert.equal(diagnosticLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
+        assert.equal(
+            diagnosticLogger["_instrumentationKey"],
+            "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333"
+        );
         assert.ok(diagnosticLogger instanceof DiagnosticLogger);
         assert.ok(diagnosticLogger["_agentLogger"] instanceof AzureFunctionsWriter);
         let statusLogger: any = agent["_statusLogger"];
@@ -53,4 +58,26 @@ describe("agent/AzureFunctionsLoader", () => {
         assert.equal(agent["_config"].enableAutoCollectStandardMetrics, false);
         assert.equal(agent["_config"].enableAutoCollectPerformance, false);
     });
+
+    it("should correctly set Azure Resource Attributes", () => {
+        const env = <{ [id: string]: string }>{};
+        const originalEnv = process.env;
+        env.WEBSITE_SITE_NAME = "testRole";
+        env.WEBSITE_INSTANCE_ID = "testRoleInstanceId";
+        process.env = env;
+        const agent = new AzureFunctionsLoader();
+        let stub = sandbox.stub(agent, "initialize");
+        agent.initialize();
+        process.env = originalEnv;
+        // Agent Loader called
+        assert.ok(stub.calledOnce);
+        assert.equal(
+            agent["_config"].resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
+            "testRoleInstanceId"
+        );
+        assert.equal(
+            agent["_config"].resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
+            "testRole"
+        );
+    });
 });
diff --git a/test/unitTests/shared/config.tests.ts b/test/unitTests/shared/config.tests.ts
index bfdd20e..541541c 100644
--- a/test/unitTests/shared/config.tests.ts
+++ b/test/unitTests/shared/config.tests.ts
@@ -40,7 +40,10 @@ describe("Library/Config", () => {
                 process.env = env;
                 const config = new ApplicationInsightsConfig();
                 config.azureMonitorExporterConfig.connectionString = "InstrumentationKey=cs.code";
-                assert.deepEqual(config.azureMonitorExporterConfig.connectionString, "InstrumentationKey=cs.code");
+                assert.deepEqual(
+                    config.azureMonitorExporterConfig.connectionString,
+                    "InstrumentationKey=cs.code"
+                );
             });
 
             it("connection string set via in configuration[Deprecated]", () => {
@@ -51,7 +54,10 @@ describe("Library/Config", () => {
                 process.env = env;
                 const config = new ApplicationInsightsConfig();
                 config.connectionString = "InstrumentationKey=cs.code";
-                assert.deepEqual(config.azureMonitorExporterConfig.connectionString, "InstrumentationKey=cs.code");
+                assert.deepEqual(
+                    config.azureMonitorExporterConfig.connectionString,
+                    "InstrumentationKey=cs.code"
+                );
             });
 
             it("connection string set via environment variable", () => {
@@ -61,14 +67,20 @@ describe("Library/Config", () => {
                 };
                 process.env = env;
                 const config = new ApplicationInsightsConfig();
-                assert.deepEqual(config.azureMonitorExporterConfig.connectionString, "InstrumentationKey=cs.env");
+                assert.deepEqual(
+                    config.azureMonitorExporterConfig.connectionString,
+                    "InstrumentationKey=cs.env"
+                );
             });
 
             it("instrumentation key set via environment variable", () => {
                 const env = { [ENV_IKEY]: "ikey.env" };
                 process.env = env;
                 const config = new ApplicationInsightsConfig();
-                assert.deepEqual(config.azureMonitorExporterConfig.connectionString, "InstrumentationKey=ikey.env;IngestionEndpoint=https://dc.services.visualstudio.com");
+                assert.deepEqual(
+                    config.azureMonitorExporterConfig.connectionString,
+                    "InstrumentationKey=ikey.env;IngestionEndpoint=https://dc.services.visualstudio.com"
+                );
             });
 
             it("merge JSON config", () => {
@@ -86,16 +98,47 @@ describe("Library/Config", () => {
                     "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
                 );
                 assert.equal(config.samplingRatio, 0.3, "Wrong samplingRatio");
-                assert.equal(config.azureMonitorExporterConfig.disableOfflineStorage, true, "Wrong disableOfflineStorage");
-                assert.equal(config.azureMonitorExporterConfig.storageDirectory, "testPath", "Wrong storageDirectory");
-                assert.equal(config.otlpTraceExporterConfig.enabled, true, "Wrong otlpTraceExporterConfig enabled");
-                assert.equal(config.otlpTraceExporterConfig.baseConfig.keepAlive, false, "Wrong otlpTraceExporterConfig keepAlive");
-                assert.equal(config.otlpTraceExporterConfig.baseConfig.url, "someurlfortraces", "Wrong otlpTraceExporterConfig url");
-
-                assert.equal(config.otlpMetricExporterConfig.enabled, true, "Wrong otlpMetricExporterConfig enabled");
-                assert.equal(config.otlpMetricExporterConfig.baseConfig.keepAlive, true, "Wrong otlpMetricExporterConfig keepAlive");
-                assert.equal(config.otlpMetricExporterConfig.baseConfig.url, "someurlformetrics", "Wrong otlpMetricExporterConfig url");
+                assert.equal(
+                    config.azureMonitorExporterConfig.disableOfflineStorage,
+                    true,
+                    "Wrong disableOfflineStorage"
+                );
+                assert.equal(
+                    config.azureMonitorExporterConfig.storageDirectory,
+                    "testPath",
+                    "Wrong storageDirectory"
+                );
+                assert.equal(
+                    config.otlpTraceExporterConfig.enabled,
+                    true,
+                    "Wrong otlpTraceExporterConfig enabled"
+                );
+                assert.equal(
+                    config.otlpTraceExporterConfig.baseConfig.keepAlive,
+                    false,
+                    "Wrong otlpTraceExporterConfig keepAlive"
+                );
+                assert.equal(
+                    config.otlpTraceExporterConfig.baseConfig.url,
+                    "someurlfortraces",
+                    "Wrong otlpTraceExporterConfig url"
+                );
 
+                assert.equal(
+                    config.otlpMetricExporterConfig.enabled,
+                    true,
+                    "Wrong otlpMetricExporterConfig enabled"
+                );
+                assert.equal(
+                    config.otlpMetricExporterConfig.baseConfig.keepAlive,
+                    true,
+                    "Wrong otlpMetricExporterConfig keepAlive"
+                );
+                assert.equal(
+                    config.otlpMetricExporterConfig.baseConfig.url,
+                    "someurlformetrics",
+                    "Wrong otlpMetricExporterConfig url"
+                );
 
                 assert.equal(
                     config.enableAutoCollectExceptions,
@@ -158,11 +201,31 @@ describe("Library/Config", () => {
                     undefined,
                     "Wrong disableOfflineStorage"
                 );
-                assert.equal(config.azureMonitorExporterConfig.storageDirectory, undefined, "Wrong storageDirectory");
-                assert.equal(config.otlpMetricExporterConfig.enabled, undefined, "Wrong otlpMetricExporterConfig.enabled");
-                assert.equal(config.otlpMetricExporterConfig.baseConfig, undefined, "Wrong otlpMetricExporterConfig.baseConfig");
-                assert.equal(config.otlpTraceExporterConfig.enabled, undefined, "Wrong otlpTraceExporterConfig.enabled");
-                assert.equal(config.otlpTraceExporterConfig.baseConfig, undefined, "Wrong otlpTraceExporterConfig.baseConfig");
+                assert.equal(
+                    config.azureMonitorExporterConfig.storageDirectory,
+                    undefined,
+                    "Wrong storageDirectory"
+                );
+                assert.equal(
+                    config.otlpMetricExporterConfig.enabled,
+                    undefined,
+                    "Wrong otlpMetricExporterConfig.enabled"
+                );
+                assert.equal(
+                    config.otlpMetricExporterConfig.baseConfig,
+                    undefined,
+                    "Wrong otlpMetricExporterConfig.baseConfig"
+                );
+                assert.equal(
+                    config.otlpTraceExporterConfig.enabled,
+                    undefined,
+                    "Wrong otlpTraceExporterConfig.enabled"
+                );
+                assert.equal(
+                    config.otlpTraceExporterConfig.baseConfig,
+                    undefined,
+                    "Wrong otlpTraceExporterConfig.baseConfig"
+                );
                 assert.equal(config.logInstrumentations.console.enabled, false, "Wrong console");
                 assert.equal(config.logInstrumentations.bunyan.enabled, false, "Wrong bunyan");
                 assert.equal(config.logInstrumentations.winston.enabled, false, "Wrong winston");
@@ -190,7 +253,8 @@ describe("Library/Config", () => {
                 const config = new ApplicationInsightsConfig();
                 assert.equal(
                     config.azureMonitorExporterConfig.connectionString,
-                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://dc.services.visualstudio.com");
+                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://dc.services.visualstudio.com"
+                );
             });
 
             it("should read iKey from azure environment", () => {
@@ -200,12 +264,14 @@ describe("Library/Config", () => {
                 const config = new ApplicationInsightsConfig();
                 assert.equal(
                     config.azureMonitorExporterConfig.connectionString,
-                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://dc.services.visualstudio.com");
+                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://dc.services.visualstudio.com"
+                );
             });
 
             it("should initialize valid values", () => {
                 const config = new ApplicationInsightsConfig();
-                config.azureMonitorExporterConfig.connectionString = "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
+                config.azureMonitorExporterConfig.connectionString =
+                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
                 assert(typeof config.azureMonitorExporterConfig.connectionString === "string");
                 assert(typeof config.samplingRatio === "number");
             });
@@ -213,14 +279,16 @@ describe("Library/Config", () => {
             it("instrumentation key validation-valid key passed", () => {
                 const warnStub = sandbox.stub(console, "warn");
                 const config = new ApplicationInsightsConfig();
-                config.azureMonitorExporterConfig.connectionString = "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
+                config.azureMonitorExporterConfig.connectionString =
+                    "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
                 assert.ok(warnStub.notCalled, "warning was not raised");
             });
 
             it("instrumentation key validation-invalid key passed", () => {
                 const warnStub = sandbox.stub(console, "warn");
                 const config = new ApplicationInsightsConfig();
-                config.azureMonitorExporterConfig.connectionString = "InstrumentationKey=1aa11111bbbb1ccc8dddeeeeffff3333";
+                config.azureMonitorExporterConfig.connectionString =
+                    "InstrumentationKey=1aa11111bbbb1ccc8dddeeeeffff3333";
                 assert.ok(warnStub.calledOn, "warning was raised");
             });
 
@@ -234,101 +302,79 @@ describe("Library/Config", () => {
     });
 
     describe("OpenTelemetry Resource", () => {
-
-        beforeEach(() => {
-            sandbox.stub(os, "hostname").callsFake(() => "host");
-        });
-
         it("should allow custom resource to be configured", () => {
             let customAttributes: any = {};
             customAttributes[SemanticResourceAttributes.SERVICE_NAME] = "testServiceName";
-            customAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = "testServiceInstanceId";
+            customAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
+                "testServiceInstanceId";
             customAttributes[SemanticResourceAttributes.CONTAINER_ID] = "testContainerId";
             let customResource = new Resource(customAttributes);
             const config = new ApplicationInsightsConfig();
             config.resource = customResource;
-            assert.strictEqual(config.resource.attributes[SemanticResourceAttributes.SERVICE_NAME], "testServiceName");
-            assert.strictEqual(config.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], "testServiceInstanceId");
-            assert.strictEqual(config.resource.attributes[SemanticResourceAttributes.CONTAINER_ID], "testContainerId");
+            assert.strictEqual(
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
+                "testServiceName"
+            );
+            assert.strictEqual(
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
+                "testServiceInstanceId"
+            );
+            assert.strictEqual(
+                config.resource.attributes[SemanticResourceAttributes.CONTAINER_ID],
+                "testContainerId"
+            );
         });
 
         it("Default values", () => {
-            const packageJsonPath = path.resolve(__dirname, "../../../../", "./package.json");
-            const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
             const config = new ApplicationInsightsConfig();
             assert.equal(
                 config.resource.attributes[
-                    SemanticResourceAttributes.TELEMETRY_SDK_VERSION
+                    SemanticResourceAttributes.TELEMETRY_SDK_NAME
                 ].toString(),
-                `node:${packageJson.version}`
+                "opentelemetry"
             );
-            assert.equal(
+            assert.ok(
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_NAME]
+                    .toString()
+                    .startsWith("unknown_service:"),
+                "Wrong SERVICE_NAME"
+            );
+            assert.ok(
                 config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_INSTANCE_ID
-                ],
-                "host"
+                    SemanticResourceAttributes.TELEMETRY_SDK_VERSION
+                ].toString().length > 0,
+                "Wrong TELEMETRY_SDK_VERSION"
             );
             assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_NAME
-                ],
-                "Web"
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
+                undefined
             );
         });
 
         it("OTEL_RESOURCE_ATTRIBUTES", () => {
             const env = <{ [id: string]: string }>{};
             const originalEnv = process.env;
-            env.OTEL_RESOURCE_ATTRIBUTES = "service.name=testServiceName,service.instance.id=testServiceInstance,k8s.cluster.name=testClusterName,k8s.node.name=testNodeName";
+            env.OTEL_RESOURCE_ATTRIBUTES =
+                "service.name=testServiceName,service.instance.id=testServiceInstance,k8s.cluster.name=testClusterName,k8s.node.name=testNodeName";
             process.env = env;
             const config = new ApplicationInsightsConfig();
             process.env = originalEnv;
             assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_NAME
-                ],
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
                 "testServiceName"
             );
             assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_INSTANCE_ID
-                ],
+                config.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
                 "testServiceInstance"
             );
             assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.K8S_CLUSTER_NAME
-                ],
+                config.resource.attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME],
                 "testClusterName"
             );
             assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.K8S_NODE_NAME
-                ],
+                config.resource.attributes[SemanticResourceAttributes.K8S_NODE_NAME],
                 "testNodeName"
             );
         });
-
-        it("should correctly set Azure attributes", () => {
-            const env = <{ [id: string]: string }>{};
-            const originalEnv = process.env;
-            env.WEBSITE_SITE_NAME = "testRole";
-            env.WEBSITE_INSTANCE_ID = "testRoleInstanceId";
-            process.env = env;
-            const config = new ApplicationInsightsConfig();
-            process.env = originalEnv;
-            assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_INSTANCE_ID
-                ],
-                "testRoleInstanceId"
-            );
-            assert.equal(
-                config.resource.attributes[
-                SemanticResourceAttributes.SERVICE_NAME
-                ],
-                "testRole"
-            );
-        });
     });
 });