From bd9fd3d9c8d74413d8246d1585ca2f69b7b08160 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Tue, 2 Jan 2024 15:11:32 -0800 Subject: [PATCH 1/3] Update PropertiesPlugin.ts --- .../applicationinsights-properties-js/src/PropertiesPlugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts b/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts index c24e9c7a1..eba969445 100644 --- a/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts +++ b/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts @@ -126,7 +126,7 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr _distributedTraceCtx = null; _previousTraceCtx = null; _context = null; - _disableUserInitMessage = false; + _disableUserInitMessage = true; } function _populateDefaults(config: IConfiguration & IConfig) { @@ -139,7 +139,7 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr if (config.storagePrefix){ utlSetStoragePrefix(config.storagePrefix); } - _disableUserInitMessage = config.disableUserInitMessage || false; + _disableUserInitMessage = config.disableUserInitMessage || true; _extensionConfig = ctx.getExtCfg(identifier, _defaultConfig); // Test hook to allow accessing the internal values -- explicitly not defined as an available property on the class From f8bba9414c0f62a085c55d23536e385f5566f618 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 8 Jan 2024 10:46:42 -0800 Subject: [PATCH 2/3] Update properties.tests.ts --- .../Tests/Unit/src/properties.tests.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts b/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts index eff8fdd04..723d0fb29 100644 --- a/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts +++ b/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts @@ -634,7 +634,8 @@ export class PropertiesTests extends AITestClass { }); this.testCase({ - name: 'User: track is triggered if user context is first time initialized', + name: 'User: track is triggered if user context is first time initialized and _disableUserInitMessage is set to false', + useFakeTimers: true, test: () => { // setup var setCookieStub = this.sandbox.stub(this as any, "_setCookie").callsFake(() => {}); @@ -646,6 +647,9 @@ export class PropertiesTests extends AITestClass { this.properties.initialize(this.getEmptyConfig(), this.core, []); Assert.ok(setCookieStub.called, 'Cookie generated'); + this.core.config["disableUserInitMessage"] = false; + this.clock.tick(1000); + // Assert Assert.equal(true, this.properties.context.user.isNewUser, 'current user is a new user'); const item: ITelemetryItem = {name: 'item'}; From 89206de3870072d8e9cc4465af45753e83fc8ca7 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 8 Jan 2024 21:38:51 -0800 Subject: [PATCH 3/3] change test --- .../Tests/Unit/src/properties.tests.ts | 10 ++++------ .../src/PropertiesPlugin.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts b/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts index 723d0fb29..7a2cde097 100644 --- a/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts +++ b/extensions/applicationinsights-properties-js/Tests/Unit/src/properties.tests.ts @@ -637,16 +637,14 @@ export class PropertiesTests extends AITestClass { name: 'User: track is triggered if user context is first time initialized and _disableUserInitMessage is set to false', useFakeTimers: true, test: () => { - // setup var setCookieStub = this.sandbox.stub(this as any, "_setCookie").callsFake(() => {}); - var loggingStub = this.sandbox.stub(this.core.logger, "logInternalMessage"); - - // Act Assert.ok(setCookieStub.notCalled, 'Cookie not yet generated'); - Assert.ok(loggingStub.notCalled, 'logInternalMessage is not yet triggered'); - this.properties.initialize(this.getEmptyConfig(), this.core, []); + this.core.initialize(this.getEmptyConfig(), [this.properties]); Assert.ok(setCookieStub.called, 'Cookie generated'); + var loggingStub = this.sandbox.stub(this.core.logger, "logInternalMessage"); + Assert.ok(loggingStub.notCalled, 'logInternalMessage is not yet triggered'); + this.core.config["disableUserInitMessage"] = false; this.clock.tick(1000); diff --git a/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts b/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts index eba969445..842e620d9 100644 --- a/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts +++ b/extensions/applicationinsights-properties-js/src/PropertiesPlugin.ts @@ -139,7 +139,7 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr if (config.storagePrefix){ utlSetStoragePrefix(config.storagePrefix); } - _disableUserInitMessage = config.disableUserInitMessage || true; + _disableUserInitMessage = config.disableUserInitMessage === false ? false : true; _extensionConfig = ctx.getExtCfg(identifier, _defaultConfig); // Test hook to allow accessing the internal values -- explicitly not defined as an available property on the class