@microsoft/applicationinsights-channel-js 2.7.2-nightly.2111-05 → 2.7.2-nightly.2111-09

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/Tests/Unit/src/Sample.tests.ts +154 -0
  2. package/Tests/Unit/src/Sender.tests.ts +1578 -0
  3. package/Tests/Unit/src/aichannel.tests.ts +7 -0
  4. package/Tests/UnitTests.html +53 -0
  5. package/Tests/tsconfig.json +17 -0
  6. package/api-extractor.json +361 -0
  7. package/applicationinsights-channel-js.build.error.log +20 -0
  8. package/applicationinsights-channel-js.build.log +265 -0
  9. package/browser/applicationinsights-channel-js.integrity.json +9 -9
  10. package/browser/applicationinsights-channel-js.js +2 -2
  11. package/browser/applicationinsights-channel-js.js.map +1 -1
  12. package/browser/applicationinsights-channel-js.min.js +2 -2
  13. package/browser/applicationinsights-channel-js.min.js.map +1 -1
  14. package/dist/applicationinsights-channel-js.api.json +1 -1
  15. package/dist/applicationinsights-channel-js.d.ts +1 -1
  16. package/dist/applicationinsights-channel-js.js +2 -2
  17. package/dist/applicationinsights-channel-js.js.map +1 -1
  18. package/dist/applicationinsights-channel-js.min.js +2 -2
  19. package/dist/applicationinsights-channel-js.min.js.map +1 -1
  20. package/dist/applicationinsights-channel-js.rollup.d.ts +1 -1
  21. package/dist-esm/EnvelopeCreator.js +2 -2
  22. package/dist-esm/EnvelopeCreator.js.map +1 -1
  23. package/dist-esm/Interfaces.js +1 -1
  24. package/dist-esm/Offline.js +1 -1
  25. package/dist-esm/SendBuffer.js +1 -1
  26. package/dist-esm/Sender.js +1 -1
  27. package/dist-esm/Serializer.js +1 -1
  28. package/dist-esm/TelemetryProcessors/Sample.js +1 -1
  29. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
  30. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
  31. package/dist-esm/applicationinsights-channel-js.js +1 -1
  32. package/microsoft-applicationinsights-channel-js-2.7.2-nightly.2111-09.tgz +0 -0
  33. package/package.json +3 -3
  34. package/rollup.config.js +139 -0
  35. package/src/EnvelopeCreator.ts +1 -1
  36. package/temp/applicationinsights-channel-js.api.md +62 -0
  37. package/tslint.json +8 -0
  38. package/types/tsdoc-metadata.json +1 -1
@@ -0,0 +1,154 @@
1
+ import { AITestClass } from "@microsoft/ai-test-framework";
2
+ import { Sample } from "../../../src/TelemetryProcessors/Sample";
3
+ import { ITelemetryItem } from "@microsoft/applicationinsights-core-js";
4
+ import { PageView, TelemetryItemCreator, IPageViewTelemetry, Util } from "@microsoft/applicationinsights-common";
5
+ import { HashCodeScoreGenerator } from "../../../src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator";
6
+
7
+ export class SampleTests extends AITestClass {
8
+ private sample: Sample
9
+ private item: ITelemetryItem;
10
+
11
+ public testInitialize() {
12
+ }
13
+
14
+ public testCleanup() {
15
+ this.sample = null;
16
+ this.item = null;
17
+ }
18
+
19
+ public registerTests() {
20
+ this.addSamplingTests();
21
+ }
22
+
23
+ private addSamplingTests() {
24
+ this.testCase({
25
+ name: 'Sampling: isSampledIn returns true for 100 sampling rate',
26
+ test: () => {
27
+ this.sample = new Sample(100);
28
+ this.item = this.getTelemetryItem();
29
+ const scoreStub = this.sandbox.stub(this.sample["samplingScoreGenerator"], "getSamplingScore");
30
+
31
+ QUnit.assert.ok(this.sample.isSampledIn(this.item));
32
+ QUnit.assert.ok(scoreStub.notCalled);
33
+ }
34
+ });
35
+
36
+ this.testCase({
37
+ name: 'Sampling: hashing is based on user id even if operation id is provided',
38
+ test: () => {
39
+ this.sample = new Sample(33);
40
+
41
+ const userid = "asdf";
42
+
43
+ const item1 = this.getTelemetryItem();
44
+ item1.tags["ai.user.id"] = userid;
45
+ item1.tags["ai.operation.id"] = "operation 1";
46
+
47
+ const item2 = this.getTelemetryItem();
48
+ item2.tags["ai.user.id"] = userid;
49
+ item2.tags["ai.operation.id"] = "operation 1";
50
+
51
+ const isSampledIn1 = this.sample.isSampledIn(item1);
52
+ const isSampledIn2 = this.sample.isSampledIn(item2);
53
+
54
+ QUnit.assert.equal(isSampledIn1, isSampledIn2);
55
+ }
56
+ });
57
+
58
+ this.testCase({
59
+ name: 'Sampling: hashing is based on operation id if no user id is provided',
60
+ test: () => {
61
+ this.sample = new Sample(33);
62
+ const operationId = "operation id";
63
+
64
+ const item1 = this.getTelemetryItem();
65
+ item1.tags["ai.user.id"] = null;
66
+ item1.tags["ai.operation.id"] = operationId;
67
+
68
+ const item2 = this.getTelemetryItem();
69
+ item2.tags["ai.user.id"] = null;
70
+ item2.tags["ai.operation.id"] = operationId;
71
+
72
+ const item3 = this.getTelemetryItem();
73
+ item3.tags["ai.user.id"] = null;
74
+ item3.tags["ai.operation.id"] = operationId;
75
+
76
+ const item4 = this.getTelemetryItem();
77
+ item4.tags["ai.user.id"] = null;
78
+ item4.tags["ai.operation.id"] = operationId;
79
+
80
+ // Act
81
+ const isSampledIn1 = this.sample.isSampledIn(item1);
82
+ const isSampledIn2 = this.sample.isSampledIn(item2);
83
+ const isSampledIn3 = this.sample.isSampledIn(item3);
84
+ const isSampledIn4 = this.sample.isSampledIn(item4);
85
+
86
+ QUnit.assert.equal(isSampledIn1, isSampledIn2);
87
+ QUnit.assert.equal(isSampledIn1, isSampledIn3);
88
+ QUnit.assert.equal(isSampledIn1, isSampledIn4);
89
+ }
90
+ });
91
+
92
+ this.testCase({
93
+ name: 'Sampling: hashing is random if no user id nor operation id provided',
94
+ test: () => {
95
+ // setup
96
+ this.sample = new Sample(33);
97
+
98
+ const envelope1 = this.getTelemetryItem();
99
+ envelope1.tags["ai.user.id"] = null;
100
+ envelope1.tags["ai.operation.id"] = null;
101
+
102
+ const mathRandomSpy = this.sandbox.spy(Math, "random");
103
+
104
+ // act
105
+ this.sample.isSampledIn(envelope1);
106
+
107
+ // assert
108
+ QUnit.assert.ok(mathRandomSpy.calledOnce);
109
+ }
110
+ });
111
+
112
+ this.testCase({
113
+ name: 'Sampling: actual sampling rate should fall into 5% error range',
114
+ test: () => {
115
+
116
+ // setup
117
+ const errorRange = 5;
118
+ const totalItems = 1000;
119
+ const ids = [];
120
+ for (let i = 0; i < totalItems; ++i) {
121
+ ids.push(Util.newId());
122
+ }
123
+
124
+ const sampleRates = [50, 33, 25, 20, 16, 10];
125
+
126
+ // act
127
+ sampleRates.forEach((sampleRate) => {
128
+ const sut = new HashCodeScoreGenerator();
129
+ let countOfSampledItems = 0;
130
+
131
+ ids.forEach((id) => {
132
+ if (sut.getHashCodeScore(id) < sampleRate) {++countOfSampledItems; }
133
+ });
134
+
135
+ // Assert
136
+ const actualSampleRate = 100 * countOfSampledItems / totalItems;
137
+ QUnit.assert.ok(Math.abs(actualSampleRate - sampleRate) < errorRange,
138
+ "Actual sampling (" + actualSampleRate + ") does not fall into +-2% range from expected rate (" + sampleRate + ")");
139
+ });
140
+ }
141
+ });
142
+ }
143
+
144
+ private getTelemetryItem(): ITelemetryItem {
145
+ return TelemetryItemCreator.create<IPageViewTelemetry>({
146
+ name: 'some page',
147
+ uri: 'some uri'
148
+ }, PageView.dataType, PageView.envelopeType, null);
149
+ }
150
+
151
+ private getMetricItem(): ITelemetryItem {
152
+ return null;
153
+ }
154
+ }