@microsoft/applicationinsights-core-js 3.0.0-beta.2303-03 → 3.0.0-beta.2303-05

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 (132) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +2 -2
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +113 -206
  7. package/dist/applicationinsights-core-js.api.md +11 -14
  8. package/dist/applicationinsights-core-js.d.ts +15 -13
  9. package/dist/applicationinsights-core-js.js +2 -2
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +15 -13
  14. package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
  15. package/dist-esm/Config/ConfigDefaults.js +1 -1
  16. package/dist-esm/Config/DynamicConfig.js +1 -1
  17. package/dist-esm/Config/DynamicProperty.js +1 -1
  18. package/dist-esm/Config/DynamicState.js +1 -1
  19. package/dist-esm/Config/DynamicSupport.js +1 -1
  20. package/dist-esm/Config/IConfigDefaults.js +1 -1
  21. package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
  22. package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
  23. package/dist-esm/Config/IDynamicWatcher.js +1 -1
  24. package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
  25. package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
  26. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  27. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  28. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  29. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  30. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  31. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  32. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  33. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  34. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  35. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  36. package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  39. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  40. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  41. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  42. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
  43. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  44. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  45. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  46. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  47. package/dist-esm/JavaScriptSDK/UnloadHookContainer.js +1 -1
  48. package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
  77. package/dist-esm/__DynamicConstants.js +1 -1
  78. package/dist-esm/applicationinsights-core-js.js +1 -1
  79. package/package.json +1 -1
  80. package/types/JavaScriptSDK/AppInsightsCore.d.ts +5 -6
  81. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +9 -6
  82. package/src/JavaScriptSDK/AggregationError.ts +0 -36
  83. package/src/JavaScriptSDK/AppInsightsCore.ts +0 -1322
  84. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +0 -343
  85. package/src/JavaScriptSDK/Constants.ts +0 -4
  86. package/src/JavaScriptSDK/CookieMgr.ts +0 -449
  87. package/src/JavaScriptSDK/CoreUtils.ts +0 -58
  88. package/src/JavaScriptSDK/DataCacheHelper.ts +0 -107
  89. package/src/JavaScriptSDK/DbgExtensionUtils.ts +0 -56
  90. package/src/JavaScriptSDK/DiagnosticLogger.ts +0 -380
  91. package/src/JavaScriptSDK/EnvUtils.ts +0 -312
  92. package/src/JavaScriptSDK/EventHelpers.ts +0 -550
  93. package/src/JavaScriptSDK/HelperFuncs.ts +0 -351
  94. package/src/JavaScriptSDK/InstrumentHooks.ts +0 -280
  95. package/src/JavaScriptSDK/InternalConstants.ts +0 -31
  96. package/src/JavaScriptSDK/NotificationManager.ts +0 -165
  97. package/src/JavaScriptSDK/PerfManager.ts +0 -288
  98. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +0 -674
  99. package/src/JavaScriptSDK/RandomHelper.ts +0 -145
  100. package/src/JavaScriptSDK/TelemetryHelpers.ts +0 -184
  101. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -112
  102. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -45
  103. package/src/JavaScriptSDK/UnloadHookContainer.ts +0 -52
  104. package/src/JavaScriptSDK/W3cTraceParent.ts +0 -197
  105. package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -24
  106. package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +0 -71
  107. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +0 -121
  108. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -56
  109. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
  110. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
  111. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +0 -216
  112. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +0 -46
  113. package/src/JavaScriptSDK.Interfaces/IConfiguration.ts +0 -176
  114. package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +0 -116
  115. package/src/JavaScriptSDK.Interfaces/IDbgExtension.ts +0 -14
  116. package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +0 -75
  117. package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +0 -54
  118. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +0 -100
  119. package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +0 -39
  120. package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +0 -52
  121. package/src/JavaScriptSDK.Interfaces/IPerfEvent.ts +0 -69
  122. package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +0 -53
  123. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +0 -157
  124. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -17
  125. package/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +0 -62
  126. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +0 -94
  127. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +0 -30
  128. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
  129. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -44
  130. package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +0 -38
  131. package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +0 -22
  132. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
@@ -1,165 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
- import dynamicProto from "@microsoft/dynamicproto-js";
4
- import { arrForEach, arrIndexOf, scheduleTimeout } from "@nevware21/ts-utils";
5
- import { createDynamicConfig } from "../Config/DynamicConfig";
6
- import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
7
- import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
8
- import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
9
- import { IPerfEvent } from "../JavaScriptSDK.Interfaces/IPerfEvent";
10
- import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
11
- import { STR_EVENTS_DISCARDED, STR_EVENTS_SEND_REQUEST, STR_EVENTS_SENT, STR_PERF_EVENT } from "./InternalConstants";
12
-
13
- const defaultValues = {
14
- perfEvtsSendAll: false
15
- };
16
-
17
- function _runListeners(listeners: INotificationListener[], name: string, isAsync: boolean, callback: (listener: INotificationListener) => void) {
18
- arrForEach(listeners, (listener) => {
19
- if (listener && listener[name]) {
20
- if (isAsync) {
21
- scheduleTimeout(() => callback(listener), 0);
22
- } else {
23
- try {
24
- callback(listener);
25
- } catch (e) {
26
- // Catch errors to ensure we don't block sending the requests
27
- }
28
- }
29
- }
30
- });
31
- }
32
-
33
- /**
34
- * Class to manage sending notifications to all the listeners.
35
- */
36
- export class NotificationManager implements INotificationManager {
37
- listeners: INotificationListener[] = [];
38
-
39
- constructor(config?: IConfiguration) {
40
- let perfEvtsSendAll: boolean;
41
-
42
- let cfgHandler = createDynamicConfig(config, defaultValues);
43
-
44
- cfgHandler.watch((details) => {
45
- perfEvtsSendAll = !!details.cfg.perfEvtsSendAll;
46
- });
47
-
48
- dynamicProto(NotificationManager, this, (_self) => {
49
- _self.addNotificationListener = (listener: INotificationListener): void => {
50
- _self.listeners.push(listener);
51
- };
52
-
53
- /**
54
- * Removes all instances of the listener.
55
- * @param listener - AWTNotificationListener to remove.
56
- */
57
- _self.removeNotificationListener = (listener: INotificationListener): void => {
58
- let index: number = arrIndexOf(_self.listeners, listener);
59
- while (index > -1) {
60
- _self.listeners.splice(index, 1);
61
- index = arrIndexOf(_self.listeners, listener);
62
- }
63
- };
64
-
65
- /**
66
- * Notification for events sent.
67
- * @param events - The array of events that have been sent.
68
- */
69
- _self.eventsSent = (events: ITelemetryItem[]): void => {
70
- _runListeners(_self.listeners, STR_EVENTS_SENT, true, (listener) => {
71
- listener.eventsSent(events);
72
- });
73
- };
74
-
75
- /**
76
- * Notification for events being discarded.
77
- * @param events - The array of events that have been discarded by the SDK.
78
- * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
79
- * constant should be used to check the different values.
80
- */
81
- _self.eventsDiscarded = (events: ITelemetryItem[], reason: number): void => {
82
- _runListeners(_self.listeners, STR_EVENTS_DISCARDED, true, (listener) => {
83
- listener.eventsDiscarded(events, reason);
84
- });
85
- };
86
-
87
- /**
88
- * [Optional] A function called when the events have been requested to be sent to the sever.
89
- * @param sendReason - The reason why the event batch is being sent.
90
- * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
91
- */
92
- _self.eventsSendRequest = (sendReason: number, isAsync: boolean): void => {
93
- _runListeners(_self.listeners, STR_EVENTS_SEND_REQUEST, isAsync, (listener) => {
94
- listener.eventsSendRequest(sendReason, isAsync);
95
- });
96
- };
97
-
98
- _self.perfEvent = (perfEvent?: IPerfEvent): void => {
99
- if (perfEvent) {
100
-
101
- // Send all events or only parent events
102
- if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
103
- _runListeners(_self.listeners, STR_PERF_EVENT, false, (listener) => {
104
- if (perfEvent.isAsync) {
105
- scheduleTimeout(() => listener.perfEvent(perfEvent), 0);
106
- } else {
107
- listener.perfEvent(perfEvent);
108
- }
109
- });
110
- }
111
- }
112
- }
113
- });
114
- }
115
-
116
- /**
117
- * Adds a notification listener.
118
- * @param listener - The notification listener to be added.
119
- */
120
- addNotificationListener(listener: INotificationListener): void {
121
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
122
- }
123
-
124
- /**
125
- * Removes all instances of the listener.
126
- * @param listener - AWTNotificationListener to remove.
127
- */
128
- removeNotificationListener(listener: INotificationListener): void {
129
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
130
- }
131
-
132
- /**
133
- * Notification for events sent.
134
- * @param events - The array of events that have been sent.
135
- */
136
- eventsSent(events: ITelemetryItem[]): void {
137
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
138
- }
139
-
140
- /**
141
- * Notification for events being discarded.
142
- * @param events - The array of events that have been discarded by the SDK.
143
- * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
144
- * constant should be used to check the different values.
145
- */
146
- eventsDiscarded(events: ITelemetryItem[], reason: number): void {
147
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
148
- }
149
-
150
- /**
151
- * [Optional] A function called when the events have been requested to be sent to the sever.
152
- * @param sendReason - The reason why the event batch is being sent.
153
- * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
154
- */
155
- eventsSendRequest?(sendReason: number, isAsync: boolean): void {
156
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
157
- }
158
-
159
- /**
160
- * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
161
- * the event can be displayed via the debug plugin extension.
162
- * @param perfEvent
163
- */
164
- perfEvent?(perfEvent: IPerfEvent): void;
165
- }
@@ -1,288 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
- import dynamicProto from "@microsoft/dynamicproto-js";
4
- import { isArray, isFunction, objDefineAccessors, utcNow } from "@nevware21/ts-utils";
5
- import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
6
- import { IPerfEvent } from "../JavaScriptSDK.Interfaces/IPerfEvent";
7
- import { IPerfManager, IPerfManagerProvider } from "../JavaScriptSDK.Interfaces/IPerfManager";
8
- import { STR_GET_PERF_MGR } from "./InternalConstants";
9
-
10
- const strExecutionContextKey = "ctx";
11
- const strParentContextKey = "ParentContextKey";
12
- const strChildrenContextKey = "ChildrenContextKey";
13
-
14
- let _defaultPerfManager: IPerfManager = null;
15
-
16
- export class PerfEvent implements IPerfEvent {
17
- public static ParentContextKey = "parent";
18
- public static ChildrenContextKey = "childEvts";
19
-
20
- /**
21
- * The name of the event
22
- */
23
- name: string;
24
-
25
- /**
26
- * The start time of the event in ms
27
- */
28
- start: number;
29
-
30
- /**
31
- * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
32
- * the runtime environment.
33
- */
34
- payload: any;
35
-
36
- /**
37
- * Is this occurring from an asynchronous event
38
- */
39
- isAsync: boolean;
40
-
41
- /**
42
- * Identifies the total inclusive time spent for this event, including the time spent for child events,
43
- * this will be undefined until the event is completed
44
- */
45
- time?: number;
46
-
47
- /**
48
- * Identifies the exclusive time spent in for this event (not including child events),
49
- * this will be undefined until the event is completed.
50
- */
51
- exTime?: number;
52
-
53
- /**
54
- * Identifies whether this event is a child event of a parent
55
- */
56
- isChildEvt: () => boolean;
57
-
58
- getCtx?: (key: string) => any | null | undefined;
59
-
60
- setCtx?: (key: string, value: any) => void;
61
-
62
- complete: () => void;
63
-
64
- constructor(name: string, payloadDetails: () => any, isAsync: boolean) {
65
- let _self = this;
66
- _self.start = utcNow();
67
- _self.name = name;
68
- _self.isAsync = isAsync;
69
- _self.isChildEvt = (): boolean => false;
70
-
71
- if (isFunction(payloadDetails)) {
72
- // Create an accessor to minimize the potential performance impact of executing the payloadDetails callback
73
- let theDetails:any;
74
- objDefineAccessors(_self, "payload", () => {
75
- // Delay the execution of the payloadDetails until needed
76
- if (!theDetails && isFunction(payloadDetails)) {
77
- theDetails = payloadDetails();
78
- // clear it out now so the referenced objects can be garbage collected
79
- payloadDetails = null;
80
- }
81
-
82
- return theDetails;
83
- });
84
- }
85
-
86
- _self.getCtx = (key: string): any | null | undefined => {
87
- if (key) {
88
- // The parent and child links are located directly on the object (for better viewing in the DebugPlugin)
89
- if (key === PerfEvent[strParentContextKey] || key === PerfEvent[strChildrenContextKey]) {
90
- return _self[key];
91
- }
92
-
93
- return (_self[strExecutionContextKey] || {})[key];
94
- }
95
-
96
- return null;
97
- };
98
-
99
- _self.setCtx = (key: string, value: any) => {
100
- if (key) {
101
- // Put the parent and child links directly on the object (for better viewing in the DebugPlugin)
102
- if (key === PerfEvent[strParentContextKey]) {
103
- // Simple assumption, if we are setting a parent then we must be a child
104
- if (!_self[key]) {
105
- _self.isChildEvt = (): boolean => true;
106
- }
107
- _self[key] = value;
108
- } else if (key === PerfEvent[strChildrenContextKey]) {
109
- _self[key] = value;
110
- } else {
111
- let ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
112
- ctx[key] = value;
113
- }
114
- }
115
- };
116
-
117
- _self.complete = () => {
118
- let childTime = 0;
119
- let childEvts = _self.getCtx(PerfEvent[strChildrenContextKey]);
120
- if (isArray<IPerfEvent>(childEvts)) {
121
- for (let lp = 0; lp < childEvts.length; lp++) {
122
- let childEvt: IPerfEvent = childEvts[lp];
123
- if (childEvt) {
124
- childTime += childEvt.time;
125
- }
126
- }
127
- }
128
-
129
- _self.time = utcNow() - _self.start;
130
- _self.exTime = _self.time - childTime;
131
- _self.complete = () => {};
132
- };
133
- }
134
- }
135
-
136
- export class PerfManager implements IPerfManager {
137
- /**
138
- * General bucket used for execution context set and retrieved via setCtx() and getCtx.
139
- * Defined as private so it can be visualized via the DebugPlugin
140
- */
141
- private ctx: { [key: string] : any } = {};
142
-
143
- constructor(manager?: INotificationManager) {
144
-
145
- dynamicProto(PerfManager, this, (_self) => {
146
-
147
- _self.create = (src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined => {
148
- // TODO (@MSNev): at some point we will want to add additional configuration to "select" which events to instrument
149
- // for now this is just a simple do everything.
150
- return new PerfEvent(src, payloadDetails, isAsync);
151
- };
152
-
153
- _self.fire = (perfEvent: IPerfEvent) => {
154
- if (perfEvent) {
155
- perfEvent.complete();
156
-
157
- if (manager && isFunction(manager.perfEvent)) {
158
- manager.perfEvent(perfEvent);
159
- }
160
- }
161
- };
162
-
163
- _self.setCtx = (key: string, value: any): void => {
164
- if (key) {
165
- let ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
166
- ctx[key] = value;
167
- }
168
- };
169
-
170
- _self.getCtx = (key: string): any => {
171
- return (_self[strExecutionContextKey] || {})[key];
172
- };
173
- });
174
- }
175
-
176
- /**
177
- * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
178
- * want to monitor this source event.
179
- * @param src - The source name of the event
180
- * @param payloadDetails - An optional callback function to fetch the payload details for the event.
181
- * @param isAsync - Is the event occurring from a async event
182
- */
183
- public create(src: string, payload?: any, isAsync?: boolean): IPerfEvent | null | undefined {
184
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
185
- return null;
186
- }
187
-
188
- /**
189
- * Complete the perfEvent and fire any notifications.
190
- * @param perfEvent - Fire the event which will also complete the passed event
191
- */
192
- public fire(perfEvent: IPerfEvent): void {
193
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
194
- }
195
-
196
- /**
197
- * Set an execution context value
198
- * @param key - The context key name
199
- * @param value - The value
200
- */
201
- public setCtx(key: string, value: any): void {
202
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
203
- }
204
-
205
- /**
206
- * Get the execution context value
207
- * @param key - The context key
208
- */
209
- public getCtx(key: string): any {
210
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
211
- }
212
- }
213
-
214
- const doPerfActiveKey = "CoreUtils.doPerf";
215
-
216
- /**
217
- * Helper function to wrap a function with a perf event
218
- * @param mgrSource - The Performance Manager or a Performance provider source (may be null)
219
- * @param getSource - The callback to create the source name for the event (if perf monitoring is enabled)
220
- * @param func - The function to call and measure
221
- * @param details - A function to return the payload details
222
- * @param isAsync - Is the event / function being call asynchronously or synchronously
223
- */
224
- export function doPerf<T>(mgrSource: IPerfManagerProvider | IPerfManager, getSource: () => string, func: (perfEvt?: IPerfEvent) => T, details?: () => any, isAsync?: boolean) {
225
- if (mgrSource) {
226
- let perfMgr: IPerfManager = mgrSource as IPerfManager;
227
- if (perfMgr[STR_GET_PERF_MGR]) {
228
- // Looks like a perf manager provider object
229
- perfMgr = perfMgr[STR_GET_PERF_MGR]();
230
- }
231
-
232
- if (perfMgr) {
233
- let perfEvt: IPerfEvent;
234
- let currentActive: IPerfEvent = perfMgr.getCtx(doPerfActiveKey);
235
- try {
236
- perfEvt = perfMgr.create(getSource(), details, isAsync);
237
- if (perfEvt) {
238
- if (currentActive && perfEvt.setCtx) {
239
- perfEvt.setCtx(PerfEvent[strParentContextKey], currentActive);
240
- if (currentActive.getCtx && currentActive.setCtx) {
241
- let children: IPerfEvent[] = currentActive.getCtx(PerfEvent[strChildrenContextKey]);
242
- if (!children) {
243
- children = [];
244
- currentActive.setCtx(PerfEvent[strChildrenContextKey], children);
245
- }
246
-
247
- children.push(perfEvt);
248
- }
249
- }
250
-
251
- // Set this event as the active event now
252
- perfMgr.setCtx(doPerfActiveKey, perfEvt);
253
- return func(perfEvt);
254
- }
255
- } catch (ex) {
256
- if (perfEvt && perfEvt.setCtx) {
257
- perfEvt.setCtx("exception", ex);
258
- }
259
- } finally {
260
- // fire the perf event
261
- if (perfEvt) {
262
- perfMgr.fire(perfEvt);
263
- }
264
-
265
- // Reset the active event to the previous value
266
- perfMgr.setCtx(doPerfActiveKey, currentActive);
267
- }
268
- }
269
- }
270
-
271
- return func();
272
- }
273
-
274
- /**
275
- * Set the global performance manager to use when there is no core instance or it has not been initialized yet.
276
- * @param perfManager - The IPerfManager instance to use when no performance manager is supplied.
277
- */
278
- export function setGblPerfMgr(perfManager: IPerfManager) {
279
- _defaultPerfManager = perfManager;
280
- }
281
-
282
- /**
283
- * Get the current global performance manager that will be used with no performance manager is supplied.
284
- * @returns - The current default manager
285
- */
286
- export function getGblPerfMgr(): IPerfManager {
287
- return _defaultPerfManager;
288
- }