@sap-ux/telemetry 1.0.12 → 1.0.14

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.
@@ -62,7 +62,7 @@ declare class ApplicationInsightClient extends Client {
62
62
  */
63
63
  private trackEventBlocking;
64
64
  /**
65
- * Send teleemtry event in non-blocking fashion.
65
+ * Send telemetry event in non-blocking fashion.
66
66
  *
67
67
  * @param client Telemetry client instance
68
68
  * @param event Telemetry event
@@ -104,23 +104,13 @@ class ApplicationInsightClient extends Client {
104
104
  * @returns Promise<void>
105
105
  */
106
106
  async trackEventBlocking(client, event) {
107
- if (process.env.SAP_UX_FIORI_TOOLS_DISABLE_TELEMETRY === 'true') {
108
- return;
107
+ if (process.env.SAP_UX_FIORI_TOOLS_DISABLE_TELEMETRY !== 'true') {
108
+ client.trackEvent(event);
109
+ await client.flush();
109
110
  }
110
- return new Promise((resolve, reject) => {
111
- try {
112
- client.trackEvent(event);
113
- client.flush({
114
- callback: () => resolve()
115
- });
116
- }
117
- catch (error) {
118
- reject(error);
119
- }
120
- });
121
111
  }
122
112
  /**
123
- * Send teleemtry event in non-blocking fashion.
113
+ * Send telemetry event in non-blocking fashion.
124
114
  *
125
115
  * @param client Telemetry client instance
126
116
  * @param event Telemetry event
@@ -140,21 +130,21 @@ class ApplicationInsightClient extends Client {
140
130
  * @returns Telemetry client instance
141
131
  */
142
132
  createTelemetryClient(sampleRate) {
143
- let sampleRateNumer;
133
+ let sampleRateNumber;
144
134
  switch (sampleRate) {
145
135
  case SampleRate.OnePercent:
146
- sampleRateNumer = 1;
136
+ sampleRateNumber = 1;
147
137
  break;
148
138
  case SampleRate.TenPercent:
149
- sampleRateNumer = 10;
139
+ sampleRateNumber = 10;
150
140
  break;
151
141
  case SampleRate.NoSampling:
152
142
  default:
153
- sampleRateNumer = 100;
143
+ sampleRateNumber = 100;
154
144
  break;
155
145
  }
156
146
  const client = new appInsights.TelemetryClient(this.applicationKey);
157
- client.config.samplingPercentage = sampleRateNumer;
147
+ client.config.samplingPercentage = sampleRateNumber;
158
148
  configAzureTelemetryClient(client);
159
149
  return client;
160
150
  }
@@ -19,6 +19,7 @@ declare class ClientFactory {
19
19
  * @returns Subclass of telemetry Client class
20
20
  */
21
21
  static getTelemetryClientByClass<T extends Client>(clientConstructor: new (appKey: string, extensionName: string, extensionVersion: string) => T): T;
22
+ private static buildConnectionString;
22
23
  }
23
24
  export { ClientFactory };
24
25
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { ToolsSuiteTelemetryClient } from '../../tooling-telemetry/index.js';
2
2
  import { TelemetrySettings } from '../config-state.js';
3
+ const instrumentationKeyPlaceholder = 'ApplicationInsightsInstrumentationKeyPLACEH0LDER';
3
4
  /**
4
5
  * Factory to get telemetry client instance.
5
6
  */
@@ -25,11 +26,19 @@ class ClientFactory {
25
26
  if (client) {
26
27
  return client;
27
28
  }
28
- const ClientConstructor = clientConstructor;
29
- client = new ClientConstructor(TelemetrySettings.azureInstrumentationKey, TelemetrySettings.consumerModuleName, TelemetrySettings.consumerModuleVersion);
29
+ const connectionString = ClientFactory.buildConnectionString(TelemetrySettings.azureInstrumentationKey);
30
+ client = new clientConstructor(connectionString, TelemetrySettings.consumerModuleName, TelemetrySettings.consumerModuleVersion);
30
31
  ClientFactory.clientMap.set(clientConstructor.name, client);
31
32
  return client;
32
33
  }
34
+ static buildConnectionString(key) {
35
+ if (!key) {
36
+ return '';
37
+ }
38
+ // ApplicationInsights v3+ requires InstrumentationKey=<uuid> format
39
+ const instrumentationKey = key === instrumentationKeyPlaceholder ? '00000000-0000-0000-0000-000000000000' : key;
40
+ return `InstrumentationKey=${instrumentationKey}`;
41
+ }
33
42
  }
34
43
  export { ClientFactory };
35
44
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
+ // import type { TelemetryItem } from 'applicationinsights'; // not exported
1
2
  /**
2
3
  * Enable local caching of telemetry data when offline.
3
4
  * Disable GDPR private data that are collected by Azure AppInsight client.
@@ -5,8 +6,16 @@
5
6
  * @param client Azure App Insights telemetry client instance
6
7
  */
7
8
  export function configAzureTelemetryClient(client) {
8
- client.channel.setUseDiskRetryCaching(true);
9
- client.addTelemetryProcessor((envelope) => {
9
+ if (client.setUseDiskRetryCaching) {
10
+ try {
11
+ client.setUseDiskRetryCaching(true);
12
+ }
13
+ catch {
14
+ // setUseDiskRetryCaching may throw "Not implemented"
15
+ }
16
+ }
17
+ client.addTelemetryProcessor((envelope /* TelemetryItem */) => {
18
+ envelope.tags ??= {};
10
19
  envelope.tags['ai.location.ip'] = '0.0.0.0';
11
20
  envelope.tags['ai.cloud.roleInstance'] = 'masked';
12
21
  envelope.tags['ai.cloud.role'] = 'masked';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/telemetry",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Library for sending usage telemetry data",
5
5
  "type": "module",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "private": false,
16
16
  "main": "dist/index.js",
17
17
  "dependencies": {
18
- "applicationinsights": "2.9.8",
18
+ "applicationinsights": "3.15.0",
19
19
  "axios": "1.16.0",
20
20
  "performance-now": "2.1.0",
21
21
  "yaml": "2.8.3",