@microsoft/applicationinsights-channel-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-04

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 (38) hide show
  1. package/browser/applicationinsights-channel-js.integrity.json +9 -9
  2. package/browser/applicationinsights-channel-js.js +1363 -719
  3. package/browser/applicationinsights-channel-js.js.map +1 -1
  4. package/browser/applicationinsights-channel-js.min.js +2 -2
  5. package/browser/applicationinsights-channel-js.min.js.map +1 -1
  6. package/dist/applicationinsights-channel-js.api.json +56 -58
  7. package/dist/applicationinsights-channel-js.api.md +0 -2
  8. package/dist/applicationinsights-channel-js.d.ts +1 -2
  9. package/dist/applicationinsights-channel-js.js +1363 -719
  10. package/dist/applicationinsights-channel-js.js.map +1 -1
  11. package/dist/applicationinsights-channel-js.min.js +2 -2
  12. package/dist/applicationinsights-channel-js.min.js.map +1 -1
  13. package/dist/applicationinsights-channel-js.rollup.d.ts +1 -2
  14. package/dist-esm/EnvelopeCreator.js +2 -2
  15. package/dist-esm/EnvelopeCreator.js.map +1 -1
  16. package/dist-esm/Interfaces.js +1 -1
  17. package/dist-esm/Offline.js +77 -65
  18. package/dist-esm/Offline.js.map +1 -1
  19. package/dist-esm/SendBuffer.js +1 -1
  20. package/dist-esm/Sender.js +72 -62
  21. package/dist-esm/Sender.js.map +1 -1
  22. package/dist-esm/Serializer.js +1 -1
  23. package/dist-esm/TelemetryProcessors/Sample.js +3 -3
  24. package/dist-esm/TelemetryProcessors/Sample.js.map +1 -1
  25. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
  26. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
  27. package/dist-esm/applicationinsights-channel-js.js +1 -1
  28. package/package.json +4 -4
  29. package/src/EnvelopeCreator.ts +2 -2
  30. package/src/Offline.ts +88 -76
  31. package/src/Sender.ts +83 -90
  32. package/src/Serializer.ts +4 -8
  33. package/src/TelemetryProcessors/Sample.ts +1 -1
  34. package/src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.ts +3 -1
  35. package/types/Offline.d.ts +8 -11
  36. package/types/Sender.d.ts +0 -1
  37. package/types/TelemetryProcessors/Sample.d.ts +2 -2
  38. package/types/tsdoc-metadata.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  import { LoggingSeverity, _InternalMessageId, getJSON, objForEachKey, isFunction, isObject, isArray } from "@microsoft/applicationinsights-core-js";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -20,8 +20,8 @@ var Sample = /** @class */ (function () {
20
20
  this.samplingScoreGenerator = new SamplingScoreGenerator();
21
21
  }
22
22
  /**
23
- * Determines if an envelope is sampled in (i.e. will be sent) or not (i.e. will be dropped).
24
- */
23
+ * Determines if an envelope is sampled in (i.e. will be sent) or not (i.e. will be dropped).
24
+ */
25
25
  Sample.prototype.isSampledIn = function (envelope) {
26
26
  var samplingPercentage = this.sampleRate; // 0 - 100
27
27
  var isSampledIn = false;
@@ -1 +1 @@
1
- {"version":3,"file":"Sample.js.map","sources":["Sample.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { SamplingScoreGenerator } from \"./SamplingScoreGenerators/SamplingScoreGenerator\";\r\nimport { Metric } from \"@microsoft/applicationinsights-common\";\r\nimport { _InternalMessageId, LoggingSeverity, safeGetLogger } from \"@microsoft/applicationinsights-core-js\";\r\nvar Sample = /** @class */ (function () {\r\n function Sample(sampleRate, logger) {\r\n // We're using 32 bit math, hence max value is (2^31 - 1)\r\n this.INT_MAX_VALUE = 2147483647;\r\n var _logger = logger || safeGetLogger(null);\r\n if (sampleRate > 100 || sampleRate < 0) {\r\n _logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.SampleRateOutOfRange, \"Sampling rate is out of range (0..100). Sampling will be disabled, you may be sending too much data which may affect your AI service level.\", { samplingRate: sampleRate }, true);\r\n sampleRate = 100;\r\n }\r\n this.sampleRate = sampleRate;\r\n this.samplingScoreGenerator = new SamplingScoreGenerator();\r\n }\r\n /**\r\n * Determines if an envelope is sampled in (i.e. will be sent) or not (i.e. will be dropped).\r\n */\r\n Sample.prototype.isSampledIn = function (envelope) {\r\n var samplingPercentage = this.sampleRate; // 0 - 100\r\n var isSampledIn = false;\r\n if (samplingPercentage === null || samplingPercentage === undefined || samplingPercentage >= 100) {\r\n return true;\r\n }\r\n else if (envelope.baseType === Metric.dataType) {\r\n // exclude MetricData telemetry from sampling\r\n return true;\r\n }\r\n isSampledIn = this.samplingScoreGenerator.getSamplingScore(envelope) < samplingPercentage;\r\n return isSampledIn;\r\n };\r\n return Sample;\r\n}());\r\nexport { Sample };\r\n//# sourceMappingURL=Sample.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"}
1
+ {"version":3,"file":"Sample.js.map","sources":["Sample.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { SamplingScoreGenerator } from \"./SamplingScoreGenerators/SamplingScoreGenerator\";\r\nimport { Metric } from \"@microsoft/applicationinsights-common\";\r\nimport { _InternalMessageId, LoggingSeverity, safeGetLogger } from \"@microsoft/applicationinsights-core-js\";\r\nvar Sample = /** @class */ (function () {\r\n function Sample(sampleRate, logger) {\r\n // We're using 32 bit math, hence max value is (2^31 - 1)\r\n this.INT_MAX_VALUE = 2147483647;\r\n var _logger = logger || safeGetLogger(null);\r\n if (sampleRate > 100 || sampleRate < 0) {\r\n _logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.SampleRateOutOfRange, \"Sampling rate is out of range (0..100). Sampling will be disabled, you may be sending too much data which may affect your AI service level.\", { samplingRate: sampleRate }, true);\r\n sampleRate = 100;\r\n }\r\n this.sampleRate = sampleRate;\r\n this.samplingScoreGenerator = new SamplingScoreGenerator();\r\n }\r\n /**\r\n * Determines if an envelope is sampled in (i.e. will be sent) or not (i.e. will be dropped).\r\n */\r\n Sample.prototype.isSampledIn = function (envelope) {\r\n var samplingPercentage = this.sampleRate; // 0 - 100\r\n var isSampledIn = false;\r\n if (samplingPercentage === null || samplingPercentage === undefined || samplingPercentage >= 100) {\r\n return true;\r\n }\r\n else if (envelope.baseType === Metric.dataType) {\r\n // exclude MetricData telemetry from sampling\r\n return true;\r\n }\r\n isSampledIn = this.samplingScoreGenerator.getSamplingScore(envelope) < samplingPercentage;\r\n return isSampledIn;\r\n };\r\n return Sample;\r\n}());\r\nexport { Sample };\r\n//# sourceMappingURL=Sample.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"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  export { Sender } from "./Sender";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-channel-js",
3
- "version": "2.8.0-nightly.2202-06",
3
+ "version": "2.8.0-nightly.2204-04",
4
4
  "description": "Microsoft Application Insights JavaScript SDK Channel",
5
5
  "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
6
  "author": "Microsoft Application Insights Team",
@@ -35,7 +35,7 @@
35
35
  "@rollup/plugin-commonjs": "^18.0.0",
36
36
  "@rollup/plugin-node-resolve": "^11.2.1",
37
37
  "@rollup/plugin-replace": "^2.3.3",
38
- "rollup-plugin-cleanup": "3.2.1",
38
+ "rollup-plugin-cleanup": "^3.2.1",
39
39
  "rollup": "^2.32.0",
40
40
  "typescript": "^4.3.4",
41
41
  "tslib": "^2.0.0",
@@ -47,8 +47,8 @@
47
47
  "dependencies": {
48
48
  "@microsoft/dynamicproto-js": "^1.1.4",
49
49
  "@microsoft/applicationinsights-shims": "2.0.1",
50
- "@microsoft/applicationinsights-core-js": "2.8.0-nightly.2202-06",
51
- "@microsoft/applicationinsights-common": "2.8.0-nightly.2202-06"
50
+ "@microsoft/applicationinsights-core-js": "2.8.0-nightly.2204-04",
51
+ "@microsoft/applicationinsights-common": "2.8.0-nightly.2204-04"
52
52
  },
53
53
  "license": "MIT",
54
54
  "publishConfig": {
@@ -175,7 +175,7 @@ function EnvelopeCreatorInit(logger: IDiagnosticLogger, telemetryItem: ITelemetr
175
175
  }
176
176
 
177
177
  export const EnvelopeCreator = {
178
- Version: "2.8.0-nightly.2202-06"
178
+ Version: "2.8.0-nightly.2204-04"
179
179
  };
180
180
 
181
181
  export function DependencyEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
@@ -279,7 +279,7 @@ export function PageViewEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem
279
279
 
280
280
  const bd = telemetryItem[strBaseData] as IPageViewTelemetryInternal;
281
281
 
282
- // special case: pageview.id is grabbed from current operation id. Analytics plugin is decoupled from properties plugin, so this is done here instead. This can be made a default telemetry intializer instead if needed to be decoupled from channel
282
+ // special case: pageview.id is grabbed from current operation id. Analytics plugin is decoupled from properties plugin, so this is done here instead. This can be made a default telemetry intializer instead if needed to be decoupled from channel
283
283
  let currentContextId;
284
284
  if (((telemetryItem.ext || {}).trace || {}).traceID) {
285
285
  currentContextId = telemetryItem.ext.trace.traceID;
package/src/Offline.ts CHANGED
@@ -1,92 +1,104 @@
1
- import { getWindow, getDocument, getNavigator, isUndefined, isNullOrUndefined, attachEvent } from "@microsoft/applicationinsights-core-js";
2
- import dynamicProto from "@microsoft/dynamicproto-js";
1
+ import { getWindow, getDocument, getNavigator, isUndefined, isNullOrUndefined, createUniqueNamespace, mergeEvtNamespace, eventOn, eventOff } from "@microsoft/applicationinsights-core-js";
2
+
3
+ export interface IOfflineListener {
4
+ isOnline: () => boolean;
5
+ isListening: () => boolean;
6
+ unload: () => void;
7
+ }
8
+
9
+ function _disableEvents(target: any, evtNamespace: string | string[]) {
10
+ eventOff(target, null, null, evtNamespace);
11
+ }
3
12
 
4
13
  /**
5
- * @description Monitors browser for offline events
6
- * @export default - Offline: Static instance of OfflineListener
7
- * @class OfflineListener
14
+ * Create a new OfflineListener instance to monitor browser online / offline events
15
+ * @param parentEvtNamespace - The parent event namespace to append to any specific events for this instance
8
16
  */
9
- export class OfflineListener {
10
- public static Offline = new OfflineListener;
11
- public isListening: boolean;
12
-
13
- constructor() {
14
- let _window = getWindow();
15
- let _document = getDocument();
16
- let isListening = false;
17
- let _onlineStatus: boolean = true;
18
-
19
- dynamicProto(OfflineListener, this, (_self) => {
20
- try {
21
- if (_window) {
22
- if (attachEvent(_window, "online", _setOnline)) {
23
- attachEvent(_window, "offline", _setOffline);
24
- isListening = true;
25
- }
26
- }
27
-
28
- if (_document) {
29
- // Also attach to the document.body or document
30
- let target:any = _document.body || _document;
31
-
32
- if (!isUndefined(target.ononline)) {
33
- target.ononline = _setOnline;
34
- target.onoffline = _setOffline;
35
- isListening = true;
36
-
37
- }
38
- }
17
+ export function createOfflineListener(parentEvtNamespace?: string | string[]): IOfflineListener {
18
+ let _document = getDocument();
19
+ var _navigator = getNavigator(); // Gets the window.navigator or workerNavigator depending on the global
20
+ let _isListening: boolean = false;
21
+ let _onlineStatus: boolean = true;
22
+ let _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
39
23
 
40
- if (isListening) {
41
- // We are listening to events so lets set the current status rather than assuming we are online #1538
42
- var _navigator = getNavigator(); // Gets the window.navigator or workerNavigator depending on the global
43
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
44
- _onlineStatus = _navigator.onLine;
45
- }
24
+ try {
25
+ if (_enableEvents(getWindow())) {
26
+ _isListening = true;
27
+ }
28
+
29
+ if (_document) {
30
+ // Also attach to the document.body or document
31
+ let target:any = _document.body || _document;
32
+
33
+ if (target.ononline) {
34
+ if (_enableEvents(target)) {
35
+ _isListening = true;
46
36
  }
47
- } catch (e) {
48
-
49
- // this makes react-native less angry
50
- isListening = false;
51
37
  }
52
-
53
- _self.isListening = isListening;
54
-
55
- _self.isOnline = (): boolean => {
56
- let result = true;
57
- var _navigator = getNavigator();
58
- if (isListening) {
59
- result = _onlineStatus
60
- } else if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
61
- result = _navigator.onLine;
62
- }
38
+ }
63
39
 
64
- return result;
65
- };
66
-
67
- _self.isOffline = (): boolean => {
68
- return !_self.isOnline();
69
- };
70
-
71
- function _setOnline() {
72
- _onlineStatus = true;
40
+ if (_isListening) {
41
+ // We are listening to events so lets set the current status rather than assuming we are online #1538
42
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
43
+ _onlineStatus = _navigator.onLine;
73
44
  }
45
+ }
46
+ } catch (e) {
47
+ // this makes react-native less angry
48
+ _isListening = false;
49
+ }
74
50
 
75
- function _setOffline() {
76
- _onlineStatus = false;
51
+ function _enableEvents(target: any): boolean {
52
+ let enabled = false;
53
+ if (target) {
54
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
55
+ if (enabled) {
56
+ eventOn(target, "offline", _setOffline, _evtNamespace);
77
57
  }
78
- });
58
+ }
59
+
60
+ return enabled;
79
61
  }
80
62
 
81
- public isOnline(): boolean {
82
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
83
- return false;
63
+ function _setOnline() {
64
+ _onlineStatus = true;
84
65
  }
85
66
 
86
- public isOffline(): boolean {
87
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
88
- return false;
67
+ function _setOffline() {
68
+ _onlineStatus = false;
89
69
  }
90
- }
91
70
 
92
- export const Offline = OfflineListener.Offline;
71
+ function _isOnline(): boolean {
72
+ let result = true;
73
+ if (_isListening) {
74
+ result = _onlineStatus
75
+ } else if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
76
+ result = _navigator.onLine;
77
+ }
78
+
79
+ return result;
80
+ }
81
+
82
+ function _unload() {
83
+ let win = getWindow();
84
+ if (win && _isListening) {
85
+ _disableEvents(win, _evtNamespace);
86
+
87
+ if (_document) {
88
+ // Also attach to the document.body or document
89
+ let target:any = _document.body || _document;
90
+ if (!isUndefined(target.ononline)) {
91
+ _disableEvents(target, _evtNamespace);
92
+ }
93
+ }
94
+
95
+ _isListening = false;
96
+ }
97
+ }
98
+
99
+ return {
100
+ isOnline: _isOnline,
101
+ isListening: () => _isListening,
102
+ unload: _unload
103
+ };
104
+ }