From 3facdbc591ca613503923fbb46501e8ec7abfe20 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Fri, 9 Feb 2024 14:57:14 -0800 Subject: [PATCH 1/7] change tags type --- .../src/TelemetryContext.ts | 32 ++++++++++++------- .../ITelemetryItem.ts | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts index 0c62bbb1e..16879b70d 100644 --- a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts +++ b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts @@ -106,8 +106,11 @@ export class TelemetryContext implements IPropTelemetryContext { if (application) { // evt.ext.app let tags = getSetValue(evt, strTags); - setValue(tags, CtxTagKeys.applicationVersion, application.ver, isString); - setValue(tags, CtxTagKeys.applicationBuild, application.build, isString) + if (!Array.isArray(tags)) { + tags = [tags]; + } + tags.push({[CtxTagKeys.applicationVersion]: "application.ver"}); + tags.push({[CtxTagKeys.applicationBuild]: "application.build"}); } }; @@ -127,13 +130,14 @@ export class TelemetryContext implements IPropTelemetryContext { let internal = _self.internal; if (internal) { let tags = getSetValue(evt, strTags); - - setValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion, isString); // not mapped in CS 4.0 - setValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64), isString); - + if (!Array.isArray(tags)) { + tags = [tags]; + } + tags.push({[CtxTagKeys.internalAgentVersion]: internal.agentVersion}); + tags.push({[CtxTagKeys.internalSdkVersion]: dataSanitizeString(logger, internal.sdkVersion, 64)}); if (evt.baseType === _InternalLogMessage.dataType || evt.baseType === PageView.dataType) { - setValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer, isString); - setValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc, isString); + tags.push({[CtxTagKeys.internalSnippet]: internal.snippetVer}); + tags.push({[CtxTagKeys.internalSdkSrc]: internal.sdkSrc}); } } }; @@ -141,7 +145,11 @@ export class TelemetryContext implements IPropTelemetryContext { _self.applyLocationContext = (evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => { let location = this.location; if (location) { - setValue(getSetValue(evt, strTags, []), CtxTagKeys.locationIp, location.ip, isString); + let tags = getSetValue(evt, strTags); + if (!Array.isArray(tags)) { + tags = [tags]; + } + tags.push({[CtxTagKeys.locationIp]: location.ip}); } }; @@ -166,9 +174,11 @@ export class TelemetryContext implements IPropTelemetryContext { let user = _self.user; if (user) { let tags = getSetValue(evt, strTags, []); - + if (!Array.isArray(tags)) { + tags = [tags]; + } // stays in tags - setValue(tags, CtxTagKeys.userAccountId, user.accountId, isString); + tags.push({[CtxTagKeys.userAccountId]: user.accountId}); // CS 4.0 let extUser = getSetValue(getSetValue(evt, strExt), Extensions.UserExt); diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts index b91b6bc74..d652c228b 100644 --- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts @@ -34,7 +34,7 @@ export interface ITelemetryItem { /** * System context property extensions that are not global (not in ctx) */ - tags?: Tags & Tags[]; // Tags[] will be deprecated. + tags?: Tags | Tags[]; // Tags[] will be deprecated. /** * Custom data From f2d94e93619c06a1056494469452bf7a6fe6a15e Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Fri, 9 Feb 2024 15:11:33 -0800 Subject: [PATCH 2/7] Update TelemetryContext.ts --- .../src/TelemetryContext.ts | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts index 16879b70d..12f9187bd 100644 --- a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts +++ b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts @@ -9,7 +9,7 @@ import { IUserContext, IWeb, PageView, dataSanitizeString } from "@microsoft/applicationinsights-common"; import { - IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, _InternalLogMessage, + IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, Tags, _InternalLogMessage, getSetValue, hasWindow, isNullOrUndefined, isString, objKeys, setValue } from "@microsoft/applicationinsights-core-js"; import { Application } from "./Context/Application"; @@ -106,11 +106,8 @@ export class TelemetryContext implements IPropTelemetryContext { if (application) { // evt.ext.app let tags = getSetValue(evt, strTags); - if (!Array.isArray(tags)) { - tags = [tags]; - } - tags.push({[CtxTagKeys.applicationVersion]: "application.ver"}); - tags.push({[CtxTagKeys.applicationBuild]: "application.build"}); + this.setTageValue(tags, CtxTagKeys.applicationVersion, application.ver); + this.setTageValue(tags, CtxTagKeys.applicationBuild, application.build); } }; @@ -130,14 +127,11 @@ export class TelemetryContext implements IPropTelemetryContext { let internal = _self.internal; if (internal) { let tags = getSetValue(evt, strTags); - if (!Array.isArray(tags)) { - tags = [tags]; - } - tags.push({[CtxTagKeys.internalAgentVersion]: internal.agentVersion}); - tags.push({[CtxTagKeys.internalSdkVersion]: dataSanitizeString(logger, internal.sdkVersion, 64)}); + this.setTageValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion); + this.setTageValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64)); if (evt.baseType === _InternalLogMessage.dataType || evt.baseType === PageView.dataType) { - tags.push({[CtxTagKeys.internalSnippet]: internal.snippetVer}); - tags.push({[CtxTagKeys.internalSdkSrc]: internal.sdkSrc}); + this.setTageValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer); + this.setTageValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc); } } }; @@ -145,14 +139,12 @@ export class TelemetryContext implements IPropTelemetryContext { _self.applyLocationContext = (evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => { let location = this.location; if (location) { - let tags = getSetValue(evt, strTags); - if (!Array.isArray(tags)) { - tags = [tags]; - } - tags.push({[CtxTagKeys.locationIp]: location.ip}); + let tags = getSetValue(evt, strTags, []); + this.setTageValue(tags, CtxTagKeys.locationIp, location.ip); } }; - + + _self.applyOperationContext = (evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => { let telemetryTrace = _self.telemetryTrace; if (telemetryTrace) { @@ -174,12 +166,8 @@ export class TelemetryContext implements IPropTelemetryContext { let user = _self.user; if (user) { let tags = getSetValue(evt, strTags, []); - if (!Array.isArray(tags)) { - tags = [tags]; - } // stays in tags - tags.push({[CtxTagKeys.userAccountId]: user.accountId}); - + this.setTageValue(tags, CtxTagKeys.userAccountId, user.accountId); // CS 4.0 let extUser = getSetValue(getSetValue(evt, strExt), Extensions.UserExt); setValue(extUser, "id", user.id, isString); @@ -201,6 +189,17 @@ export class TelemetryContext implements IPropTelemetryContext { }); } + private setTageValue = (tags: Tags | Tags[], field: string, value: string): void => { + // Function body + if (Array.isArray(tags)) { + tags.forEach(tag => setValue(tag, field, value, isString) + ); + } else { + setValue(tags, field, value, isString) + } + } + } + public applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) { // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging } From bd9c1030be714f52aaee4c700fcec968515f614b Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Fri, 9 Feb 2024 15:13:42 -0800 Subject: [PATCH 3/7] Update TelemetryContext.ts --- .../src/TelemetryContext.ts | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts index 12f9187bd..bfb6edbcc 100644 --- a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts +++ b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts @@ -35,6 +35,17 @@ function _nullResult(): string { return null; } +function setTageValue(tags: Tags | Tags[], field: string, value: string): void { + // Function body + if (Array.isArray(tags)) { + tags.forEach(tag => setValue(tag, field, value, isString) + ); + } else { + setValue(tags, field, value, isString) + } +} + + export class TelemetryContext implements IPropTelemetryContext { public application: IApplication; // The object describing a component tracked by this object - legacy @@ -106,8 +117,8 @@ export class TelemetryContext implements IPropTelemetryContext { if (application) { // evt.ext.app let tags = getSetValue(evt, strTags); - this.setTageValue(tags, CtxTagKeys.applicationVersion, application.ver); - this.setTageValue(tags, CtxTagKeys.applicationBuild, application.build); + setTageValue(tags, CtxTagKeys.applicationVersion, application.ver); + setTageValue(tags, CtxTagKeys.applicationBuild, application.build); } }; @@ -127,11 +138,11 @@ export class TelemetryContext implements IPropTelemetryContext { let internal = _self.internal; if (internal) { let tags = getSetValue(evt, strTags); - this.setTageValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion); - this.setTageValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64)); + setTageValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion); + setTageValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64)); if (evt.baseType === _InternalLogMessage.dataType || evt.baseType === PageView.dataType) { - this.setTageValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer); - this.setTageValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc); + setTageValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer); + setTageValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc); } } }; @@ -140,7 +151,7 @@ export class TelemetryContext implements IPropTelemetryContext { let location = this.location; if (location) { let tags = getSetValue(evt, strTags, []); - this.setTageValue(tags, CtxTagKeys.locationIp, location.ip); + setTageValue(tags, CtxTagKeys.locationIp, location.ip); } }; @@ -167,7 +178,7 @@ export class TelemetryContext implements IPropTelemetryContext { if (user) { let tags = getSetValue(evt, strTags, []); // stays in tags - this.setTageValue(tags, CtxTagKeys.userAccountId, user.accountId); + setTageValue(tags, CtxTagKeys.userAccountId, user.accountId); // CS 4.0 let extUser = getSetValue(getSetValue(evt, strExt), Extensions.UserExt); setValue(extUser, "id", user.id, isString); @@ -189,16 +200,6 @@ export class TelemetryContext implements IPropTelemetryContext { }); } - private setTageValue = (tags: Tags | Tags[], field: string, value: string): void => { - // Function body - if (Array.isArray(tags)) { - tags.forEach(tag => setValue(tag, field, value, isString) - ); - } else { - setValue(tags, field, value, isString) - } - } - } public applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) { // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging From db4466144a3895a94753062278bf8d7a9366ce47 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 12 Feb 2024 10:50:42 -0800 Subject: [PATCH 4/7] Update TelemetryContext.ts --- .../src/TelemetryContext.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts index bfb6edbcc..84c795279 100644 --- a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts +++ b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts @@ -10,7 +10,7 @@ import { } from "@microsoft/applicationinsights-common"; import { IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, Tags, _InternalLogMessage, - getSetValue, hasWindow, isNullOrUndefined, isString, objKeys, setValue + arrForEach, getSetValue, hasWindow, isArray, isNullOrUndefined, isString, objKeys, setValue } from "@microsoft/applicationinsights-core-js"; import { Application } from "./Context/Application"; import { Device } from "./Context/Device"; @@ -36,10 +36,8 @@ function _nullResult(): string { } function setTageValue(tags: Tags | Tags[], field: string, value: string): void { - // Function body - if (Array.isArray(tags)) { - tags.forEach(tag => setValue(tag, field, value, isString) - ); + if (isArray(tags)) { + arrForEach(tags, (tag) => setValue(tag, field, value, isString)); } else { setValue(tags, field, value, isString) } From 2803f3bd85bc6f4d0bee1ba489ce9f78e2fb7970 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 12 Feb 2024 11:44:18 -0800 Subject: [PATCH 5/7] remove tags[] --- .../src/TelemetryContext.ts | 38 ++++++++----------- .../ITelemetryItem.ts | 2 +- .../src/applicationinsights-web-snippet.ts | 2 +- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts index 84c795279..0c62bbb1e 100644 --- a/extensions/applicationinsights-properties-js/src/TelemetryContext.ts +++ b/extensions/applicationinsights-properties-js/src/TelemetryContext.ts @@ -9,8 +9,8 @@ import { IUserContext, IWeb, PageView, dataSanitizeString } from "@microsoft/applicationinsights-common"; import { - IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, Tags, _InternalLogMessage, - arrForEach, getSetValue, hasWindow, isArray, isNullOrUndefined, isString, objKeys, setValue + IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, _InternalLogMessage, + getSetValue, hasWindow, isNullOrUndefined, isString, objKeys, setValue } from "@microsoft/applicationinsights-core-js"; import { Application } from "./Context/Application"; import { Device } from "./Context/Device"; @@ -35,15 +35,6 @@ function _nullResult(): string { return null; } -function setTageValue(tags: Tags | Tags[], field: string, value: string): void { - if (isArray(tags)) { - arrForEach(tags, (tag) => setValue(tag, field, value, isString)); - } else { - setValue(tags, field, value, isString) - } -} - - export class TelemetryContext implements IPropTelemetryContext { public application: IApplication; // The object describing a component tracked by this object - legacy @@ -115,8 +106,8 @@ export class TelemetryContext implements IPropTelemetryContext { if (application) { // evt.ext.app let tags = getSetValue(evt, strTags); - setTageValue(tags, CtxTagKeys.applicationVersion, application.ver); - setTageValue(tags, CtxTagKeys.applicationBuild, application.build); + setValue(tags, CtxTagKeys.applicationVersion, application.ver, isString); + setValue(tags, CtxTagKeys.applicationBuild, application.build, isString) } }; @@ -136,11 +127,13 @@ export class TelemetryContext implements IPropTelemetryContext { let internal = _self.internal; if (internal) { let tags = getSetValue(evt, strTags); - setTageValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion); - setTageValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64)); + + setValue(tags, CtxTagKeys.internalAgentVersion, internal.agentVersion, isString); // not mapped in CS 4.0 + setValue(tags, CtxTagKeys.internalSdkVersion, dataSanitizeString(logger, internal.sdkVersion, 64), isString); + if (evt.baseType === _InternalLogMessage.dataType || evt.baseType === PageView.dataType) { - setTageValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer); - setTageValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc); + setValue(tags, CtxTagKeys.internalSnippet, internal.snippetVer, isString); + setValue(tags, CtxTagKeys.internalSdkSrc, internal.sdkSrc, isString); } } }; @@ -148,12 +141,10 @@ export class TelemetryContext implements IPropTelemetryContext { _self.applyLocationContext = (evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => { let location = this.location; if (location) { - let tags = getSetValue(evt, strTags, []); - setTageValue(tags, CtxTagKeys.locationIp, location.ip); + setValue(getSetValue(evt, strTags, []), CtxTagKeys.locationIp, location.ip, isString); } }; - - + _self.applyOperationContext = (evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => { let telemetryTrace = _self.telemetryTrace; if (telemetryTrace) { @@ -175,8 +166,10 @@ export class TelemetryContext implements IPropTelemetryContext { let user = _self.user; if (user) { let tags = getSetValue(evt, strTags, []); + // stays in tags - setTageValue(tags, CtxTagKeys.userAccountId, user.accountId); + setValue(tags, CtxTagKeys.userAccountId, user.accountId, isString); + // CS 4.0 let extUser = getSetValue(getSetValue(evt, strExt), Extensions.UserExt); setValue(extUser, "id", user.id, isString); @@ -198,7 +191,6 @@ export class TelemetryContext implements IPropTelemetryContext { }); } - public applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext) { // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging } diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts index d652c228b..528fe5fb2 100644 --- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts @@ -34,7 +34,7 @@ export interface ITelemetryItem { /** * System context property extensions that are not global (not in ctx) */ - tags?: Tags | Tags[]; // Tags[] will be deprecated. + tags?: Tags; // Tags[] is deprecated since 4.1.0 /** * Custom data diff --git a/tools/applicationinsights-web-snippet/src/applicationinsights-web-snippet.ts b/tools/applicationinsights-web-snippet/src/applicationinsights-web-snippet.ts index 3a275ab1d..147af1dfc 100644 --- a/tools/applicationinsights-web-snippet/src/applicationinsights-web-snippet.ts +++ b/tools/applicationinsights-web-snippet/src/applicationinsights-web-snippet.ts @@ -18,7 +18,7 @@ function getSdkLoaderScript(config: SdkLoaderConfig) { snippet = webSnippetCs.replace("YOUR_CONNECTION_STRING", config.connectionString); } else if (config && config.instrumentationKey) { snippet = webSnippet.replace("InstrumentationKey=INSTRUMENTATION_KEY", config.instrumentationKey); - } + } return snippet; } From 55585342bbcbfe4286245676f30050ae86dda1b2 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 12 Feb 2024 12:50:16 -0800 Subject: [PATCH 6/7] add notes --- AISKU/API.md | 2 +- RELEASES.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/AISKU/API.md b/AISKU/API.md index 741f4f916..d383b66d1 100644 --- a/AISKU/API.md +++ b/AISKU/API.md @@ -205,7 +205,7 @@ interface ITelemetryItem { /** * Part A custom extensions */ - tags?: Tags[]; + tags?: // Tags[] is deprecated since 4.1.0 /** * Telemetry type used for part B diff --git a/RELEASES.md b/RELEASES.md index c2ea5cd2b..ce5f3d1f2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -2,6 +2,27 @@ > Note: ES3/IE8 compatibility will be removed in the future v3.x.x releases (scheduled for mid-late 2022), so if you need to retain ES3 compatibility you will need to remain on the 2.x.x versions of the SDK or your runtime will need install polyfill's to your ES3 environment before loading / initializing the SDK. +## 4.0.1 (Feb 12nd, 2024) + +### Potential break change + +This release contains a potential break change with 'tags' type [change](https://github.com/microsoft/ApplicationInsights-JS/pull/2269) + +#### Old +```ts + tags?: Tags & Tags[]; +``` +#### New +```ts + tags?: Tags; + +``` + +### Changelog + + + + ## 3.0.7 (Dec 14th, 2023) ### Changelog From 75a5b1ed7e824e50329c54d35327d0713273eb05 Mon Sep 17 00:00:00 2001 From: siyuniu-ms Date: Mon, 12 Feb 2024 12:51:21 -0800 Subject: [PATCH 7/7] fix --- AISKU/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AISKU/API.md b/AISKU/API.md index d383b66d1..cc67ccc3a 100644 --- a/AISKU/API.md +++ b/AISKU/API.md @@ -205,7 +205,7 @@ interface ITelemetryItem { /** * Part A custom extensions */ - tags?: // Tags[] is deprecated since 4.1.0 + tags?: Tags; // Tags[] is deprecated since 4.1.0 /** * Telemetry type used for part B