@microsoft/applicationinsights-properties-js 3.0.0-beta.2301-15 → 3.0.0-beta.2301-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/browser/applicationinsights-properties-js.integrity.json +9 -9
  2. package/browser/applicationinsights-properties-js.js +140 -93
  3. package/browser/applicationinsights-properties-js.js.map +1 -1
  4. package/browser/applicationinsights-properties-js.min.js +2 -2
  5. package/browser/applicationinsights-properties-js.min.js.map +1 -1
  6. package/dist/applicationinsights-properties-js.api.json +34 -0
  7. package/dist/applicationinsights-properties-js.api.md +3 -2
  8. package/dist/applicationinsights-properties-js.d.ts +4 -4
  9. package/dist/applicationinsights-properties-js.js +140 -93
  10. package/dist/applicationinsights-properties-js.js.map +1 -1
  11. package/dist/applicationinsights-properties-js.min.js +2 -2
  12. package/dist/applicationinsights-properties-js.min.js.map +1 -1
  13. package/dist/applicationinsights-properties-js.rollup.d.ts +4 -4
  14. package/dist-esm/Context/Application.js +1 -1
  15. package/dist-esm/Context/Device.js +1 -1
  16. package/dist-esm/Context/Internal.js +4 -3
  17. package/dist-esm/Context/Internal.js.map +1 -1
  18. package/dist-esm/Context/Location.js +1 -1
  19. package/dist-esm/Context/Session.js +23 -24
  20. package/dist-esm/Context/Session.js.map +1 -1
  21. package/dist-esm/Context/TelemetryTrace.js +1 -1
  22. package/dist-esm/Context/User.js +4 -3
  23. package/dist-esm/Context/User.js.map +1 -1
  24. package/dist-esm/Interfaces/IPropTelemetryContext.js +1 -1
  25. package/dist-esm/Interfaces/IPropertiesConfig.js +1 -1
  26. package/dist-esm/PropertiesPlugin.js +11 -12
  27. package/dist-esm/PropertiesPlugin.js.map +1 -1
  28. package/dist-esm/TelemetryContext.js +5 -5
  29. package/dist-esm/TelemetryContext.js.map +1 -1
  30. package/dist-esm/__DynamicConstants.js +3 -3
  31. package/dist-esm/__DynamicConstants.js.map +1 -1
  32. package/dist-esm/applicationinsights-properties-js.js +1 -1
  33. package/package.json +3 -3
  34. package/src/Context/Internal.ts +5 -3
  35. package/src/Context/Session.ts +27 -27
  36. package/src/Context/User.ts +6 -4
  37. package/src/Interfaces/IPropertiesConfig.ts +0 -1
  38. package/src/PropertiesPlugin.ts +10 -9
  39. package/src/TelemetryContext.ts +6 -6
  40. package/src/__DynamicConstants.ts +2 -2
  41. package/types/Context/Internal.d.ts +2 -1
  42. package/types/Context/Session.d.ts +2 -2
  43. package/types/Context/User.d.ts +2 -2
  44. package/types/Interfaces/IPropertiesConfig.d.ts +0 -1
  45. package/types/TelemetryContext.d.ts +2 -2
  46. package/types/__DynamicConstants.d.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2301-15
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2301-18
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -11,12 +11,12 @@
11
11
  // ###########################################################################################################################################
12
12
  // Note: DON'T Export these const from the package as we are still targeting IE this will export a mutable variables that someone could change
13
13
  // ###########################################################################################################################################
14
- export var _DYN_GET_TRACE_CTX = "getTraceCtx"; // Count: 3
15
- export var _DYN_TELEMETRY_TRACE = "telemetryTrace"; // Count: 3
16
14
  export var _DYN_SESSION_MANAGER = "sessionManager"; // Count: 3
17
15
  export var _DYN_UPDATE = "update"; // Count: 4
18
16
  export var _DYN_IS_USER_COOKIE_SET = "isUserCookieSet"; // Count: 4
19
17
  export var _DYN_IS_NEW_USER = "isNewUser"; // Count: 4
18
+ export var _DYN_GET_TRACE_CTX = "getTraceCtx"; // Count: 3
19
+ export var _DYN_TELEMETRY_TRACE = "telemetryTrace"; // Count: 3
20
20
  export var _DYN_APPLY_SESSION_CONTEX0 = "applySessionContext"; // Count: 2
21
21
  export var _DYN_APPLY_APPLICATION_CO1 = "applyApplicationContext"; // Count: 2
22
22
  export var _DYN_APPLY_DEVICE_CONTEXT = "applyDeviceContext"; // Count: 2
@@ -1 +1 @@
1
- {"version":3,"file":"__DynamicConstants.js.map","sources":["__DynamicConstants.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n// @skip-file-minify\r\n// ##############################################################\r\n// AUTO GENERATED FILE: This file is Auto Generated during build.\r\n// ##############################################################\r\n// ###########################################################################################################################################\r\n// Note: DON'T Export these const from the package as we are still targeting IE this will export a mutable variables that someone could change\r\n// ###########################################################################################################################################\r\nexport var _DYN_GET_TRACE_CTX = \"getTraceCtx\"; // Count: 3\r\nexport var _DYN_TELEMETRY_TRACE = \"telemetryTrace\"; // Count: 3\r\nexport var _DYN_SESSION_MANAGER = \"sessionManager\"; // Count: 3\r\nexport var _DYN_UPDATE = \"update\"; // Count: 4\r\nexport var _DYN_IS_USER_COOKIE_SET = \"isUserCookieSet\"; // Count: 4\r\nexport var _DYN_IS_NEW_USER = \"isNewUser\"; // Count: 4\r\nexport var _DYN_APPLY_SESSION_CONTEX0 = \"applySessionContext\"; // Count: 2\r\nexport var _DYN_APPLY_APPLICATION_CO1 = \"applyApplicationContext\"; // Count: 2\r\nexport var _DYN_APPLY_DEVICE_CONTEXT = \"applyDeviceContext\"; // Count: 2\r\nexport var _DYN_APPLY_OPERATION_CONT2 = \"applyOperationContext\"; // Count: 2\r\nexport var _DYN_APPLY_USER_CONTEXT = \"applyUserContext\"; // Count: 2\r\nexport var _DYN_APPLY_OPERATING_SYST3 = \"applyOperatingSystemContxt\"; // Count: 2\r\nexport var _DYN_APPLY_LOCATION_CONTE4 = \"applyLocationContext\"; // Count: 2\r\nexport var _DYN_APPLY_INTERNAL_CONTE5 = \"applyInternalContext\"; // Count: 2\r\nexport var _DYN_ACCOUNT_ID = \"accountId\"; // Count: 7\r\nexport var _DYN_GET_SESSION_ID = \"getSessionId\"; // Count: 4\r\nexport var _DYN_NAME_PREFIX = \"namePrefix\"; // Count: 3\r\nexport var _DYN_SESSION_COOKIE_POSTF6 = \"sessionCookiePostfix\"; // Count: 2\r\nexport var _DYN_USER_COOKIE_POSTFIX = \"userCookiePostfix\"; // Count: 2\r\nexport var _DYN_ID_LENGTH = \"idLength\"; // Count: 4\r\nexport var _DYN_GET_NEW_ID = \"getNewId\"; // Count: 3\r\nexport var _DYN_LENGTH = \"length\"; // Count: 4\r\nexport var _DYN_AUTOMATIC_SESSION = \"automaticSession\"; // Count: 5\r\nexport var _DYN_AUTHENTICATED_ID = \"authenticatedId\"; // Count: 6\r\nexport var _DYN_ACQUISITION_DATE = \"acquisitionDate\"; // Count: 5\r\nexport var _DYN_RENEWAL_DATE = \"renewalDate\"; // Count: 4\r\nexport var _DYN_JOIN = \"join\"; // Count: 5\r\nexport var _DYN_COOKIE_SEPARATOR = \"cookieSeparator\"; // Count: 5\r\nexport var _DYN_AUTH_USER_COOKIE_NAM7 = \"authUserCookieName\"; // Count: 3\r\n//# sourceMappingURL=__DynamicConstants.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"__DynamicConstants.js.map","sources":["__DynamicConstants.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n// @skip-file-minify\r\n// ##############################################################\r\n// AUTO GENERATED FILE: This file is Auto Generated during build.\r\n// ##############################################################\r\n// ###########################################################################################################################################\r\n// Note: DON'T Export these const from the package as we are still targeting IE this will export a mutable variables that someone could change\r\n// ###########################################################################################################################################\r\nexport var _DYN_SESSION_MANAGER = \"sessionManager\"; // Count: 3\r\nexport var _DYN_UPDATE = \"update\"; // Count: 4\r\nexport var _DYN_IS_USER_COOKIE_SET = \"isUserCookieSet\"; // Count: 4\r\nexport var _DYN_IS_NEW_USER = \"isNewUser\"; // Count: 4\r\nexport var _DYN_GET_TRACE_CTX = \"getTraceCtx\"; // Count: 3\r\nexport var _DYN_TELEMETRY_TRACE = \"telemetryTrace\"; // Count: 3\r\nexport var _DYN_APPLY_SESSION_CONTEX0 = \"applySessionContext\"; // Count: 2\r\nexport var _DYN_APPLY_APPLICATION_CO1 = \"applyApplicationContext\"; // Count: 2\r\nexport var _DYN_APPLY_DEVICE_CONTEXT = \"applyDeviceContext\"; // Count: 2\r\nexport var _DYN_APPLY_OPERATION_CONT2 = \"applyOperationContext\"; // Count: 2\r\nexport var _DYN_APPLY_USER_CONTEXT = \"applyUserContext\"; // Count: 2\r\nexport var _DYN_APPLY_OPERATING_SYST3 = \"applyOperatingSystemContxt\"; // Count: 2\r\nexport var _DYN_APPLY_LOCATION_CONTE4 = \"applyLocationContext\"; // Count: 2\r\nexport var _DYN_APPLY_INTERNAL_CONTE5 = \"applyInternalContext\"; // Count: 2\r\nexport var _DYN_ACCOUNT_ID = \"accountId\"; // Count: 7\r\nexport var _DYN_GET_SESSION_ID = \"getSessionId\"; // Count: 4\r\nexport var _DYN_NAME_PREFIX = \"namePrefix\"; // Count: 3\r\nexport var _DYN_SESSION_COOKIE_POSTF6 = \"sessionCookiePostfix\"; // Count: 2\r\nexport var _DYN_USER_COOKIE_POSTFIX = \"userCookiePostfix\"; // Count: 2\r\nexport var _DYN_ID_LENGTH = \"idLength\"; // Count: 4\r\nexport var _DYN_GET_NEW_ID = \"getNewId\"; // Count: 3\r\nexport var _DYN_LENGTH = \"length\"; // Count: 4\r\nexport var _DYN_AUTOMATIC_SESSION = \"automaticSession\"; // Count: 5\r\nexport var _DYN_AUTHENTICATED_ID = \"authenticatedId\"; // Count: 6\r\nexport var _DYN_ACQUISITION_DATE = \"acquisitionDate\"; // Count: 5\r\nexport var _DYN_RENEWAL_DATE = \"renewalDate\"; // Count: 4\r\nexport var _DYN_JOIN = \"join\"; // Count: 5\r\nexport var _DYN_COOKIE_SEPARATOR = \"cookieSeparator\"; // Count: 5\r\nexport var _DYN_AUTH_USER_COOKIE_NAM7 = \"authUserCookieName\"; // Count: 3\r\n//# sourceMappingURL=__DynamicConstants.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2301-15
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2301-18
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-properties-js",
3
- "version": "3.0.0-beta.2301-15",
3
+ "version": "3.0.0-beta.2301-18",
4
4
  "description": "Microsoft Application Insights properties (Part A) plugin",
5
5
  "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
6
  "author": "Microsoft Application Insights Team",
@@ -54,8 +54,8 @@
54
54
  "dependencies": {
55
55
  "@microsoft/dynamicproto-js": "^1.1.7",
56
56
  "@microsoft/applicationinsights-shims": "2.0.2",
57
- "@microsoft/applicationinsights-core-js": "3.0.0-beta.2301-15",
58
- "@microsoft/applicationinsights-common": "3.0.0-beta.2301-15",
57
+ "@microsoft/applicationinsights-core-js": "3.0.0-beta.2301-18",
58
+ "@microsoft/applicationinsights-common": "3.0.0-beta.2301-18",
59
59
  "@nevware21/ts-utils": "^0.6.0"
60
60
  },
61
61
  "license": "MIT",
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import { IInternal } from "@microsoft/applicationinsights-common";
5
- import { onConfigChange } from "@microsoft/applicationinsights-core-js";
5
+ import { IUnloadHookContainer, onConfigChange } from "@microsoft/applicationinsights-core-js";
6
6
  import { IPropertiesConfig } from "../Interfaces/IPropertiesConfig";
7
7
 
8
8
  const Version = "2.8.5";
@@ -37,11 +37,13 @@ export class Internal implements IInternal {
37
37
  /**
38
38
  * Constructs a new instance of the internal telemetry data class.
39
39
  */
40
- constructor(config: IPropertiesConfig) {
40
+ constructor(config: IPropertiesConfig, unloadHookContainer?: IUnloadHookContainer) {
41
41
 
42
- onConfigChange((config), () => {
42
+ let unloadHook = onConfigChange((config), () => {
43
43
  let prefix = config.sdkExtension;
44
44
  this.sdkVersion = (prefix ? prefix + "_" : "") + "javascript:" + Version;
45
45
  });
46
+
47
+ unloadHookContainer && unloadHookContainer.add(unloadHook);
46
48
  }
47
49
  }
@@ -4,8 +4,8 @@
4
4
  import dynamicProto from "@microsoft/dynamicproto-js";
5
5
  import { ISession, utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "@microsoft/applicationinsights-common";
6
6
  import {
7
- IAppInsightsCore, ICookieMgr, IDiagnosticLogger, _eInternalMessageId, _throwInternal, dateNow, dumpObj, eLoggingSeverity,
8
- getExceptionName, isFunction, newId, safeGetCookieMgr, safeGetLogger
7
+ IAppInsightsCore, ICookieMgr, IDiagnosticLogger, IUnloadHookContainer, _eInternalMessageId, _throwInternal, dateNow, dumpObj,
8
+ eLoggingSeverity, getExceptionName, isFunction, newId, onConfigChange, safeGetCookieMgr, safeGetLogger
9
9
  } from "@microsoft/applicationinsights-core-js";
10
10
 
11
11
  const SESSION_COOKIE_NAME = "ai_session";
@@ -51,11 +51,14 @@ export class _SessionManager {
51
51
 
52
52
  public automaticSession: Session;
53
53
 
54
- constructor(config: ISessionConfig, core?: IAppInsightsCore) {
54
+ constructor(config: ISessionConfig, core?: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer) {
55
55
  let self = this;
56
+ let _storageNamePrefix: string;
56
57
  let _cookieUpdatedTimestamp: number;
57
58
  let _logger: IDiagnosticLogger = safeGetLogger(core);
58
59
  let _cookieManager: ICookieMgr = safeGetCookieMgr(core);
60
+ let _sessionExpirationMs: number;
61
+ let _sessionRenewalMs: number;
59
62
 
60
63
  dynamicProto(_SessionManager, self, (_self) => {
61
64
 
@@ -63,6 +66,18 @@ export class _SessionManager {
63
66
  config = ({} as any);
64
67
  }
65
68
 
69
+ let unloadHook = onConfigChange(config, (details) => {
70
+ _sessionExpirationMs = config.sessionExpirationMs || ACQUISITION_SPAN;
71
+ _sessionRenewalMs = config.sessionRenewalMs || RENEWAL_SPAN;
72
+
73
+ // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.
74
+ const sessionCookiePostfix = config.sessionCookiePostfix || config.namePrefix || "";
75
+
76
+ _storageNamePrefix = SESSION_COOKIE_NAME + sessionCookiePostfix;
77
+ });
78
+
79
+ unloadHookContainer && unloadHookContainer.add(unloadHook);
80
+
66
81
  _self.automaticSession = new Session();
67
82
 
68
83
  _self.update = () => {
@@ -76,12 +91,12 @@ export class _SessionManager {
76
91
  isExpired = !_initializeAutomaticSession(session, nowMs);
77
92
  }
78
93
 
79
- if (!isExpired && _sessionExpirationMs() > 0) {
94
+ if (!isExpired && _sessionExpirationMs > 0) {
80
95
  const timeSinceAcqMs = nowMs - session.acquisitionDate;
81
96
  const timeSinceRenewalMs = nowMs - session.renewalDate;
82
97
  isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future
83
- isExpired = isExpired || timeSinceAcqMs > _sessionExpirationMs(); // expired if the time since acquisition is more than session Expiration
84
- isExpired = isExpired || timeSinceRenewalMs > _sessionRenewalMs(); // expired if the time since last renewal is more than renewal period
98
+ isExpired = isExpired || timeSinceAcqMs > _sessionExpirationMs; // expired if the time since acquisition is more than session Expiration
99
+ isExpired = isExpired || timeSinceRenewalMs > _sessionRenewalMs; // expired if the time since last renewal is more than renewal period
85
100
  }
86
101
 
87
102
  // renew if acquisitionSpan or renewalSpan has elapsed
@@ -106,21 +121,6 @@ export class _SessionManager {
106
121
  _setStorage(session.id, session.acquisitionDate, session.renewalDate);
107
122
  };
108
123
 
109
- //TODO: move _storageNamePrefix, _sessionExpirationMs _sessionRenewalMs back to local variables after dynamic config fix
110
- function _storageNamePrefix(): string {
111
- // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.
112
- let sessionCookiePostfix = config.sessionCookiePostfix || config.namePrefix || "";
113
- return SESSION_COOKIE_NAME + sessionCookiePostfix;
114
- }
115
-
116
- function _sessionExpirationMs(): number {
117
- return config.sessionExpirationMs || ACQUISITION_SPAN;
118
- }
119
-
120
- function _sessionRenewalMs(): number {
121
- return config.sessionRenewalMs || RENEWAL_SPAN;
122
- }
123
-
124
124
  /**
125
125
  * Use config.namePrefix + ai_session cookie data or local storage data (when the cookie is unavailable) to
126
126
  * initialize the automatic session.
@@ -128,7 +128,7 @@ export class _SessionManager {
128
128
  */
129
129
  function _initializeAutomaticSession(session: ISession, now: number): boolean {
130
130
  let isValid = false;
131
- const cookieValue = _cookieManager.get(_storageNamePrefix());
131
+ const cookieValue = _cookieManager.get(_storageNamePrefix);
132
132
  if (cookieValue && isFunction(cookieValue.split)) {
133
133
  isValid = _initializeAutomaticSessionWithData(session, cookieValue);
134
134
  } else {
@@ -136,7 +136,7 @@ export class _SessionManager {
136
136
  // This can happen if the session expired or the user actively deleted the cookie
137
137
  // We only want to recover data if the cookie is missing from expiry. We should respect the user's wishes if the cookie was deleted actively.
138
138
  // The User class handles this for us and deletes our local storage object if the persistent user cookie was removed.
139
- const storageValue = utlGetLocalStorage(_logger, _storageNamePrefix());
139
+ const storageValue = utlGetLocalStorage(_logger, _storageNamePrefix);
140
140
  if (storageValue) {
141
141
  isValid = _initializeAutomaticSessionWithData(session, storageValue);
142
142
  }
@@ -210,11 +210,11 @@ export class _SessionManager {
210
210
  let acq = session.acquisitionDate;
211
211
  session.renewalDate = nowMs;
212
212
 
213
- let renewalPeriodMs = _sessionRenewalMs();
213
+ let renewalPeriodMs = _sessionRenewalMs;
214
214
 
215
215
  // Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner
216
216
  // Expiring the cookie will cause the session to expire even if the user isn't on the page
217
- const acqTimeLeftMs = (acq +_sessionExpirationMs()) - nowMs;
217
+ const acqTimeLeftMs = (acq +_sessionExpirationMs) - nowMs;
218
218
  const cookie = [session.id, acq, nowMs];
219
219
  let maxAgeSec = 0;
220
220
 
@@ -229,7 +229,7 @@ export class _SessionManager {
229
229
  // if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie
230
230
  // A cookie with 0 expiry in the session cookie will never expire for that browser session. If the browser is closed the cookie expires.
231
231
  // Depending on the browser, another instance does not inherit this cookie, however, another tab will
232
- _cookieManager.set(_storageNamePrefix(), cookie.join("|"), _sessionExpirationMs() > 0 ? maxAgeSec : null, cookieDomain);
232
+ _cookieManager.set(_storageNamePrefix, cookie.join("|"), _sessionExpirationMs > 0 ? maxAgeSec : null, cookieDomain);
233
233
  _cookieUpdatedTimestamp = nowMs;
234
234
  }
235
235
 
@@ -237,7 +237,7 @@ export class _SessionManager {
237
237
  // Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires
238
238
  // Browsers that don't support local storage won't be able to end sessions cleanly from the client
239
239
  // The server will notice this and end the sessions itself, with loss of accurate session duration
240
- utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal].join("|"));
240
+ utlSetLocalStorage(_logger, _storageNamePrefix, [guid, acq, renewal].join("|"));
241
241
  }
242
242
  });
243
243
  }
@@ -4,8 +4,8 @@
4
4
  import dynamicProto from "@microsoft/dynamicproto-js";
5
5
  import { IUserContext, utlRemoveStorage } from "@microsoft/applicationinsights-common";
6
6
  import {
7
- IAppInsightsCore, ICookieMgr, _eInternalMessageId, _throwInternal, eLoggingSeverity, newId, onConfigChange, safeGetCookieMgr,
8
- safeGetLogger, toISOString
7
+ IAppInsightsCore, ICookieMgr, IUnloadHookContainer, _eInternalMessageId, _throwInternal, eLoggingSeverity, newId, onConfigChange,
8
+ safeGetCookieMgr, safeGetLogger, toISOString
9
9
  } from "@microsoft/applicationinsights-core-js";
10
10
  import { objDefineProp } from "@nevware21/ts-utils";
11
11
  import { IPropertiesConfig } from "../Interfaces/IPropertiesConfig";
@@ -69,7 +69,7 @@ export class User implements IUserContext {
69
69
  */
70
70
  public isUserCookieSet = false;
71
71
 
72
- constructor(config: IPropertiesConfig, core: IAppInsightsCore) {
72
+ constructor(config: IPropertiesConfig, core: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer) {
73
73
  let _logger = safeGetLogger(core);
74
74
  let _cookieManager: ICookieMgr = safeGetCookieMgr(core);
75
75
  let _storageNamePrefix: string;
@@ -82,7 +82,7 @@ export class User implements IUserContext {
82
82
  get: () => config
83
83
  });
84
84
 
85
- onConfigChange(config, () => {
85
+ let unloadHook = onConfigChange(config, () => {
86
86
 
87
87
  const userCookiePostfix = config.userCookiePostfix || "";
88
88
  _storageNamePrefix = User.userCookieName + userCookiePostfix;
@@ -131,6 +131,8 @@ export class User implements IUserContext {
131
131
  }
132
132
  });
133
133
 
134
+ unloadHookContainer && unloadHookContainer.add(unloadHook);
135
+
134
136
  function _generateNewId() {
135
137
  let theConfig = (config || {}) as IPropertiesConfig;
136
138
  let getNewId = theConfig.getNewId || newId;
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  export interface IPropertiesConfig {
5
- readonly instrumentationKey: string;
6
5
  readonly accountId: string;
7
6
  readonly sessionRenewalMs: number;
8
7
  readonly samplingPercentage: number;
@@ -21,7 +21,6 @@ let undefString: string;
21
21
  const nullValue: any = null;
22
22
 
23
23
  const _defaultConfig: IConfigDefaults<IPropertiesConfig> = objDeepFreeze({
24
- instrumentationKey: undefString,
25
24
  accountId: nullValue,
26
25
  sessionRenewalMs: 30 * 60 * 1000,
27
26
  samplingPercentage: 100,
@@ -68,14 +67,6 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr
68
67
  _self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
69
68
  _base.initialize(config, core, extensions, pluginChain);
70
69
  _populateDefaults(config);
71
- _previousTraceCtx = core.getTraceCtx(false);
72
- _context = new TelemetryContext(core, _extensionConfig, _previousTraceCtx);
73
- _distributedTraceCtx = createDistributedTraceContextFromTrace(_self.context.telemetryTrace, _previousTraceCtx);
74
- core.setTraceCtx(_distributedTraceCtx);
75
- _self.context.appId = () => {
76
- let breezeChannel = core.getPlugin<IPlugin>(BreezeChannelIdentifier);
77
- return breezeChannel ? breezeChannel.plugin["_appId"] : null;
78
- };
79
70
  };
80
71
 
81
72
  /**
@@ -147,6 +138,16 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr
147
138
  // Test hook to allow accessing the internal values -- explicitly not defined as an available property on the class
148
139
  _self["_extConfig"] = _extensionConfig;
149
140
  }));
141
+
142
+ // This is outside of the onConfigChange as we don't want to update (replace) these values whenever a referenced config item changes
143
+ _previousTraceCtx = core.getTraceCtx(false);
144
+ _context = new TelemetryContext(core, _extensionConfig, _previousTraceCtx, _self._unloadHooks);
145
+ _distributedTraceCtx = createDistributedTraceContextFromTrace(_self.context.telemetryTrace, _previousTraceCtx);
146
+ core.setTraceCtx(_distributedTraceCtx);
147
+ _self.context.appId = () => {
148
+ let breezeChannel = core.getPlugin<IPlugin>(BreezeChannelIdentifier);
149
+ return breezeChannel ? breezeChannel.plugin["_appId"] : null;
150
+ };
150
151
  }
151
152
 
152
153
  function _processTelemetryInternal(evt: ITelemetryItem, itemCtx: IProcessTelemetryContext) {
@@ -9,8 +9,8 @@ import {
9
9
  PageView
10
10
  } from "@microsoft/applicationinsights-common";
11
11
  import {
12
- IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, _InternalLogMessage, getSetValue, hasWindow,
13
- isNullOrUndefined, isString, objKeys, setValue
12
+ IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer, _InternalLogMessage,
13
+ getSetValue, hasWindow, isNullOrUndefined, isString, objKeys, setValue
14
14
  } from "@microsoft/applicationinsights-core-js";
15
15
  import { Application } from "./Context/Application";
16
16
  import { Device } from "./Context/Device";
@@ -50,19 +50,19 @@ export class TelemetryContext implements IPropTelemetryContext {
50
50
  public appId: () => string;
51
51
  public getSessionId: () => string;
52
52
 
53
- constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext) {
53
+ constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext, unloadHookContainer?: IUnloadHookContainer) {
54
54
  let logger = core.logger
55
55
 
56
56
  dynamicProto(TelemetryContext, this, (_self) => {
57
57
  _self.appId = _nullResult;
58
58
  _self.getSessionId = _nullResult;
59
59
  _self.application = new Application();
60
- _self.internal = new Internal(defaultConfig);
60
+ _self.internal = new Internal(defaultConfig, unloadHookContainer);
61
61
  if (hasWindow()) {
62
- _self.sessionManager = new _SessionManager(defaultConfig, core);
62
+ _self.sessionManager = new _SessionManager(defaultConfig, core, unloadHookContainer);
63
63
  _self.device = new Device();
64
64
  _self.location = new Location();
65
- _self.user = new User(defaultConfig, core);
65
+ _self.user = new User(defaultConfig, core, unloadHookContainer);
66
66
 
67
67
  let traceId: string;
68
68
  let parentId: string;
@@ -10,12 +10,12 @@
10
10
  // Note: DON'T Export these const from the package as we are still targeting IE this will export a mutable variables that someone could change
11
11
  // ###########################################################################################################################################
12
12
 
13
- export const _DYN_GET_TRACE_CTX = "getTraceCtx"; // Count: 3
14
- export const _DYN_TELEMETRY_TRACE = "telemetryTrace"; // Count: 3
15
13
  export const _DYN_SESSION_MANAGER = "sessionManager"; // Count: 3
16
14
  export const _DYN_UPDATE = "update"; // Count: 4
17
15
  export const _DYN_IS_USER_COOKIE_SET = "isUserCookieSet"; // Count: 4
18
16
  export const _DYN_IS_NEW_USER = "isNewUser"; // Count: 4
17
+ export const _DYN_GET_TRACE_CTX = "getTraceCtx"; // Count: 3
18
+ export const _DYN_TELEMETRY_TRACE = "telemetryTrace"; // Count: 3
19
19
  export const _DYN_APPLY_SESSION_CONTEX0 = "applySessionContext"; // Count: 2
20
20
  export const _DYN_APPLY_APPLICATION_CO1 = "applyApplicationContext"; // Count: 2
21
21
  export const _DYN_APPLY_DEVICE_CONTEXT = "applyDeviceContext"; // Count: 2
@@ -1,4 +1,5 @@
1
1
  import { IInternal } from "@microsoft/applicationinsights-common";
2
+ import { IUnloadHookContainer } from "@microsoft/applicationinsights-core-js";
2
3
  import { IPropertiesConfig } from "../Interfaces/IPropertiesConfig";
3
4
  export declare class Internal implements IInternal {
4
5
  /**
@@ -25,5 +26,5 @@ export declare class Internal implements IInternal {
25
26
  /**
26
27
  * Constructs a new instance of the internal telemetry data class.
27
28
  */
28
- constructor(config: IPropertiesConfig);
29
+ constructor(config: IPropertiesConfig, unloadHookContainer?: IUnloadHookContainer);
29
30
  }
@@ -1,5 +1,5 @@
1
1
  import { ISession } from "@microsoft/applicationinsights-common";
2
- import { IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
2
+ import { IAppInsightsCore, IUnloadHookContainer } from "@microsoft/applicationinsights-core-js";
3
3
  export interface ISessionConfig {
4
4
  readonly sessionRenewalMs?: number;
5
5
  readonly sessionExpirationMs?: number;
@@ -31,7 +31,7 @@ export declare class Session implements ISession {
31
31
  }
32
32
  export declare class _SessionManager {
33
33
  automaticSession: Session;
34
- constructor(config: ISessionConfig, core?: IAppInsightsCore);
34
+ constructor(config: ISessionConfig, core?: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer);
35
35
  update(): void;
36
36
  /**
37
37
  * Record the current state of the automatic session and store it in our cookie string format
@@ -1,5 +1,5 @@
1
1
  import { IUserContext } from "@microsoft/applicationinsights-common";
2
- import { IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
2
+ import { IAppInsightsCore, IUnloadHookContainer } from "@microsoft/applicationinsights-core-js";
3
3
  import { IPropertiesConfig } from "../Interfaces/IPropertiesConfig";
4
4
  export declare class User implements IUserContext {
5
5
  static cookieSeparator: string;
@@ -37,7 +37,7 @@ export declare class User implements IUserContext {
37
37
  * A flag indicating whether the user cookie has been set
38
38
  */
39
39
  isUserCookieSet: boolean;
40
- constructor(config: IPropertiesConfig, core: IAppInsightsCore);
40
+ constructor(config: IPropertiesConfig, core: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer);
41
41
  /**
42
42
  * Sets the authenticated user id and the account id in this session.
43
43
  *
@@ -1,5 +1,4 @@
1
1
  export interface IPropertiesConfig {
2
- readonly instrumentationKey: string;
3
2
  readonly accountId: string;
4
3
  readonly sessionRenewalMs: number;
5
4
  readonly samplingPercentage: number;
@@ -3,7 +3,7 @@
3
3
  * @copyright Microsoft 2018
4
4
  */
5
5
  import { IApplication, IDevice, IInternal, ILocation, IOperatingSystem, ISession, ITelemetryTrace, IUserContext, IWeb } from "@microsoft/applicationinsights-common";
6
- import { IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem } from "@microsoft/applicationinsights-core-js";
6
+ import { IAppInsightsCore, IDistributedTraceContext, IProcessTelemetryContext, ITelemetryItem, IUnloadHookContainer } from "@microsoft/applicationinsights-core-js";
7
7
  import { _SessionManager } from "./Context/Session";
8
8
  import { IPropTelemetryContext } from "./Interfaces/IPropTelemetryContext";
9
9
  import { IPropertiesConfig } from "./Interfaces/IPropertiesConfig";
@@ -20,7 +20,7 @@ export declare class TelemetryContext implements IPropTelemetryContext {
20
20
  web: IWeb;
21
21
  appId: () => string;
22
22
  getSessionId: () => string;
23
- constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext);
23
+ constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext, unloadHookContainer?: IUnloadHookContainer);
24
24
  applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
25
25
  applyOperatingSystemContxt(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
26
26
  applyApplicationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
@@ -1,9 +1,9 @@
1
- export declare const _DYN_GET_TRACE_CTX = "getTraceCtx";
2
- export declare const _DYN_TELEMETRY_TRACE = "telemetryTrace";
3
1
  export declare const _DYN_SESSION_MANAGER = "sessionManager";
4
2
  export declare const _DYN_UPDATE = "update";
5
3
  export declare const _DYN_IS_USER_COOKIE_SET = "isUserCookieSet";
6
4
  export declare const _DYN_IS_NEW_USER = "isNewUser";
5
+ export declare const _DYN_GET_TRACE_CTX = "getTraceCtx";
6
+ export declare const _DYN_TELEMETRY_TRACE = "telemetryTrace";
7
7
  export declare const _DYN_APPLY_SESSION_CONTEX0 = "applySessionContext";
8
8
  export declare const _DYN_APPLY_APPLICATION_CO1 = "applyApplicationContext";
9
9
  export declare const _DYN_APPLY_DEVICE_CONTEXT = "applyDeviceContext";