Repository: microsoft/ApplicationInsights-node.js (ts)

Issue:
[Beta] Cannot set Cloud Role Name and Instance values
## Description
Although I set cloud role name, instance id and namespace as described in the latest docs, I still see the default values (role='Web', instance=hostname) in the Application insights .

## Importance
1. We have been using this SDK for CLI tool which runs on local machines, we do not want to collect/report hostname for privacy reasons.
2. Default Role (Web) doesn't not reflect our tool's role. However, this is less important comparing to above item 
 
## Code
```js
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");

const config = new ApplicationInsightsConfig();
config.connectionString = '<MyConnectionString>';

const appInsights = new ApplicationInsightsClient(config);

const traceResource = appInsights.getTraceResource();
const metricResource = appInsights.getMetricResource();
const logResource = appInsights.getLogResource();

// ----------------------------------------
// Setting role name and role instance
// ----------------------------------------
traceResource.attributes[SemanticResourceAttributes.SERVICE_NAME] = "my-helloworld-service";
traceResource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE] = "my-namespace";
traceResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = "my-instance";

metricResource.attributes[SemanticResourceAttributes.SERVICE_NAME] = "my-helloworld-service";
metricResource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE] = "my-namespace";
metricResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = "my-instance";

logResource.attributes[SemanticResourceAttributes.SERVICE_NAME] = "my-helloworld-service";
logResource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE] = "my-namespace";
logResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = "my-instance";

appInsights.start();

const tracer = appInsights.getTraceHandler().getTracer();

const span = tracer.startSpan("my-span");
span.addEvent('my-event', { myEventAttribute: 'my-event-attribute-value' });
span.end();

appInsights.flush().finally(()=>{
    console.log("Done");
});
```

## Application Insights results:

Traces:
![image](https://user-images.githubusercontent.com/5796904/221669117-fa7ca9b7-b53b-4247-9cb1-9ec6e8e8ce79.png)

Dependencies:
![image](https://user-images.githubusercontent.com/5796904/221669312-3699ce66-9240-473c-8fb8-bf1f2a64bc51.png)

## Expected Results: 
- cloud_RoleName => my-helloworld-service
- cloud_RoleInstance => my-instance 



Pull request:
[Beta] Allow custom OTel Resource to be passed in configuration
Fixes #1089
Related to #1083 

Breaking change, Resource reference is not kept in OpenTelemetry side, a copy is created that is immutable, we should expose Resource as configuration option that can be set before the SDK is initialized,  allowing customer to cloud role name and instance properties and any other custom one. I will update documentation in release PR

Patch:
diff --git a/src/applicationInsightsClient.ts b/src/applicationInsightsClient.ts
index 27ca3d8..b8861ff 100644
--- a/src/applicationInsightsClient.ts
+++ b/src/applicationInsightsClient.ts
@@ -5,7 +5,7 @@ import { Logger } from "./shared/logging";
 import { LogHandler } from "./logs";
 import { MetricHandler } from "./metrics";
 import { TraceHandler } from "./traces";
-import { ResourceManager } from "./shared";
+
 
 export class ApplicationInsightsClient {
     private _config: ApplicationInsightsConfig;
@@ -62,18 +62,6 @@ export class ApplicationInsightsClient {
         return this._statsbeat;
     }
 
-    public getTraceResource(): Resource {
-        return ResourceManager.getInstance().getTraceResource();
-    }
-
-    public getMetricResource(): Resource {
-        return ResourceManager.getInstance().getMetricResource();
-    }
-
-    public getLogResource(): Resource {
-        return ResourceManager.getInstance().getLogResource();
-    }
-
     public getLogger(): Logger {
         return Logger.getInstance();
     }
diff --git a/src/logs/logHandler.ts b/src/logs/logHandler.ts
index ed239c8..c8ad3b5 100644
--- a/src/logs/logHandler.ts
+++ b/src/logs/logHandler.ts
@@ -11,7 +11,6 @@ import { AutoCollectConsole } from "./console";
 import { AutoCollectExceptions } from "./exceptions";
 import { ApplicationInsightsConfig } from "../shared/configuration";
 import { Util } from "../shared/util";
-import { ResourceManager } from "../shared/resourceManager";
 import { Statsbeat } from "../metrics/statsbeat";
 import { parseStack } from "./exporters/exceptionUtils";
 import {
@@ -324,7 +323,7 @@ export class LogHandler {
 
     private _getTags() {
         const tags = <{ [key: string]: string }>{};
-        const attributes = ResourceManager.getInstance().getLogResource().attributes;
+        const attributes = this._config.resource.attributes;
         const serviceName = attributes[SemanticResourceAttributes.SERVICE_NAME];
         const serviceNamespace = attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];
         if (serviceName) {
diff --git a/src/metrics/handlers/customMetricsHandler.ts b/src/metrics/handlers/customMetricsHandler.ts
index 9a437c2..939eedd 100644
--- a/src/metrics/handlers/customMetricsHandler.ts
+++ b/src/metrics/handlers/customMetricsHandler.ts
@@ -9,7 +9,7 @@ import {
     PeriodicExportingMetricReader,
     PeriodicExportingMetricReaderOptions,
 } from "@opentelemetry/sdk-metrics";
-import { ApplicationInsightsConfig, ResourceManager } from "../../shared";
+import { ApplicationInsightsConfig } from "../../shared";
 
 export class CustomMetricsHandler {
     private _config: ApplicationInsightsConfig;
@@ -22,7 +22,7 @@ export class CustomMetricsHandler {
     constructor(config: ApplicationInsightsConfig, options?: { collectionInterval: number }) {
         this._config = config;
         const meterProviderConfig: MeterProviderOptions = {
-            resource: ResourceManager.getInstance().getMetricResource(),
+            resource: this._config.resource,
         };
         this._meterProvider = new MeterProvider(meterProviderConfig);
         const exporterConfig: AzureMonitorExporterOptions = {
diff --git a/src/metrics/handlers/heartBeatHandler.ts b/src/metrics/handlers/heartBeatHandler.ts
index 77a306a..53a0fee 100644
--- a/src/metrics/handlers/heartBeatHandler.ts
+++ b/src/metrics/handlers/heartBeatHandler.ts
@@ -15,7 +15,7 @@ import {
     PeriodicExportingMetricReaderOptions,
 } from "@opentelemetry/sdk-metrics";
 import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
-import { ApplicationInsightsConfig, AzureVirtualMachine, ResourceManager } from "../../shared";
+import { ApplicationInsightsConfig, AzureVirtualMachine } from "../../shared";
 import { IVirtualMachineInfo } from "../../shared/azureVirtualMachine";
 import { Logger } from "../../shared/logging";
 
@@ -74,8 +74,8 @@ export class HeartBeatHandler {
         // TODO: Add sdk property for attach scenarios, confirm if this is only expected when attach happens, older code doing this was present in Default.ts
         const sdkVersion =
             String(
-                ResourceManager.getInstance().getTraceResource().attributes[
-                    SemanticResourceAttributes.TELEMETRY_SDK_VERSION
+                this._config.resource.attributes[
+                SemanticResourceAttributes.TELEMETRY_SDK_VERSION
                 ]
             ) || null;
         properties["sdk"] = sdkVersion;
diff --git a/src/metrics/handlers/performanceCounterMetricsHandler.ts b/src/metrics/handlers/performanceCounterMetricsHandler.ts
index cce5d1d..e93c75e 100644
--- a/src/metrics/handlers/performanceCounterMetricsHandler.ts
+++ b/src/metrics/handlers/performanceCounterMetricsHandler.ts
@@ -21,7 +21,7 @@ import {
 import { AzureHttpMetricsInstrumentation } from "../collection/azureHttpMetricsInstrumentation";
 import { ProcessMetrics } from "../collection/processMetrics";
 import { RequestMetrics } from "../collection/requestMetrics";
-import { ApplicationInsightsConfig, ResourceManager } from "../../shared";
+import { ApplicationInsightsConfig } from "../../shared";
 import { NativePerformanceMetrics } from "../collection/nativePerformanceMetrics";
 import { Util } from "../../shared/util";
 
@@ -40,7 +40,7 @@ export class PerformanceCounterMetricsHandler {
     constructor(config: ApplicationInsightsConfig, options?: { collectionInterval: number }) {
         this._config = config;
         const meterProviderConfig: MeterProviderOptions = {
-            resource: ResourceManager.getInstance().getMetricResource(),
+            resource: this._config.resource,
             views: this._getViews(),
         };
         this._meterProvider = new MeterProvider(meterProviderConfig);
diff --git a/src/metrics/handlers/standardMetricsHandler.ts b/src/metrics/handlers/standardMetricsHandler.ts
index 2df5a2b..f0cb26a 100644
--- a/src/metrics/handlers/standardMetricsHandler.ts
+++ b/src/metrics/handlers/standardMetricsHandler.ts
@@ -11,7 +11,7 @@ import {
     PeriodicExportingMetricReaderOptions,
     View,
 } from "@opentelemetry/sdk-metrics";
-import { ApplicationInsightsConfig, ResourceManager } from "../../shared";
+import { ApplicationInsightsConfig } from "../../shared";
 import { ExceptionMetrics } from "../collection/exceptionMetrics";
 import { TraceMetrics } from "../collection/traceMetrics";
 import { MetricName, StandardMetric } from "../types";
@@ -29,7 +29,7 @@ export class StandardMetricsHandler {
     constructor(config: ApplicationInsightsConfig, options?: { collectionInterval: number }) {
         this._config = config;
         const meterProviderConfig: MeterProviderOptions = {
-            resource: ResourceManager.getInstance().getMetricResource(),
+            resource: this._config.resource,
             views: this._getViews(),
         };
         this._meterProvider = new MeterProvider(meterProviderConfig);
diff --git a/src/shared/configuration/applicationInsightsConfig.ts b/src/shared/configuration/applicationInsightsConfig.ts
index 2921796..1313d9c 100644
--- a/src/shared/configuration/applicationInsightsConfig.ts
+++ b/src/shared/configuration/applicationInsightsConfig.ts
@@ -1,3 +1,4 @@
+import * as os from "os";
 import * as azureCore from "@azure/core-http";
 import { ConnectionStringParser } from "./connectionStringParser";
 import * as Constants from "../../declarations/constants";
@@ -13,10 +14,14 @@ import {
 import { ConnectionString } from "../../declarations/contracts";
 import { JsonConfig } from "./jsonConfig";
 import { Logger } from "../logging";
+import { Resource } from "@opentelemetry/resources";
+import { SemanticResourceAttributes, TelemetrySdkLanguageValues } from "@opentelemetry/semantic-conventions";
 
 // Azure Connection String
 const ENV_connectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING";
 const ENV_noStatsbeat = "APPLICATION_INSIGHTS_NO_STATSBEAT";
+const DEFAULT_ROLE_NAME = "Web";
+
 
 export class ApplicationInsightsConfig implements IConfig {
     public samplingRate: number;
@@ -35,6 +40,7 @@ export class ApplicationInsightsConfig implements IConfig {
     private _connectionStringParser: ConnectionStringParser;
     private _parsedConnectionString: ConnectionString;
     private _connectionString: string;
+    private _resource?: Resource;
 
     constructor() {
         this._connectionStringParser = new ConnectionStringParser();
@@ -63,6 +69,14 @@ export class ApplicationInsightsConfig implements IConfig {
         return this._connectionString;
     }
 
+    public set resource(resource: Resource) {
+        this._resource = this._resource.merge(resource);
+    }
+
+    public get resource(): Resource {
+        return this._resource;
+    }
+
     public getInstrumentationKey(): string {
         return this._parsedConnectionString?.instrumentationkey;
     }
@@ -109,6 +123,29 @@ export class ApplicationInsightsConfig implements IConfig {
         this.extendedMetrics[ExtendedMetricType.gc] = false;
         this.extendedMetrics[ExtendedMetricType.heap] = false;
         this.extendedMetrics[ExtendedMetricType.loop] = false;
+        this._resource = this._getDefaultResource();
+    }
+
+    private _getDefaultResource(): Resource {
+        let resource = Resource.EMPTY;
+        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] = os && os.hostname();
+        if (process.env.WEBSITE_INSTANCE_ID) {
+            resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
+                process.env.WEBSITE_INSTANCE_ID;
+        }
+        const sdkVersion = Constants.APPLICATION_INSIGHTS_SDK_VERSION;
+        resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE] =
+            TelemetrySdkLanguageValues.NODEJS;
+        resource.attributes[
+            SemanticResourceAttributes.TELEMETRY_SDK_VERSION
+        ] = `node:${sdkVersion}`;
+        return resource;
     }
 
     private _mergeConfig() {
diff --git a/src/shared/configuration/jsonConfig.ts b/src/shared/configuration/jsonConfig.ts
index 6c5ab7f..23367ea 100644
--- a/src/shared/configuration/jsonConfig.ts
+++ b/src/shared/configuration/jsonConfig.ts
@@ -1,11 +1,11 @@
 import * as fs from "fs";
 import * as path from "path";
 import { Logger } from "../logging";
-import { IConfig, InstrumentationsConfig, LogInstrumentationsConfig } from "./types";
+import { IBaseConfig, IConfig, InstrumentationsConfig, LogInstrumentationsConfig } from "./types";
 
 const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE";
 
-export class JsonConfig implements IConfig {
+export class JsonConfig implements IBaseConfig {
     private static _instance: JsonConfig;
 
     public connectionString: string;
diff --git a/src/shared/configuration/types.ts b/src/shared/configuration/types.ts
index 6d2d91e..abecb74 100644
--- a/src/shared/configuration/types.ts
+++ b/src/shared/configuration/types.ts
@@ -1,12 +1,13 @@
 import * as azureCore from "@azure/core-http";
 import { InstrumentationConfig } from "@opentelemetry/instrumentation";
+import { Resource } from "@opentelemetry/resources";
 
 export const ENV_AZURE_PREFIX = "APPSETTING_"; // Azure adds this prefix to all environment variables
 export const ENV_IKEY = "APPINSIGHTS_INSTRUMENTATIONKEY"; // This key is provided in the readme
 export const LEGACY_ENV_IKEY = "APPINSIGHTS_INSTRUMENTATION_KEY";
 export const ENV_QUCKPULSE_HOST = "APPINSIGHTS_QUICKPULSE_HOST";
 
-export interface IConfig {
+export interface IBaseConfig {
     /** Connection String used to send telemetry payloads to */
     connectionString: string;
     /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
@@ -51,8 +52,13 @@ export interface IConfig {
      * Disable offline storage when telemetry cannot be exported.
      */
     disableOfflineStorage: boolean;
+}
+
+export interface IConfig extends IBaseConfig {
     /** AAD TokenCredential to use to authenticate the app */
     aadTokenCredential?: azureCore.TokenCredential;
+    /** OpenTelemetry Resource */
+    resource?: Resource;
 }
 
 export interface InstrumentationsConfig {
diff --git a/src/shared/index.ts b/src/shared/index.ts
index 3957d2e..163c181 100644
--- a/src/shared/index.ts
+++ b/src/shared/index.ts
@@ -3,4 +3,3 @@
 
 export { ApplicationInsightsConfig } from "./configuration";
 export { AzureVirtualMachine } from "./azureVirtualMachine";
-export { ResourceManager } from "./resourceManager";
diff --git a/src/shared/resourceManager.ts b/src/shared/resourceManager.ts
deleted file mode 100644
index 0de9622..0000000
--- a/src/shared/resourceManager.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-﻿import * as os from "os";
-import { Resource } from "@opentelemetry/resources";
-import {
-    SemanticResourceAttributes,
-    TelemetrySdkLanguageValues,
-} from "@opentelemetry/semantic-conventions";
-import { APPLICATION_INSIGHTS_SDK_VERSION } from "../declarations/constants";
-
-const DEFAULT_ROLE_NAME = "Web";
-
-export class ResourceManager {
-    private static _instance: ResourceManager;
-    private _baseResource: Resource;
-    private _traceResource: Resource;
-    private _metricResource: Resource;
-    private _logResource: Resource;
-
-    constructor() {
-        this._baseResource = Resource.EMPTY;
-        this._loadAttributes();
-        this._traceResource = Resource.EMPTY.merge(this._baseResource);
-        this._metricResource = Resource.EMPTY.merge(this._baseResource);
-        this._logResource = Resource.EMPTY.merge(this._baseResource);
-    }
-
-    public static getInstance() {
-        if (!ResourceManager._instance) {
-            ResourceManager._instance = new ResourceManager();
-        }
-        return ResourceManager._instance;
-    }
-
-    public getTraceResource(): Resource {
-        return this._traceResource;
-    }
-
-    public getMetricResource(): Resource {
-        return this._metricResource;
-    }
-
-    public getLogResource(): Resource {
-        return this._logResource;
-    }
-
-    private _loadAttributes() {
-        this._baseResource.attributes[SemanticResourceAttributes.SERVICE_NAME] = DEFAULT_ROLE_NAME;
-        this._baseResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
-            os && os.hostname();
-        if (process.env.WEBSITE_SITE_NAME) {
-            // Azure Web apps and Functions
-            this._baseResource.attributes[SemanticResourceAttributes.SERVICE_NAME] =
-                process.env.WEBSITE_SITE_NAME;
-        }
-        if (process.env.WEBSITE_INSTANCE_ID) {
-            this._baseResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
-                process.env.WEBSITE_INSTANCE_ID;
-        }
-        const sdkVersion = APPLICATION_INSIGHTS_SDK_VERSION;
-        this._baseResource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE] =
-            TelemetrySdkLanguageValues.NODEJS;
-        this._baseResource.attributes[
-            SemanticResourceAttributes.TELEMETRY_SDK_VERSION
-        ] = `node:${sdkVersion}`;
-    }
-}
diff --git a/src/traces/traceHandler.ts b/src/traces/traceHandler.ts
index 5a400b7..bf32b0f 100644
--- a/src/traces/traceHandler.ts
+++ b/src/traces/traceHandler.ts
@@ -17,7 +17,7 @@ import { NodeTracerProvider, NodeTracerConfig } from "@opentelemetry/sdk-trace-n
 import { BatchSpanProcessor, BufferConfig, Tracer } from "@opentelemetry/sdk-trace-base";
 import { HttpInstrumentation, HttpInstrumentationConfig, IgnoreOutgoingRequestFunction } from "@opentelemetry/instrumentation-http";
 
-import { ApplicationInsightsConfig, ResourceManager } from "../shared";
+import { ApplicationInsightsConfig } from "../shared";
 import { TracerProvider } from "@opentelemetry/api";
 import { MetricHandler } from "../metrics/metricHandler";
 import { AzureSpanProcessor } from "./azureSpanProcessor";
@@ -53,7 +53,7 @@ export class TraceHandler {
         const aiSampler = new ApplicationInsightsSampler(this._config.samplingRate);
         const tracerConfig: NodeTracerConfig = {
             sampler: aiSampler,
-            resource: ResourceManager.getInstance().getTraceResource(),
+            resource: this._config.resource,
             forceFlushTimeoutMillis: 30000,
         };
         this._tracerProvider = new NodeTracerProvider(tracerConfig);


Test patch:
diff --git a/test/unitTests/metrics/heartbeat.tests.ts b/test/unitTests/metrics/heartbeat.tests.ts
index 80c137c..754e548 100644
--- a/test/unitTests/metrics/heartbeat.tests.ts
+++ b/test/unitTests/metrics/heartbeat.tests.ts
@@ -3,7 +3,7 @@ import * as sinon from "sinon";
 import * as os from "os";
 
 import { HeartBeatHandler } from "../../../src/metrics/handlers/heartBeatHandler";
-import { ApplicationInsightsConfig, ResourceManager } from "../../../src/shared";
+import { ApplicationInsightsConfig } from "../../../src/shared";
 import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
 
 describe("AutoCollection/HeartBeat", () => {
@@ -97,7 +97,7 @@ describe("AutoCollection/HeartBeat", () => {
                     );
                     assert.equal(
                         properties["sdk"],
-                        ResourceManager.getInstance().getMetricResource().attributes[
+                        config.resource.attributes[
                             SemanticResourceAttributes.TELEMETRY_SDK_VERSION
                         ],
                         "sdk version should be read from Context"
@@ -149,7 +149,7 @@ describe("AutoCollection/HeartBeat", () => {
                 );
                 assert.equal(
                     properties["sdk"],
-                    ResourceManager.getInstance().getMetricResource().attributes[
+                    config.resource.attributes[
                         SemanticResourceAttributes.TELEMETRY_SDK_VERSION
                     ],
                     "sdk version should be read from Context"
diff --git a/test/unitTests/shared/config.tests.ts b/test/unitTests/shared/config.tests.ts
index bff10e0..a57d5b6 100644
--- a/test/unitTests/shared/config.tests.ts
+++ b/test/unitTests/shared/config.tests.ts
@@ -1,5 +1,7 @@
 import * as assert from "assert";
+import * as fs from "fs";
 import * as path from "path";
+import * as os from "os";
 import * as sinon from "sinon";
 import * as http from "http";
 import * as https from "https";
@@ -7,6 +9,8 @@ import * as https from "https";
 import { ApplicationInsightsConfig } from "../../../src/shared";
 import { JsonConfig } from "../../../src/shared/configuration/jsonConfig";
 import { ENV_AZURE_PREFIX, ENV_IKEY } from "../../../src/shared/configuration/types";
+import { Resource } from "@opentelemetry/resources";
+import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
 
 const ENV_connectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING";
 
@@ -212,4 +216,70 @@ 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.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");
+        });
+
+        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
+                ].toString(),
+                `node:${packageJson.version}`
+            );
+            assert.equal(
+                config.resource.attributes[
+                SemanticResourceAttributes.SERVICE_INSTANCE_ID
+                ],
+                "host"
+            );
+            assert.equal(
+                config.resource.attributes[
+                SemanticResourceAttributes.SERVICE_NAME
+                ],
+                "Web"
+            );
+        });
+
+        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"
+            );
+        });
+    });
 });
diff --git a/test/unitTests/shared/resourceManager.tests.ts b/test/unitTests/shared/resourceManager.tests.ts
deleted file mode 100644
index 8230c40..0000000
--- a/test/unitTests/shared/resourceManager.tests.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import * as assert from "assert";
-import * as sinon from "sinon";
-import * as fs from "fs";
-import * as os from "os";
-import * as path from "path";
-import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
-import { ResourceManager } from "../../../src/shared";
-
-describe("ResourceManager", () => {
-    let sandbox: sinon.SinonSandbox;
-
-    describe("#constructor()", () => {
-        before(() => {
-            sandbox = sinon.createSandbox();
-            // Create custom package json
-            const jsonContent = JSON.stringify({ version: "testVersion" });
-            const testFilePath = path.resolve(__dirname, "testpackage.json");
-            fs.writeFile(testFilePath, jsonContent, () => {});
-        });
-
-        after(() => {
-            const testFilePath = path.resolve(__dirname, "testpackage.json");
-            fs.unlink(testFilePath, (err) => {});
-        });
-
-        beforeEach(() => {
-            sandbox.stub(os, "hostname").callsFake(() => "host");
-            sandbox.stub(os, "type").callsFake(() => "type");
-            sandbox.stub(os, "arch").callsFake(() => "arch");
-            sandbox.stub(os, "release").callsFake(() => "release");
-            sandbox.stub(os, "platform").callsFake(() => "linux");
-        });
-
-        afterEach(() => {
-            sandbox.restore();
-        });
-
-        it("should set internalSdkVersion to 'node:<version>'", () => {
-            const resourceManager = new ResourceManager();
-            const packageJsonPath = path.resolve(__dirname, "../../../../", "./package.json");
-            const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
-            assert.equal(
-                resourceManager["_baseResource"].attributes[
-                    SemanticResourceAttributes.TELEMETRY_SDK_VERSION
-                ].toString(),
-                `node:${packageJson.version}`
-            );
-        });
-
-        it("should correctly set service attributes", () => {
-            const resourceManager = new ResourceManager();
-            assert.equal(
-                resourceManager["_baseResource"].attributes[
-                    SemanticResourceAttributes.SERVICE_INSTANCE_ID
-                ],
-                "host"
-            );
-            assert.equal(
-                resourceManager["_baseResource"].attributes[
-                    SemanticResourceAttributes.SERVICE_NAME
-                ],
-                "Web"
-            );
-        });
-
-        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 resourceManager = new ResourceManager();
-            process.env = originalEnv;
-            assert.equal(
-                resourceManager["_baseResource"].attributes[
-                    SemanticResourceAttributes.SERVICE_INSTANCE_ID
-                ],
-                "testRoleInstanceId"
-            );
-            assert.equal(
-                resourceManager["_baseResource"].attributes[
-                    SemanticResourceAttributes.SERVICE_NAME
-                ],
-                "testRole"
-            );
-        });
-    });
-});