@sap-ux/telemetry 1.0.25 → 2.0.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.
@@ -35,9 +35,16 @@ class ClientFactory {
35
35
  if (!key) {
36
36
  return '';
37
37
  }
38
- // ApplicationInsights v3+ requires InstrumentationKey=<uuid> format
38
+ // ApplicationInsights v3+ requires InstrumentationKey=<uuid> format.
39
+ // The IngestionEndpoint/LiveEndpoint must be set explicitly: the @azure/monitor-opentelemetry-exporter
40
+ // (>= 1.0.0-beta.44, pulled in by applicationinsights 3.16.0) refuses to follow the global endpoint's
41
+ // cross-origin 307/308 redirect to the regional endpoint (isSameRegisteredDomain guard), so a bare
42
+ // InstrumentationKey would silently drop all telemetry. The endpoints default to the westus2 region
43
+ // and can be overridden by the consumer via initTelemetrySettings.
39
44
  const instrumentationKey = key === instrumentationKeyPlaceholder ? '00000000-0000-0000-0000-000000000000' : key;
40
- return `InstrumentationKey=${instrumentationKey}`;
45
+ return (`InstrumentationKey=${instrumentationKey};` +
46
+ `IngestionEndpoint=${TelemetrySettings.azureIngestionEndpoint};` +
47
+ `LiveEndpoint=${TelemetrySettings.azureLiveEndpoint};`);
41
48
  }
42
49
  }
43
50
  export { ClientFactory };
@@ -3,6 +3,8 @@
3
3
  */
4
4
  export declare const TelemetrySettings: {
5
5
  azureInstrumentationKey: string;
6
+ azureIngestionEndpoint: string;
7
+ azureLiveEndpoint: string;
6
8
  telemetryEnabled: boolean;
7
9
  telemetryLibName: string;
8
10
  telemetryLibVersion: string;
@@ -5,6 +5,12 @@ import packageJson from '../../package.json' with { type: 'json' };
5
5
  export const TelemetrySettings = {
6
6
  // Target Azure apps insight destination
7
7
  azureInstrumentationKey: '',
8
+ // Regional Azure App Insights ingestion endpoint. Must be set explicitly because the
9
+ // @azure/monitor-opentelemetry-exporter (>= 1.0.0-beta.44) refuses to follow the global
10
+ // endpoint's cross-origin redirect to the regional endpoint. Consumers may override this default.
11
+ azureIngestionEndpoint: 'https://westus2-0.in.applicationinsights.azure.com/',
12
+ // Regional Azure App Insights live-metrics endpoint. Consumers may override this default.
13
+ azureLiveEndpoint: 'https://westus2.livediagnostics.monitor.azure.com/',
8
14
  // Allow user to opt out from telemetry collection
9
15
  telemetryEnabled: true,
10
16
  // Module name in telemetry/pacakge.json
@@ -1,4 +1,8 @@
1
1
  // import type { TelemetryItem } from 'applicationinsights'; // not exported
2
+ // Mask OTEL resource attributes that become cloud_RoleName / cloud_RoleInstance in Azure Portal.
3
+ // Must be set before the first TelemetryClient.initialize() call (which happens lazily on first trackEvent).
4
+ // applicationinsights v3 reads these via envDetector during initialize(); context.tags has no effect on them.
5
+ process.env.OTEL_RESOURCE_ATTRIBUTES ??= 'service.name=masked,service.instance.id=masked';
2
6
  /**
3
7
  * Enable local caching of telemetry data when offline.
4
8
  * Disable GDPR private data that are collected by Azure AppInsight client.
@@ -14,13 +18,11 @@ export function configAzureTelemetryClient(client) {
14
18
  // setUseDiskRetryCaching may throw "Not implemented"
15
19
  }
16
20
  }
17
- client.addTelemetryProcessor((envelope /* TelemetryItem */) => {
18
- envelope.tags ??= {};
19
- envelope.tags['ai.location.ip'] = '0.0.0.0';
20
- envelope.tags['ai.cloud.roleInstance'] = 'masked';
21
- envelope.tags['ai.cloud.role'] = 'masked';
22
- envelope.tags['ai.device.type'] = 'masked';
23
- return true;
24
- });
21
+ client.context.tags ??= {};
22
+ client.context.tags['ai.location.ip'] = '0.0.0.0';
23
+ client.context.tags['microsoft.client.ip'] = '0.0.0.0';
24
+ client.context.tags['ai.cloud.roleInstance'] = 'masked';
25
+ client.context.tags['ai.cloud.role'] = 'masked';
26
+ client.context.tags['ai.device.type'] = 'masked';
25
27
  }
26
28
  //# sourceMappingURL=azure-client-config.js.map
@@ -105,6 +105,12 @@ export const initTelemetrySettings = async (options) => {
105
105
  if (options.resourceId) {
106
106
  TelemetrySettings.azureInstrumentationKey = options.resourceId;
107
107
  }
108
+ if (options.ingestionEndpoint) {
109
+ TelemetrySettings.azureIngestionEndpoint = options.ingestionEndpoint;
110
+ }
111
+ if (options.liveEndpoint) {
112
+ TelemetrySettings.azureLiveEndpoint = options.liveEndpoint;
113
+ }
108
114
  const storeService = await getService({
109
115
  entityName: 'telemetrySetting'
110
116
  });
@@ -11,6 +11,8 @@ export type TelemetryHelperProperties = {
11
11
  * - internalFeature: if UX tooling InternalFeature is enabled
12
12
  * - watchTelemetrySettingStore: watch changes to telemetry setting in the store and update runtime settings accordingly (recommended for extensions)
13
13
  * - resourceId: Id of cloud telemetry resource (e.g. Azure application insights resource is supported).
14
+ * - ingestionEndpoint: override the default Azure App Insights regional ingestion endpoint.
15
+ * - liveEndpoint: override the default Azure App Insights regional live-metrics endpoint.
14
16
  *
15
17
  */
16
18
  export type ToolsSuiteTelemetryInitSettings = {
@@ -18,6 +20,8 @@ export type ToolsSuiteTelemetryInitSettings = {
18
20
  internalFeature: boolean;
19
21
  watchTelemetrySettingStore: boolean;
20
22
  resourceId?: string;
23
+ ingestionEndpoint?: string;
24
+ liveEndpoint?: string;
21
25
  };
22
26
  export declare enum ToolsId {
23
27
  UNKNOWN = "UNKNOWN",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/telemetry",
3
- "version": "1.0.25",
3
+ "version": "2.0.0",
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": "3.15.1",
18
+ "applicationinsights": "3.16.0",
19
19
  "axios": "1.18.1",
20
20
  "performance-now": "2.1.0",
21
21
  "yaml": "2.9.0",