@microsoft/applicationinsights-properties-js 3.0.0-beta.2303-10 → 3.0.0-beta.2304-07

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 (95) hide show
  1. package/browser/es5/ai.props.3.0.0-beta.2304-07.cjs.js +3990 -0
  2. package/browser/es5/ai.props.3.0.0-beta.2304-07.cjs.js.map +1 -0
  3. package/browser/es5/ai.props.3.0.0-beta.2304-07.cjs.min.js +6 -0
  4. package/browser/es5/ai.props.3.0.0-beta.2304-07.cjs.min.js.map +1 -0
  5. package/browser/es5/ai.props.3.0.0-beta.2304-07.gbl.js +3994 -0
  6. package/browser/es5/ai.props.3.0.0-beta.2304-07.gbl.js.map +1 -0
  7. package/browser/es5/ai.props.3.0.0-beta.2304-07.gbl.min.js +6 -0
  8. package/browser/es5/ai.props.3.0.0-beta.2304-07.gbl.min.js.map +1 -0
  9. package/browser/es5/ai.props.3.0.0-beta.2304-07.integrity.json +66 -0
  10. package/browser/es5/ai.props.3.0.0-beta.2304-07.js +3996 -0
  11. package/browser/es5/ai.props.3.0.0-beta.2304-07.js.map +1 -0
  12. package/browser/es5/ai.props.3.0.0-beta.2304-07.min.js +6 -0
  13. package/browser/es5/ai.props.3.0.0-beta.2304-07.min.js.map +1 -0
  14. package/browser/es5/ai.props.3.cjs.js +3990 -0
  15. package/browser/es5/ai.props.3.cjs.js.map +1 -0
  16. package/browser/es5/ai.props.3.cjs.min.js +6 -0
  17. package/browser/es5/ai.props.3.cjs.min.js.map +1 -0
  18. package/browser/es5/ai.props.3.gbl.js +3994 -0
  19. package/browser/es5/ai.props.3.gbl.js.map +1 -0
  20. package/browser/es5/ai.props.3.gbl.min.js +6 -0
  21. package/browser/es5/ai.props.3.gbl.min.js.map +1 -0
  22. package/{dist/applicationinsights-properties-js.js → browser/es5/ai.props.3.js} +886 -851
  23. package/browser/es5/ai.props.3.js.map +1 -0
  24. package/browser/es5/ai.props.3.min.js +6 -0
  25. package/browser/es5/ai.props.3.min.js.map +1 -0
  26. package/{browser → dist/es5}/applicationinsights-properties-js.js +885 -850
  27. package/dist/es5/applicationinsights-properties-js.js.map +1 -0
  28. package/dist/es5/applicationinsights-properties-js.min.js +6 -0
  29. package/dist/es5/applicationinsights-properties-js.min.js.map +1 -0
  30. package/{dist-esm → dist-es5}/Context/Application.js +1 -1
  31. package/{dist-esm → dist-es5}/Context/Device.js +1 -1
  32. package/{dist-esm → dist-es5}/Context/Internal.js +1 -1
  33. package/{dist-esm → dist-es5}/Context/Location.js +1 -1
  34. package/{dist-esm → dist-es5}/Context/Session.js +1 -1
  35. package/{dist-esm → dist-es5}/Context/TelemetryTrace.js +1 -1
  36. package/{dist-esm → dist-es5}/Context/User.js +1 -1
  37. package/{dist-esm → dist-es5}/Interfaces/IPropTelemetryContext.js +1 -1
  38. package/{dist-esm → dist-es5}/Interfaces/IPropertiesConfig.js +1 -1
  39. package/{dist-esm → dist-es5}/PropertiesPlugin.js +1 -1
  40. package/{dist-esm → dist-es5}/TelemetryContext.js +1 -1
  41. package/{dist-esm → dist-es5}/__DynamicConstants.js +1 -1
  42. package/{dist-esm → dist-es5}/applicationinsights-properties-js.js +1 -1
  43. package/package.json +17 -16
  44. package/tsconfig.json +4 -3
  45. package/types/applicationinsights-properties-js.d.ts +161 -6
  46. package/{dist/applicationinsights-properties-js.d.ts → types/applicationinsights-properties-js.namespaced.d.ts} +1 -1
  47. package/browser/applicationinsights-properties-js.integrity.json +0 -26
  48. package/browser/applicationinsights-properties-js.js.map +0 -1
  49. package/browser/applicationinsights-properties-js.min.js +0 -6
  50. package/browser/applicationinsights-properties-js.min.js.map +0 -1
  51. package/dist/applicationinsights-properties-js.api.json +0 -3120
  52. package/dist/applicationinsights-properties-js.api.md +0 -173
  53. package/dist/applicationinsights-properties-js.js.map +0 -1
  54. package/dist/applicationinsights-properties-js.min.js +0 -6
  55. package/dist/applicationinsights-properties-js.min.js.map +0 -1
  56. package/dist/applicationinsights-properties-js.rollup.d.ts +0 -162
  57. package/src/Context/Application.ts +0 -16
  58. package/src/Context/Device.ts +0 -49
  59. package/src/Context/Internal.ts +0 -49
  60. package/src/Context/Location.ts +0 -12
  61. package/src/Context/Session.ts +0 -257
  62. package/src/Context/TelemetryTrace.ts +0 -26
  63. package/src/Context/User.ts +0 -233
  64. package/src/Interfaces/IPropTelemetryContext.ts +0 -21
  65. package/src/Interfaces/IPropertiesConfig.ts +0 -19
  66. package/src/PropertiesPlugin.ts +0 -183
  67. package/src/TelemetryContext.ts +0 -233
  68. package/src/__DynamicConstants.ts +0 -41
  69. package/src/applicationinsights-properties-js.ts +0 -10
  70. package/types/Context/Application.d.ts +0 -11
  71. package/types/Context/Device.d.ts +0 -31
  72. package/types/Context/Internal.d.ts +0 -30
  73. package/types/Context/Location.d.ts +0 -7
  74. package/types/Context/Session.d.ts +0 -42
  75. package/types/Context/TelemetryTrace.d.ts +0 -10
  76. package/types/Context/User.d.ts +0 -59
  77. package/types/Interfaces/IPropTelemetryContext.d.ts +0 -16
  78. package/types/Interfaces/IPropertiesConfig.d.ts +0 -16
  79. package/types/PropertiesPlugin.d.ts +0 -19
  80. package/types/TelemetryContext.d.ts +0 -34
  81. package/types/__DynamicConstants.d.ts +0 -29
  82. package/types/tsdoc-metadata.json +0 -11
  83. /package/{dist-esm → dist-es5}/Context/Application.js.map +0 -0
  84. /package/{dist-esm → dist-es5}/Context/Device.js.map +0 -0
  85. /package/{dist-esm → dist-es5}/Context/Internal.js.map +0 -0
  86. /package/{dist-esm → dist-es5}/Context/Location.js.map +0 -0
  87. /package/{dist-esm → dist-es5}/Context/Session.js.map +0 -0
  88. /package/{dist-esm → dist-es5}/Context/TelemetryTrace.js.map +0 -0
  89. /package/{dist-esm → dist-es5}/Context/User.js.map +0 -0
  90. /package/{dist-esm → dist-es5}/Interfaces/IPropTelemetryContext.js.map +0 -0
  91. /package/{dist-esm → dist-es5}/Interfaces/IPropertiesConfig.js.map +0 -0
  92. /package/{dist-esm → dist-es5}/PropertiesPlugin.js.map +0 -0
  93. /package/{dist-esm → dist-es5}/TelemetryContext.js.map +0 -0
  94. /package/{dist-esm → dist-es5}/__DynamicConstants.js.map +0 -0
  95. /package/{dist-esm → dist-es5}/applicationinsights-properties-js.js.map +0 -0
@@ -1,162 +0,0 @@
1
- /*
2
- * Microsoft Application Insights properties plugin, 3.0.0-beta.2303-10
3
- * Copyright (c) Microsoft and contributors. All rights reserved.
4
- *
5
- * Microsoft Application Insights Team
6
- * https://github.com/microsoft/ApplicationInsights-JS#readme
7
- *
8
- * ---------------------------------------------------------------------------
9
- * This is a single combined (rollup) declaration file for the package,
10
- * use this version if your build environment doesn't support the using the
11
- * individual *.d.ts files or default namespace wrapped version.
12
- * - Namespaced version: applicationinsights-properties-js.d.ts
13
- * ---------------------------------------------------------------------------
14
- */
15
-
16
- import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
17
- import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
18
- import { IApplication } from '@microsoft/applicationinsights-common';
19
- import { IConfig } from '@microsoft/applicationinsights-common';
20
- import { IConfiguration } from '@microsoft/applicationinsights-core-js';
21
- import { IDevice } from '@microsoft/applicationinsights-common';
22
- import { IDiagnosticLogger } from '@microsoft/applicationinsights-core-js';
23
- import { IDistributedTraceContext } from '@microsoft/applicationinsights-core-js';
24
- import { IInternal } from '@microsoft/applicationinsights-common';
25
- import { ILocation } from '@microsoft/applicationinsights-common';
26
- import { IOperatingSystem } from '@microsoft/applicationinsights-common';
27
- import { IPlugin } from '@microsoft/applicationinsights-core-js';
28
- import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
29
- import { IPropertiesPlugin } from '@microsoft/applicationinsights-common';
30
- import { ISession } from '@microsoft/applicationinsights-common';
31
- import { ITelemetryContext } from '@microsoft/applicationinsights-common';
32
- import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
33
- import { ITelemetryPluginChain } from '@microsoft/applicationinsights-core-js';
34
- import { ITelemetryTrace } from '@microsoft/applicationinsights-common';
35
- import { ITraceState } from '@microsoft/applicationinsights-common';
36
- import { IUnloadHookContainer } from '@microsoft/applicationinsights-core-js';
37
- import { IUserContext } from '@microsoft/applicationinsights-common';
38
- import { IWeb } from '@microsoft/applicationinsights-common';
39
-
40
- declare interface IPropertiesConfig {
41
- readonly accountId: string;
42
- readonly sessionRenewalMs: number;
43
- readonly samplingPercentage: number;
44
- readonly sessionExpirationMs: number;
45
- readonly cookieDomain: string;
46
- readonly sdkExtension: string;
47
- readonly isBrowserLinkTrackingEnabled: boolean;
48
- readonly appId: string;
49
- readonly getSessionId: string;
50
- readonly namePrefix: string;
51
- readonly sessionCookiePostfix: string;
52
- readonly userCookiePostfix: string;
53
- readonly idLength: number;
54
- readonly getNewId: (idLength?: number) => string;
55
- }
56
-
57
- export declare interface IPropTelemetryContext extends ITelemetryContext {
58
- readonly sessionManager: SessionManager;
59
- applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
60
- applyOperatingSystemContxt(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
61
- applyApplicationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
62
- applyDeviceContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
63
- applyInternalContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
64
- applyLocationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
65
- applyOperationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
66
- applyWebContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
67
- applyUserContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
68
- cleanUp(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
69
- }
70
-
71
- export declare interface ISessionConfig {
72
- readonly sessionRenewalMs?: number;
73
- readonly sessionExpirationMs?: number;
74
- readonly namePrefix?: string;
75
- readonly sessionCookiePostfix?: string;
76
- readonly idLength?: number;
77
- readonly getNewId?: (idLength?: number) => string;
78
- /**
79
- * @deprecated Avoid using this value to override the cookie manager cookie domain.
80
- */
81
- cookieDomain?: string;
82
- }
83
-
84
- export declare class PropertiesPlugin extends BaseTelemetryPlugin implements IPropertiesPlugin {
85
- context: IPropTelemetryContext;
86
- priority: number;
87
- identifier: string;
88
- constructor();
89
- initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
90
- /**
91
- * Add Part A fields to the event
92
- * @param event - The event that needs to be processed
93
- */
94
- processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
95
- }
96
-
97
- export declare class Session implements ISession {
98
- /**
99
- * The session ID.
100
- */
101
- id?: string;
102
- /**
103
- * The date at which this guid was generated.
104
- * Per the spec the ID will be regenerated if more than acquisitionSpan milliseconds elapsed from this time.
105
- */
106
- acquisitionDate?: number;
107
- /**
108
- * The date at which this session ID was last reported.
109
- * This value should be updated whenever telemetry is sent using this ID.
110
- * Per the spec the ID will be regenerated if more than renewalSpan milliseconds elapse from this time with no activity.
111
- */
112
- renewalDate?: number;
113
- }
114
-
115
- export declare class SessionManager {
116
- automaticSession: Session;
117
- constructor(config: ISessionConfig, core?: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer);
118
- update(): void;
119
- /**
120
- * Record the current state of the automatic session and store it in our cookie string format
121
- * into the browser's local storage. This is used to restore the session data when the cookie
122
- * expires.
123
- */
124
- backup(): void;
125
- }
126
-
127
- export declare class TelemetryContext implements IPropTelemetryContext {
128
- application: IApplication;
129
- device: IDevice;
130
- location: ILocation;
131
- telemetryTrace: ITelemetryTrace;
132
- user: IUserContext;
133
- internal: IInternal;
134
- session: ISession;
135
- sessionManager: SessionManager;
136
- os: IOperatingSystem;
137
- web: IWeb;
138
- appId: () => string;
139
- getSessionId: () => string;
140
- constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext, unloadHookContainer?: IUnloadHookContainer);
141
- applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
142
- applyOperatingSystemContxt(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
143
- applyApplicationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
144
- applyDeviceContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
145
- applyInternalContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
146
- applyLocationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
147
- applyOperationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
148
- applyWebContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
149
- applyUserContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
150
- cleanUp(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
151
- }
152
-
153
- export declare class TelemetryTrace implements ITelemetryTrace {
154
- traceID: string;
155
- parentID: string;
156
- traceState: ITraceState;
157
- traceFlags: number;
158
- name: string;
159
- constructor(id?: string, parentId?: string, name?: string, logger?: IDiagnosticLogger);
160
- }
161
-
162
- export { }
@@ -1,16 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import { IApplication } from "@microsoft/applicationinsights-common";
5
-
6
- export class Application implements IApplication {
7
- /**
8
- * The application version.
9
- */
10
- public ver: string;
11
-
12
- /**
13
- * The application build version.
14
- */
15
- public build: string;
16
- }
@@ -1,49 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import { IDevice } from "@microsoft/applicationinsights-common";
5
-
6
- export class Device implements IDevice {
7
-
8
- /**
9
- * The type for the current device.
10
- */
11
- public deviceClass: string;
12
-
13
- /**
14
- * A device unique ID.
15
- */
16
- public id: string;
17
-
18
- /**
19
- * The application screen resolution.
20
- */
21
- resolution: string;
22
-
23
- /**
24
- * The device model for the current device.
25
- */
26
- public model: string;
27
-
28
- /**
29
- * Device identifier known at instrumentation time
30
- */
31
- public localId: string;
32
-
33
- /**
34
- * Device identifier known at instrumentation time
35
- */
36
- public ip: string;
37
-
38
- /**
39
- * Constructs a new instance of the Device class
40
- */
41
- constructor() {
42
- // don't attempt to fingerprint browsers
43
- this.id = "browser";
44
-
45
- // Device type is a dimension in our data platform
46
- // Setting it to 'Browser' allows to separate client and server dependencies/exceptions
47
- this.deviceClass = "Browser";
48
- }
49
- }
@@ -1,49 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import { IInternal } from "@microsoft/applicationinsights-common";
5
- import { IUnloadHookContainer, onConfigChange } from "@microsoft/applicationinsights-core-js";
6
- import { IPropertiesConfig } from "../Interfaces/IPropertiesConfig";
7
-
8
- const Version = "2.8.5";
9
-
10
- export class Internal implements IInternal {
11
-
12
- /**
13
- * The SDK version used to create this telemetry item.
14
- */
15
- public sdkVersion: string;
16
-
17
- /**
18
- * The SDK agent version.
19
- */
20
- public agentVersion: string;
21
-
22
- /**
23
- * The Snippet version used to initialize the sdk instance, this will contain either
24
- * undefined/null - Snippet not used
25
- * '-' - Version and legacy mode not determined
26
- * # - Version # of the snippet
27
- * #.l - Version # in legacy mode
28
- * .l - No defined version, but used legacy mode initialization
29
- */
30
- public snippetVer: string;
31
-
32
- /**
33
- * Identifies the source of the sdk script
34
- */
35
- public sdkSrc: string;
36
-
37
- /**
38
- * Constructs a new instance of the internal telemetry data class.
39
- */
40
- constructor(config: IPropertiesConfig, unloadHookContainer?: IUnloadHookContainer) {
41
-
42
- let unloadHook = onConfigChange((config), () => {
43
- let prefix = config.sdkExtension;
44
- this.sdkVersion = (prefix ? prefix + "_" : "") + "javascript:" + Version;
45
- });
46
-
47
- unloadHookContainer && unloadHookContainer.add(unloadHook);
48
- }
49
- }
@@ -1,12 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import { ILocation } from "@microsoft/applicationinsights-common";
5
-
6
- export class Location implements ILocation {
7
-
8
- /**
9
- * Client IP address for reverse lookup
10
- */
11
- public ip: string;
12
- }
@@ -1,257 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import dynamicProto from "@microsoft/dynamicproto-js";
5
- import { ISession, utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "@microsoft/applicationinsights-common";
6
- import {
7
- IAppInsightsCore, ICookieMgr, IDiagnosticLogger, IUnloadHookContainer, _eInternalMessageId, _throwInternal, dateNow, dumpObj,
8
- eLoggingSeverity, getExceptionName, isFunction, newId, onConfigChange, safeGetCookieMgr, safeGetLogger
9
- } from "@microsoft/applicationinsights-core-js";
10
-
11
- const SESSION_COOKIE_NAME = "ai_session";
12
- const ACQUISITION_SPAN = 86400000; // 24 hours in ms
13
- const RENEWAL_SPAN = 1800000; // 30 minutes in ms
14
- const COOKIE_UPDATE_INTERVAL = 60000 // 1 minute in ms
15
-
16
- export interface ISessionConfig {
17
- readonly sessionRenewalMs?: number;
18
- readonly sessionExpirationMs?: number;
19
- readonly namePrefix?: string;
20
- readonly sessionCookiePostfix?: string;
21
- readonly idLength?: number;
22
- readonly getNewId?: (idLength?: number) => string;
23
-
24
- /**
25
- * @deprecated Avoid using this value to override the cookie manager cookie domain.
26
- */
27
- cookieDomain?: string;
28
- }
29
-
30
- export class Session implements ISession {
31
- /**
32
- * The session ID.
33
- */
34
- public id?: string;
35
-
36
- /**
37
- * The date at which this guid was generated.
38
- * Per the spec the ID will be regenerated if more than acquisitionSpan milliseconds elapsed from this time.
39
- */
40
- public acquisitionDate?: number;
41
-
42
- /**
43
- * The date at which this session ID was last reported.
44
- * This value should be updated whenever telemetry is sent using this ID.
45
- * Per the spec the ID will be regenerated if more than renewalSpan milliseconds elapse from this time with no activity.
46
- */
47
- public renewalDate?: number;
48
- }
49
-
50
- export class _SessionManager {
51
-
52
- public automaticSession: Session;
53
-
54
- constructor(config: ISessionConfig, core?: IAppInsightsCore, unloadHookContainer?: IUnloadHookContainer) {
55
- let self = this;
56
- let _storageNamePrefix: string;
57
- let _cookieUpdatedTimestamp: number;
58
- let _logger: IDiagnosticLogger = safeGetLogger(core);
59
- let _cookieManager: ICookieMgr = safeGetCookieMgr(core);
60
- let _sessionExpirationMs: number;
61
- let _sessionRenewalMs: number;
62
-
63
- dynamicProto(_SessionManager, self, (_self) => {
64
-
65
- if (!config) {
66
- config = ({} as any);
67
- }
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
-
81
- _self.automaticSession = new Session();
82
-
83
- _self.update = () => {
84
- // Always using Date getTime() as there is a bug in older IE instances that causes the performance timings to have the hi-bit set eg 0x800000000 causing
85
- // the number to be incorrect.
86
- const nowMs = dateNow();
87
-
88
- let isExpired = false;
89
- const session = _self.automaticSession;
90
- if (!session.id) {
91
- isExpired = !_initializeAutomaticSession(session, nowMs);
92
- }
93
-
94
- if (!isExpired && _sessionExpirationMs > 0) {
95
- const timeSinceAcqMs = nowMs - session.acquisitionDate;
96
- const timeSinceRenewalMs = nowMs - session.renewalDate;
97
- isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future
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
100
- }
101
-
102
- // renew if acquisitionSpan or renewalSpan has elapsed
103
- if (isExpired) {
104
- // update automaticSession so session state has correct id
105
- _renew(nowMs);
106
- } else {
107
- // do not update the cookie more often than cookieUpdateInterval
108
- if (!_cookieUpdatedTimestamp || nowMs - _cookieUpdatedTimestamp > COOKIE_UPDATE_INTERVAL) {
109
- _setCookie(session, nowMs);
110
- }
111
- }
112
- };
113
-
114
- /**
115
- * Record the current state of the automatic session and store it in our cookie string format
116
- * into the browser's local storage. This is used to restore the session data when the cookie
117
- * expires.
118
- */
119
- _self.backup = () => {
120
- const session = _self.automaticSession;
121
- _setStorage(session.id, session.acquisitionDate, session.renewalDate);
122
- };
123
-
124
- /**
125
- * Use config.namePrefix + ai_session cookie data or local storage data (when the cookie is unavailable) to
126
- * initialize the automatic session.
127
- * @returns true if values set otherwise false
128
- */
129
- function _initializeAutomaticSession(session: ISession, now: number): boolean {
130
- let isValid = false;
131
- const cookieValue = _cookieManager.get(_storageNamePrefix);
132
- if (cookieValue && isFunction(cookieValue.split)) {
133
- isValid = _initializeAutomaticSessionWithData(session, cookieValue);
134
- } else {
135
- // There's no cookie, but we might have session data in local storage
136
- // This can happen if the session expired or the user actively deleted the cookie
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
- // 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);
140
- if (storageValue) {
141
- isValid = _initializeAutomaticSessionWithData(session, storageValue);
142
- }
143
- }
144
-
145
- return isValid || !!session.id;
146
- }
147
-
148
- /**
149
- * Extract id, acquisitionDate, and renewalDate from an ai_session payload string and
150
- * use this data to initialize automaticSession.
151
- *
152
- * @param sessionData - The string stored in an ai_session cookie or local storage backup
153
- * @returns true if values set otherwise false
154
- */
155
- function _initializeAutomaticSessionWithData(session: ISession, sessionData: string) {
156
- let isValid = false;
157
- const sessionReset = ", session will be reset";
158
- const tokens = sessionData.split("|");
159
-
160
- if (tokens.length >= 2) {
161
- try {
162
- const acqMs = +tokens[1] || 0;
163
- const renewalMs = +tokens[2] || 0;
164
- if (isNaN(acqMs) || acqMs <= 0) {
165
- _throwInternal(_logger,
166
- eLoggingSeverity.WARNING,
167
- _eInternalMessageId.SessionRenewalDateIsZero,
168
- "AI session acquisition date is 0" + sessionReset);
169
- } else if (isNaN(renewalMs) || renewalMs <= 0) {
170
- _throwInternal(_logger,
171
- eLoggingSeverity.WARNING,
172
- _eInternalMessageId.SessionRenewalDateIsZero,
173
- "AI session renewal date is 0" + sessionReset);
174
- } else if (tokens[0]) {
175
- // Everything looks valid so set the values
176
- session.id = tokens[0];
177
- session.acquisitionDate = acqMs;
178
- session.renewalDate = renewalMs;
179
- isValid = true;
180
- }
181
- } catch (e) {
182
- _throwInternal(_logger,
183
- eLoggingSeverity.CRITICAL,
184
- _eInternalMessageId.ErrorParsingAISessionCookie,
185
- "Error parsing ai_session value [" + (sessionData || "") + "]" + sessionReset + " - " + getExceptionName(e),
186
- { exception: dumpObj(e) });
187
- }
188
- }
189
-
190
- return isValid;
191
- }
192
-
193
- function _renew(nowMs: number) {
194
- let getNewId = config.getNewId || newId;
195
- _self.automaticSession.id = getNewId(config.idLength || 22);
196
- _self.automaticSession.acquisitionDate = nowMs;
197
-
198
- _setCookie(_self.automaticSession, nowMs);
199
-
200
- // If this browser does not support local storage, fire an internal log to keep track of it at this point
201
- if (!utlCanUseLocalStorage()) {
202
- _throwInternal(_logger,
203
- eLoggingSeverity.WARNING,
204
- _eInternalMessageId.BrowserDoesNotSupportLocalStorage,
205
- "Browser does not support local storage. Session durations will be inaccurate.");
206
- }
207
- }
208
-
209
- function _setCookie(session: ISession, nowMs: number) {
210
- let acq = session.acquisitionDate;
211
- session.renewalDate = nowMs;
212
-
213
- let renewalPeriodMs = _sessionRenewalMs;
214
-
215
- // Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner
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;
218
- const cookie = [session.id, acq, nowMs];
219
- let maxAgeSec = 0;
220
-
221
- if (acqTimeLeftMs < renewalPeriodMs) {
222
- maxAgeSec = acqTimeLeftMs / 1000;
223
- } else {
224
- maxAgeSec = renewalPeriodMs / 1000;
225
- }
226
-
227
- const cookieDomain = config.cookieDomain || null;
228
-
229
- // if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie
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
- // 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);
233
- _cookieUpdatedTimestamp = nowMs;
234
- }
235
-
236
- function _setStorage(guid: string, acq: number, renewal: number) {
237
- // Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires
238
- // Browsers that don't support local storage won't be able to end sessions cleanly from the client
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("|"));
241
- }
242
- });
243
- }
244
-
245
- public update() {
246
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
247
- }
248
-
249
- /**
250
- * Record the current state of the automatic session and store it in our cookie string format
251
- * into the browser's local storage. This is used to restore the session data when the cookie
252
- * expires.
253
- */
254
- public backup() {
255
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
256
- }
257
- }
@@ -1,26 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
-
4
- import { ITelemetryTrace, ITraceState, dataSanitizeString } from "@microsoft/applicationinsights-common";
5
- import { IDiagnosticLogger, generateW3CId, getLocation } from "@microsoft/applicationinsights-core-js";
6
-
7
- export class TelemetryTrace implements ITelemetryTrace {
8
-
9
- public traceID: string;
10
- public parentID: string;
11
- public traceState: ITraceState;
12
- public traceFlags: number;
13
- public name: string;
14
-
15
- constructor(id?: string, parentId?: string, name?: string, logger?: IDiagnosticLogger) {
16
- const _self = this;
17
- _self.traceID = id || generateW3CId();
18
- _self.parentID = parentId;
19
- let location = getLocation();
20
- if (!name && location && location.pathname) {
21
- name = location.pathname;
22
- }
23
-
24
- _self.name = dataSanitizeString(logger, name);
25
- }
26
- }