@sap-ux/telemetry 0.2.0

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +27 -0
  3. package/dist/base/client/azure-appinsight-client.d.ts +88 -0
  4. package/dist/base/client/azure-appinsight-client.js +195 -0
  5. package/dist/base/client/client.d.ts +24 -0
  6. package/dist/base/client/client.js +33 -0
  7. package/dist/base/client/index.d.ts +24 -0
  8. package/dist/base/client/index.js +38 -0
  9. package/dist/base/config-state.d.ts +12 -0
  10. package/dist/base/config-state.js +26 -0
  11. package/dist/base/decorator/index.d.ts +23 -0
  12. package/dist/base/decorator/index.js +41 -0
  13. package/dist/base/interceptor/config.d.ts +19 -0
  14. package/dist/base/interceptor/config.js +54 -0
  15. package/dist/base/interceptor/index.d.ts +10 -0
  16. package/dist/base/interceptor/index.js +90 -0
  17. package/dist/base/performance/api.d.ts +74 -0
  18. package/dist/base/performance/api.js +120 -0
  19. package/dist/base/performance/entries.d.ts +42 -0
  20. package/dist/base/performance/entries.js +53 -0
  21. package/dist/base/performance/types.d.ts +35 -0
  22. package/dist/base/performance/types.js +17 -0
  23. package/dist/base/types/event-header.d.ts +28 -0
  24. package/dist/base/types/event-header.js +38 -0
  25. package/dist/base/types/event-name.d.ts +6 -0
  26. package/dist/base/types/event-name.js +10 -0
  27. package/dist/base/types/index.d.ts +5 -0
  28. package/dist/base/types/index.js +21 -0
  29. package/dist/base/types/project-info.d.ts +5 -0
  30. package/dist/base/types/project-info.js +3 -0
  31. package/dist/base/types/sample-rate.d.ts +6 -0
  32. package/dist/base/types/sample-rate.js +10 -0
  33. package/dist/base/utils/azure-client-config.d.ts +9 -0
  34. package/dist/base/utils/azure-client-config.js +21 -0
  35. package/dist/base/utils/date.d.ts +2 -0
  36. package/dist/base/utils/date.js +9 -0
  37. package/dist/base/utils/index.d.ts +6 -0
  38. package/dist/base/utils/index.js +24 -0
  39. package/dist/base/utils/logger.d.ts +6 -0
  40. package/dist/base/utils/logger.js +10 -0
  41. package/dist/base/utils/param-processing.d.ts +46 -0
  42. package/dist/base/utils/param-processing.js +103 -0
  43. package/dist/base/utils/reporting.d.ts +3 -0
  44. package/dist/base/utils/reporting.js +101 -0
  45. package/dist/index.d.ts +12 -0
  46. package/dist/index.js +35 -0
  47. package/dist/tooling-telemetry/config-state.d.ts +4 -0
  48. package/dist/tooling-telemetry/config-state.js +7 -0
  49. package/dist/tooling-telemetry/data-processor.d.ts +23 -0
  50. package/dist/tooling-telemetry/data-processor.js +354 -0
  51. package/dist/tooling-telemetry/index.d.ts +5 -0
  52. package/dist/tooling-telemetry/index.js +23 -0
  53. package/dist/tooling-telemetry/telemetry-client.d.ts +65 -0
  54. package/dist/tooling-telemetry/telemetry-client.js +118 -0
  55. package/dist/tooling-telemetry/telemetry-settings.d.ts +22 -0
  56. package/dist/tooling-telemetry/telemetry-settings.js +180 -0
  57. package/dist/tooling-telemetry/types.d.ts +92 -0
  58. package/dist/tooling-telemetry/types.js +40 -0
  59. package/package.json +60 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @sap-ux/telemetry
2
+
3
+ This library is used by SAP Fiori tools to collect anonymous usage data to guide Fiori tools improvement. This library is
4
+ specific for SAP Fiori tools's telemtry infrastrcture deployed on Azure cloud and it is built on Azure Application Insight node.js client. It is open sourced becaused some open sourced modules of Fiori tools need it for collecting usage data.
5
+
6
+
7
+ ## Installation
8
+ Npm
9
+ `npm install --save @sap-ux/telemetry`
10
+
11
+ Yarn
12
+ `yarn add @sap-ux/telemetry`
13
+
14
+ Pnpm
15
+ `pnpm add @sap-ux/telemetry`
16
+
17
+ ## Example Usage
18
+
19
+ See code in example folder for basic usage. To run example:
20
+
21
+ ```shell
22
+ # At project root folder of @sap-ux/telemetry
23
+ cd package/telemetry
24
+ # Create a file with name .env
25
+ # Add this line in .env file OpenUxTools_ResourceId=<your_azure_instrument_key>
26
+ pnpm example
27
+ ```
@@ -0,0 +1,88 @@
1
+ import { Client } from './client';
2
+ import { SampleRate } from '../types/sample-rate';
3
+ /**
4
+ *
5
+ */
6
+ declare class ApplicationInsightClient extends Client {
7
+ private clients;
8
+ /**
9
+ *
10
+ * @param applicationKey Application key to identify the Azure Application Insight resource
11
+ * @param extensionName Unique name of the extension in the format of {publisher}.{extension}
12
+ * @param extensionVersion Conventional version number of the extension
13
+ */
14
+ constructor(applicationKey: string, extensionName: string, extensionVersion: string);
15
+ /**
16
+ * Send a telemetry event to Azure Application Insights. This API makes sure the telemetry event
17
+ * is flushed to Azure backend before executing the next statement. Since this API blocks
18
+ * normal execution flow, please use this API cautiously. See `report()` method for non-blocking
19
+ * usage.
20
+ *
21
+ * @param eventName Categorize the type of the event within the scope of an extension.
22
+ * @param properties A set of string properties to be reported
23
+ * @param measurements A set of numeric measurements to be reported
24
+ * @param sampleRate Sampling the event to be sent
25
+ * @param ignoreSettings Ignore telemetryEnabled settings and skip submitting telemetry data
26
+ * @returns Promise<void>
27
+ */
28
+ reportBlocking(eventName: string, properties: {
29
+ [key: string]: string | boolean;
30
+ }, measurements: {
31
+ [key: string]: number;
32
+ }, sampleRate: SampleRate | undefined, ignoreSettings?: boolean): Promise<void>;
33
+ /**
34
+ * Send a telemetry event to Azure Application Insights. The telemetry event sending is still non-blocking
35
+ * in this API. To make sure telemetry event is sent to Azure backend before next statement, please see
36
+ * `reportBlocking()`.
37
+ *
38
+ * @param eventName Categorize the type of the event within the scope of an extension.
39
+ * @param properties A set of string properties to be reported
40
+ * @param measurements A set of numeric measurements to be reported
41
+ * @param sampleRate Sampling the event to be sent
42
+ * @param telemetryHelperProperties Properties that are passed to specific TelemetryClient for generating specific properties (E.g. ToolsSuiteTelemetryClient)
43
+ * @param ignoreSettings Ignore telemetryEnabled settings and skip submitting telemetry data
44
+ */
45
+ report(eventName: string, properties: {
46
+ [key: string]: string | boolean;
47
+ }, measurements: {
48
+ [key: string]: number;
49
+ }, sampleRate: SampleRate | undefined, telemetryHelperProperties?: {
50
+ [key: string]: string;
51
+ }, ignoreSettings?: boolean): Promise<void>;
52
+ /**
53
+ * Provide specification of telemetry event to be sent.
54
+ *
55
+ * @param eventName Categorize the type of the event within the scope of an extension.
56
+ * @param properties A set of string properties to be reported
57
+ * @param measurements A set of numeric measurements to be reported
58
+ * @param sampleRate Sampling the event to be sent
59
+ * @returns TelemetryClient instance and telemetry event
60
+ */
61
+ private prepareClientAndEvent;
62
+ /**
63
+ * Send telemetry event in blocking style. It blocks
64
+ * the subsequent statements until telemetry event has been sent.
65
+ *
66
+ * @param client TelemetryClient instance
67
+ * @param event Telemetry event
68
+ * @returns Promise<void>
69
+ */
70
+ private trackEventBlocking;
71
+ /**
72
+ * Send teleemtry event in non-blocking fashion.
73
+ *
74
+ * @param client Telemetry client instance
75
+ * @param event Telemetry event
76
+ * @returns Send telemetry succeeded or not
77
+ */
78
+ private trackEvent;
79
+ /**
80
+ * Create telemetry client instance based on sample rate.
81
+ *
82
+ * @param sampleRate Sampling telemetry event
83
+ * @returns Telemetry client instance
84
+ */
85
+ private createTelemetryClient;
86
+ }
87
+ export { ApplicationInsightClient };
88
+ //# sourceMappingURL=azure-appinsight-client.d.ts.map
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.ApplicationInsightClient = void 0;
36
+ const client_1 = require("./client");
37
+ const appInsights = __importStar(require("applicationinsights"));
38
+ const event_header_1 = require("../types/event-header");
39
+ const sample_rate_1 = require("../types/sample-rate");
40
+ const azure_client_config_1 = require("../utils/azure-client-config");
41
+ const config_state_1 = require("../config-state");
42
+ /**
43
+ *
44
+ */
45
+ class ApplicationInsightClient extends client_1.Client {
46
+ /**
47
+ *
48
+ * @param applicationKey Application key to identify the Azure Application Insight resource
49
+ * @param extensionName Unique name of the extension in the format of {publisher}.{extension}
50
+ * @param extensionVersion Conventional version number of the extension
51
+ */
52
+ constructor(applicationKey, extensionName, extensionVersion) {
53
+ super();
54
+ this.clients = new Map();
55
+ super.applicationKey = applicationKey;
56
+ this.extensionVersion = extensionVersion;
57
+ this.extensionName = extensionName;
58
+ const clientOnePercent = this.createTelemetryClient(sample_rate_1.SampleRate.OnePercent);
59
+ const clientTenPercent = this.createTelemetryClient(sample_rate_1.SampleRate.TenPercent);
60
+ const clientNoSampling = this.createTelemetryClient(sample_rate_1.SampleRate.NoSampling);
61
+ this.clients.set(sample_rate_1.SampleRate.OnePercent, clientOnePercent);
62
+ this.clients.set(sample_rate_1.SampleRate.TenPercent, clientTenPercent);
63
+ this.clients.set(sample_rate_1.SampleRate.NoSampling, clientNoSampling);
64
+ }
65
+ /**
66
+ * Send a telemetry event to Azure Application Insights. This API makes sure the telemetry event
67
+ * is flushed to Azure backend before executing the next statement. Since this API blocks
68
+ * normal execution flow, please use this API cautiously. See `report()` method for non-blocking
69
+ * usage.
70
+ *
71
+ * @param eventName Categorize the type of the event within the scope of an extension.
72
+ * @param properties A set of string properties to be reported
73
+ * @param measurements A set of numeric measurements to be reported
74
+ * @param sampleRate Sampling the event to be sent
75
+ * @param ignoreSettings Ignore telemetryEnabled settings and skip submitting telemetry data
76
+ * @returns Promise<void>
77
+ */
78
+ reportBlocking(eventName, properties, measurements, sampleRate, ignoreSettings = false) {
79
+ if (!ignoreSettings || config_state_1.TelemetrySettings.telemetryEnabled) {
80
+ const { client, event } = this.prepareClientAndEvent(eventName, properties, measurements, sampleRate);
81
+ return this.trackEventBlocking(client, event);
82
+ }
83
+ return Promise.resolve();
84
+ }
85
+ /**
86
+ * Send a telemetry event to Azure Application Insights. The telemetry event sending is still non-blocking
87
+ * in this API. To make sure telemetry event is sent to Azure backend before next statement, please see
88
+ * `reportBlocking()`.
89
+ *
90
+ * @param eventName Categorize the type of the event within the scope of an extension.
91
+ * @param properties A set of string properties to be reported
92
+ * @param measurements A set of numeric measurements to be reported
93
+ * @param sampleRate Sampling the event to be sent
94
+ * @param telemetryHelperProperties Properties that are passed to specific TelemetryClient for generating specific properties (E.g. ToolsSuiteTelemetryClient)
95
+ * @param ignoreSettings Ignore telemetryEnabled settings and skip submitting telemetry data
96
+ */
97
+ report(eventName, properties, measurements, sampleRate, telemetryHelperProperties, ignoreSettings) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if ((ignoreSettings !== undefined && !ignoreSettings) || !config_state_1.TelemetrySettings.telemetryEnabled) {
100
+ return;
101
+ }
102
+ const { client, event } = this.prepareClientAndEvent(eventName, properties, measurements, sampleRate);
103
+ this.trackEvent(client, event);
104
+ });
105
+ }
106
+ /**
107
+ * Provide specification of telemetry event to be sent.
108
+ *
109
+ * @param eventName Categorize the type of the event within the scope of an extension.
110
+ * @param properties A set of string properties to be reported
111
+ * @param measurements A set of numeric measurements to be reported
112
+ * @param sampleRate Sampling the event to be sent
113
+ * @returns TelemetryClient instance and telemetry event
114
+ */
115
+ prepareClientAndEvent(eventName, properties, measurements, sampleRate = sample_rate_1.SampleRate.NoSampling) {
116
+ const client = this.clients.get(sampleRate);
117
+ const eventHeader = new event_header_1.EventHeader(this.extensionName, eventName);
118
+ const event = {
119
+ name: eventHeader.toString(),
120
+ properties: properties,
121
+ measurements: measurements
122
+ };
123
+ return {
124
+ client,
125
+ event
126
+ };
127
+ }
128
+ /**
129
+ * Send telemetry event in blocking style. It blocks
130
+ * the subsequent statements until telemetry event has been sent.
131
+ *
132
+ * @param client TelemetryClient instance
133
+ * @param event Telemetry event
134
+ * @returns Promise<void>
135
+ */
136
+ trackEventBlocking(client, event) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ if (process.env.SAP_UX_FIORI_TOOLS_DISABLE_TELEMETRY === 'true') {
139
+ return Promise.resolve();
140
+ }
141
+ return new Promise((resolve, reject) => {
142
+ try {
143
+ client.trackEvent(event);
144
+ client.flush({
145
+ callback: () => resolve()
146
+ });
147
+ }
148
+ catch (error) {
149
+ reject(error);
150
+ }
151
+ });
152
+ });
153
+ }
154
+ /**
155
+ * Send teleemtry event in non-blocking fashion.
156
+ *
157
+ * @param client Telemetry client instance
158
+ * @param event Telemetry event
159
+ * @returns Send telemetry succeeded or not
160
+ */
161
+ trackEvent(client, event) {
162
+ if (process.env.SAP_UX_FIORI_TOOLS_DISABLE_TELEMETRY !== 'true') {
163
+ client.trackEvent(event);
164
+ return true;
165
+ }
166
+ return false;
167
+ }
168
+ /**
169
+ * Create telemetry client instance based on sample rate.
170
+ *
171
+ * @param sampleRate Sampling telemetry event
172
+ * @returns Telemetry client instance
173
+ */
174
+ createTelemetryClient(sampleRate) {
175
+ let sampleRateNumer;
176
+ switch (sampleRate) {
177
+ case sample_rate_1.SampleRate.OnePercent:
178
+ sampleRateNumer = 1;
179
+ break;
180
+ case sample_rate_1.SampleRate.TenPercent:
181
+ sampleRateNumer = 10;
182
+ break;
183
+ case sample_rate_1.SampleRate.NoSampling:
184
+ default:
185
+ sampleRateNumer = 100;
186
+ break;
187
+ }
188
+ const client = new appInsights.TelemetryClient(this.applicationKey);
189
+ client.config.samplingPercentage = sampleRateNumer;
190
+ (0, azure_client_config_1.configAzureTelemetryClient)(client);
191
+ return client;
192
+ }
193
+ }
194
+ exports.ApplicationInsightClient = ApplicationInsightClient;
195
+ //# sourceMappingURL=azure-appinsight-client.js.map
@@ -0,0 +1,24 @@
1
+ import type { SampleRate } from '../types/sample-rate';
2
+ /**
3
+ *
4
+ */
5
+ declare abstract class Client {
6
+ abstract report(event: string, properties: Record<string, string>, metrics: Record<string, number>, sampleRate: SampleRate | undefined, telemetryHelperProperties?: Record<string, string>, ignoreSettings?: boolean): Promise<void>;
7
+ protected applicationKey: string;
8
+ protected extensionName: string;
9
+ protected extensionVersion: string;
10
+ /**
11
+ * @returns Target Azure application insights resource Id
12
+ */
13
+ getApplicationKey(): string;
14
+ /**
15
+ * @returns Consumer module version
16
+ */
17
+ getExtensionVersion(): string;
18
+ /**
19
+ * @returns Consumer module name
20
+ */
21
+ getExtensionName(): string;
22
+ }
23
+ export { Client };
24
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ /**
5
+ *
6
+ */
7
+ class Client {
8
+ constructor() {
9
+ this.applicationKey = '';
10
+ this.extensionName = '';
11
+ this.extensionVersion = '';
12
+ }
13
+ /**
14
+ * @returns Target Azure application insights resource Id
15
+ */
16
+ getApplicationKey() {
17
+ return this.applicationKey;
18
+ }
19
+ /**
20
+ * @returns Consumer module version
21
+ */
22
+ getExtensionVersion() {
23
+ return this.extensionVersion;
24
+ }
25
+ /**
26
+ * @returns Consumer module name
27
+ */
28
+ getExtensionName() {
29
+ return this.extensionName;
30
+ }
31
+ }
32
+ exports.Client = Client;
33
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,24 @@
1
+ import type { Client } from './client';
2
+ import { ToolsSuiteTelemetryClient } from '../../tooling-telemetry';
3
+ /**
4
+ * Factory to get telemetry client instance.
5
+ */
6
+ declare class ClientFactory {
7
+ private static clientMap;
8
+ /**
9
+ * Get singleton instance of default telemetry client for Azure app insights.
10
+ *
11
+ * @returns Telemetry client for Azure app insights
12
+ */
13
+ static getTelemetryClient(): ToolsSuiteTelemetryClient;
14
+ /**
15
+ * Get singleton instance of telemetry client based on the generics type. Currently, we only support
16
+ * telemetry client for Azure app insights.
17
+ *
18
+ * @param clientConstructor Class passed in as construtor function. Needs to be subclass of Client class
19
+ * @returns Subclass of telemetry Client class
20
+ */
21
+ static getTelemetryClientByClass<T extends Client>(clientConstructor: new (appKey: string, extensionName: string, extensionVersion: string) => T): T;
22
+ }
23
+ export { ClientFactory };
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientFactory = void 0;
4
+ const tooling_telemetry_1 = require("../../tooling-telemetry");
5
+ const config_state_1 = require("../config-state");
6
+ /**
7
+ * Factory to get telemetry client instance.
8
+ */
9
+ class ClientFactory {
10
+ /**
11
+ * Get singleton instance of default telemetry client for Azure app insights.
12
+ *
13
+ * @returns Telemetry client for Azure app insights
14
+ */
15
+ static getTelemetryClient() {
16
+ return ClientFactory.getTelemetryClientByClass(tooling_telemetry_1.ToolsSuiteTelemetryClient);
17
+ }
18
+ /**
19
+ * Get singleton instance of telemetry client based on the generics type. Currently, we only support
20
+ * telemetry client for Azure app insights.
21
+ *
22
+ * @param clientConstructor Class passed in as construtor function. Needs to be subclass of Client class
23
+ * @returns Subclass of telemetry Client class
24
+ */
25
+ static getTelemetryClientByClass(clientConstructor) {
26
+ let client = ClientFactory.clientMap.get(clientConstructor.name);
27
+ if (client) {
28
+ return client;
29
+ }
30
+ const ClientConstructor = clientConstructor;
31
+ client = new ClientConstructor(config_state_1.TelemetrySettings.azureInstrumentationKey, config_state_1.TelemetrySettings.consumerModuleName, config_state_1.TelemetrySettings.consumerModuleVersion);
32
+ ClientFactory.clientMap.set(clientConstructor.name, client);
33
+ return client;
34
+ }
35
+ }
36
+ exports.ClientFactory = ClientFactory;
37
+ ClientFactory.clientMap = new Map();
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Runtime telemetry settings
3
+ */
4
+ export declare const TelemetrySettings: {
5
+ azureInstrumentationKey: string;
6
+ telemetryEnabled: boolean;
7
+ telemetryLibName: string;
8
+ telemetryLibVersion: string;
9
+ consumerModuleName: string;
10
+ consumerModuleVersion: string;
11
+ };
12
+ //# sourceMappingURL=config-state.d.ts.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TelemetrySettings = void 0;
7
+ // @ts-ignore
8
+ const package_json_1 = __importDefault(require("../../package.json"));
9
+ /**
10
+ * Runtime telemetry settings
11
+ */
12
+ exports.TelemetrySettings = {
13
+ // Target Azure apps insight destination
14
+ azureInstrumentationKey: '',
15
+ // Allow user to opt out from telemetry collection
16
+ telemetryEnabled: true,
17
+ // Module name in telemetry/pacakge.json
18
+ telemetryLibName: package_json_1.default.name,
19
+ // Version in telemetry/pacakge.json
20
+ telemetryLibVersion: package_json_1.default.version,
21
+ // Name of module that uses telemetry library
22
+ consumerModuleName: '',
23
+ // Version of module that uses telemetry library
24
+ consumerModuleVersion: ''
25
+ };
26
+ //# sourceMappingURL=config-state.js.map