@microsoft/power-apps-native-common 0.1.8 → 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.
- package/lib/NOTICE.txt +31 -5
- package/lib/commonjs/http/HttpClient.js +83 -0
- package/lib/commonjs/http/index.js +18 -0
- package/lib/commonjs/index.js +33 -0
- package/lib/commonjs/telemetry/AppLogger.js +15 -2
- package/lib/commonjs/telemetry/ApplicationInsightsTelemetryProvider.js +128 -0
- package/lib/commonjs/telemetry/CustomerTelemetryLogger.js +56 -0
- package/lib/module/http/HttpClient.js +77 -0
- package/lib/module/http/index.js +3 -0
- package/lib/module/index.js +3 -0
- package/lib/module/telemetry/AppLogger.js +15 -2
- package/lib/module/telemetry/ApplicationInsightsTelemetryProvider.js +123 -0
- package/lib/module/telemetry/CustomerTelemetryLogger.js +51 -0
- package/lib/typescript/commonjs/http/HttpClient.d.ts +8 -0
- package/lib/typescript/commonjs/http/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts +5 -1
- package/lib/typescript/commonjs/telemetry/ApplicationInsightsTelemetryProvider.d.ts +31 -0
- package/lib/typescript/commonjs/telemetry/CustomerTelemetryLogger.d.ts +21 -0
- package/lib/typescript/commonjs/telemetry/TelemetryTypes.d.ts +21 -0
- package/lib/typescript/module/http/HttpClient.d.ts +8 -0
- package/lib/typescript/module/http/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts +5 -1
- package/lib/typescript/module/telemetry/ApplicationInsightsTelemetryProvider.d.ts +31 -0
- package/lib/typescript/module/telemetry/CustomerTelemetryLogger.d.ts +21 -0
- package/lib/typescript/module/telemetry/TelemetryTypes.d.ts +21 -0
- package/package.json +14 -1
package/lib/NOTICE.txt
CHANGED
|
@@ -4,7 +4,7 @@ This repository incorporates material as listed below or described in the code.
|
|
|
4
4
|
|
|
5
5
|
========================================================================
|
|
6
6
|
|
|
7
|
-
@microsoft/1ds-
|
|
7
|
+
@microsoft/1ds-post-js 4.4.1
|
|
8
8
|
--
|
|
9
9
|
The MIT License (MIT)
|
|
10
10
|
|
|
@@ -30,7 +30,7 @@ SOFTWARE.
|
|
|
30
30
|
|
|
31
31
|
========================================================================
|
|
32
32
|
|
|
33
|
-
@microsoft/
|
|
33
|
+
@microsoft/applicationinsights-core-js 3.4.3
|
|
34
34
|
--
|
|
35
35
|
The MIT License (MIT)
|
|
36
36
|
|
|
@@ -56,7 +56,7 @@ SOFTWARE.
|
|
|
56
56
|
|
|
57
57
|
========================================================================
|
|
58
58
|
|
|
59
|
-
@microsoft/applicationinsights-
|
|
59
|
+
@microsoft/applicationinsights-react-native 4.4.1
|
|
60
60
|
--
|
|
61
61
|
The MIT License (MIT)
|
|
62
62
|
|
|
@@ -108,13 +108,39 @@ SOFTWARE.
|
|
|
108
108
|
|
|
109
109
|
========================================================================
|
|
110
110
|
|
|
111
|
+
@microsoft/applicationinsights-web 3.4.3
|
|
112
|
+
--
|
|
113
|
+
The MIT License (MIT)
|
|
114
|
+
|
|
115
|
+
Copyright (c) Microsoft Corporation
|
|
116
|
+
|
|
117
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
118
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
119
|
+
in the Software without restriction, including without limitation the rights
|
|
120
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
121
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
122
|
+
furnished to do so, subject to the following conditions:
|
|
123
|
+
|
|
124
|
+
The above copyright notice and this permission notice shall be included in all
|
|
125
|
+
copies or substantial portions of the Software.
|
|
126
|
+
|
|
127
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
128
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
129
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
130
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
131
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
132
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
133
|
+
SOFTWARE.
|
|
134
|
+
|
|
135
|
+
========================================================================
|
|
136
|
+
|
|
111
137
|
@microsoft/dynamicproto-js 2.0.5
|
|
112
138
|
--
|
|
113
139
|
Copyright Microsoft Application Insights Team; licensed under MIT (https://spdx.org/licenses/MIT.html)
|
|
114
140
|
|
|
115
141
|
========================================================================
|
|
116
142
|
|
|
117
|
-
@nevware21/ts-async 0.
|
|
143
|
+
@nevware21/ts-async 0.5.5
|
|
118
144
|
--
|
|
119
145
|
MIT License
|
|
120
146
|
|
|
@@ -140,7 +166,7 @@ SOFTWARE.
|
|
|
140
166
|
|
|
141
167
|
========================================================================
|
|
142
168
|
|
|
143
|
-
@nevware21/ts-utils 0.
|
|
169
|
+
@nevware21/ts-utils 0.16.0
|
|
144
170
|
--
|
|
145
171
|
MIT License
|
|
146
172
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HttpClient = void 0;
|
|
7
|
+
exports.getHttpCorrelationProperties = getHttpCorrelationProperties;
|
|
8
|
+
var _AppLogger = require("../telemetry/AppLogger.js");
|
|
9
|
+
var _TelemetrySanitizer = require("../telemetry/TelemetrySanitizer.js");
|
|
10
|
+
const CORRELATION_HEADERS = [['x-ms-request-id', 'xMsRequestId'], ['x-ms-service-request-id', 'xMsServiceRequestId'], ['request-id', 'requestId'], ['x-ms-client-request-id', 'xMsClientRequestId'], ['x-ms-correlation-request-id', 'xMsCorrelationRequestId'], ['x-ms-activity-id', 'xMsActivityId']];
|
|
11
|
+
const OPAQUE_CORRELATION_ID = /^(?:[0-9a-f]{16,64}|[0-9a-f]{8}-[0-9a-f-]{27,})(?:[:/.-][0-9a-f]+)*$/i;
|
|
12
|
+
const TELEMETRY_URL_BASE = 'https://telemetry.invalid';
|
|
13
|
+
function getTelemetryPath(url) {
|
|
14
|
+
try {
|
|
15
|
+
const pathname = new URL(url, TELEMETRY_URL_BASE).pathname;
|
|
16
|
+
let decodedPathname = pathname;
|
|
17
|
+
try {
|
|
18
|
+
decodedPathname = decodeURIComponent(pathname);
|
|
19
|
+
} catch {
|
|
20
|
+
// Keep the encoded pathname when it contains malformed escape sequences.
|
|
21
|
+
}
|
|
22
|
+
return (0, _TelemetrySanitizer.sanitizeErrorString)(decodedPathname).slice(0, 200);
|
|
23
|
+
} catch {
|
|
24
|
+
return '<invalid-url>';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isDevelopment() {
|
|
28
|
+
return globalThis.__DEV__ === true;
|
|
29
|
+
}
|
|
30
|
+
async function logFailedResponse(operationName, method, path, response, shouldLogToConsole) {
|
|
31
|
+
if (!shouldLogToConsole()) return;
|
|
32
|
+
try {
|
|
33
|
+
const body = await response.clone().text();
|
|
34
|
+
console.warn(`[${operationName}] HTTP ${response.status} for ${method} ${path} | res: ${body.slice(0, 1000)}`);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(`[${operationName}] HTTP ${response.status} for ${method} ${path} | failed to read response body:`, error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getHttpCorrelationProperties(headers) {
|
|
40
|
+
const properties = {};
|
|
41
|
+
for (const [headerName, propertyName] of CORRELATION_HEADERS) {
|
|
42
|
+
const value = headers.get(headerName);
|
|
43
|
+
if (value && value.length <= 256 && OPAQUE_CORRELATION_ID.test(value)) {
|
|
44
|
+
properties[propertyName] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return properties;
|
|
48
|
+
}
|
|
49
|
+
class HttpClient {
|
|
50
|
+
constructor(operationName, shouldLogToConsole = isDevelopment) {
|
|
51
|
+
this.operationName = operationName;
|
|
52
|
+
this.shouldLogToConsole = shouldLogToConsole;
|
|
53
|
+
}
|
|
54
|
+
async request(url, init) {
|
|
55
|
+
const method = init?.method ?? 'GET';
|
|
56
|
+
const path = getTelemetryPath(url);
|
|
57
|
+
const scenario = (0, _AppLogger.getAppLogger)().trackScenario(this.operationName, {
|
|
58
|
+
httpMethod: method,
|
|
59
|
+
url: path
|
|
60
|
+
});
|
|
61
|
+
try {
|
|
62
|
+
const response = await globalThis.fetch(url, init);
|
|
63
|
+
const properties = {
|
|
64
|
+
httpStatus: response.status,
|
|
65
|
+
...getHttpCorrelationProperties(response.headers)
|
|
66
|
+
};
|
|
67
|
+
if (response.ok) scenario.complete(properties);else {
|
|
68
|
+
scenario.completeWithError(properties);
|
|
69
|
+
await logFailedResponse(this.operationName, method, path, response, this.shouldLogToConsole);
|
|
70
|
+
}
|
|
71
|
+
return response;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
scenario.fail(undefined, {
|
|
74
|
+
errorName: error instanceof Error ? error.constructor.name : typeof error
|
|
75
|
+
});
|
|
76
|
+
if (this.shouldLogToConsole()) {
|
|
77
|
+
console.warn(`[${this.operationName}] fetch THREW for ${method} ${path}:`, error);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "HttpClient", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _HttpClient.HttpClient;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getHttpCorrelationProperties", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _HttpClient.getHttpCorrelationProperties;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _HttpClient = require("./HttpClient.js");
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,12 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ApplicationInsightsTelemetryProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ApplicationInsightsTelemetryProvider.ApplicationInsightsTelemetryProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "ConsoleAdapter", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
9
15
|
return _ConsoleAdapter.ConsoleAdapter;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "HttpClient", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _HttpClient.HttpClient;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
Object.defineProperty(exports, "Logger", {
|
|
13
25
|
enumerable: true,
|
|
14
26
|
get: function () {
|
|
@@ -45,12 +57,30 @@ Object.defineProperty(exports, "configureAppLogger", {
|
|
|
45
57
|
return _AppLogger.configureAppLogger;
|
|
46
58
|
}
|
|
47
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "configureCustomerTelemetryLogger", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _CustomerTelemetryLogger.configureCustomerTelemetryLogger;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
48
66
|
Object.defineProperty(exports, "getAppLogger", {
|
|
49
67
|
enumerable: true,
|
|
50
68
|
get: function () {
|
|
51
69
|
return _AppLogger.getAppLogger;
|
|
52
70
|
}
|
|
53
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "getCustomerTelemetryLogger", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _CustomerTelemetryLogger.getCustomerTelemetryLogger;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "getHttpCorrelationProperties", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _HttpClient.getHttpCorrelationProperties;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
54
84
|
Object.defineProperty(exports, "regionToClusterCategory", {
|
|
55
85
|
enumerable: true,
|
|
56
86
|
get: function () {
|
|
@@ -102,11 +132,14 @@ Object.defineProperty(exports, "suppressKnownWarnings", {
|
|
|
102
132
|
var _ConsoleAdapter = require("./telemetry/ConsoleAdapter.js");
|
|
103
133
|
var _Logger = require("./telemetry/Logger.js");
|
|
104
134
|
var _OneDsTelemetryProvider = require("./telemetry/OneDsTelemetryProvider.js");
|
|
135
|
+
var _ApplicationInsightsTelemetryProvider = require("./telemetry/ApplicationInsightsTelemetryProvider.js");
|
|
105
136
|
var _resolveTelemetryLocation = require("./telemetry/resolveTelemetryLocation.js");
|
|
106
137
|
var _stringifyError = require("./telemetry/stringifyError.js");
|
|
107
138
|
var _TelemetrySanitizer = require("./telemetry/TelemetrySanitizer.js");
|
|
108
139
|
var _suppressKnownWarnings = require("./telemetry/suppressKnownWarnings.js");
|
|
140
|
+
var _HttpClient = require("./http/HttpClient.js");
|
|
109
141
|
var _DeviceIdUtils = require("./utils/DeviceIdUtils.js");
|
|
110
142
|
var _AppLogger = require("./telemetry/AppLogger.js");
|
|
143
|
+
var _CustomerTelemetryLogger = require("./telemetry/CustomerTelemetryLogger.js");
|
|
111
144
|
var _TelemetryTypes = require("./telemetry/TelemetryTypes.js");
|
|
112
145
|
var _ClusterCategory = require("./types/ClusterCategory.js");
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.configureAppLogger = configureAppLogger;
|
|
7
7
|
exports.getAppLogger = getAppLogger;
|
|
8
|
-
var _Logger = require("./Logger.js");
|
|
9
8
|
/*!
|
|
10
9
|
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
11
10
|
*
|
|
@@ -29,7 +28,21 @@ var _Logger = require("./Logger.js");
|
|
|
29
28
|
* configureAppLogger(new Logger({ providers: [myProvider] }));
|
|
30
29
|
*/
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
const noopLogger = {
|
|
32
|
+
trackActivityEvent: () => {},
|
|
33
|
+
trackVerboseEvent: () => {},
|
|
34
|
+
trackErrorEvent: () => {},
|
|
35
|
+
trackScenario: () => ({
|
|
36
|
+
complete: () => {},
|
|
37
|
+
completeWithError: () => {},
|
|
38
|
+
fail: () => {}
|
|
39
|
+
}),
|
|
40
|
+
setDefaultProperty: () => {},
|
|
41
|
+
identifyUser: () => {},
|
|
42
|
+
sessionId: undefined,
|
|
43
|
+
flush: async () => {}
|
|
44
|
+
};
|
|
45
|
+
let _logger = noopLogger;
|
|
33
46
|
|
|
34
47
|
/**
|
|
35
48
|
* Replace the shared app logger with a configured instance.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ApplicationInsightsTelemetryProvider = void 0;
|
|
7
|
+
var _applicationinsightsWeb = require("@microsoft/applicationinsights-web");
|
|
8
|
+
var _manual = require("@microsoft/applicationinsights-react-native/manual");
|
|
9
|
+
var _reactNative = require("react-native");
|
|
10
|
+
var _PlatformInfoUtils = require("../utils/PlatformInfoUtils.js");
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Application Insights adapter for customer-owned mobile-app telemetry.
|
|
17
|
+
*
|
|
18
|
+
* The Microsoft React Native manual-device plugin avoids a dependency on
|
|
19
|
+
* react-native-device-info, which is important for apps loaded by the fixed
|
|
20
|
+
* Power Apps Dev Player binary.
|
|
21
|
+
*/
|
|
22
|
+
class ApplicationInsightsTelemetryProvider {
|
|
23
|
+
defaultProperties = {};
|
|
24
|
+
constructor(config) {
|
|
25
|
+
const connectionString = config.connectionString.trim();
|
|
26
|
+
if (!connectionString) {
|
|
27
|
+
throw new Error('Application Insights connection string is required.');
|
|
28
|
+
}
|
|
29
|
+
if (!config.appId.trim()) {
|
|
30
|
+
throw new Error('Application Insights appId is required.');
|
|
31
|
+
}
|
|
32
|
+
this.appId = config.appId.trim();
|
|
33
|
+
this.appVersion = config.appVersion?.trim() || undefined;
|
|
34
|
+
this.environment = config.environment?.trim() || undefined;
|
|
35
|
+
this.includeUserId = config.includeUserId ?? false;
|
|
36
|
+
this.minSeverity = config.minSeverity ?? 'info';
|
|
37
|
+
this._sessionId = config.sessionId;
|
|
38
|
+
const platform = (0, _PlatformInfoUtils.resolvePlatformInfo)();
|
|
39
|
+
const extensions = [];
|
|
40
|
+
if (_reactNative.Platform.OS === 'ios' || _reactNative.Platform.OS === 'android') {
|
|
41
|
+
const reactNativePlugin = new _manual.ReactNativeManualDevicePlugin();
|
|
42
|
+
reactNativePlugin.setDeviceInfoModule({
|
|
43
|
+
getModel: () => platform.deviceModel || 'unknown',
|
|
44
|
+
getDeviceType: () => platform.deviceType || 'unknown',
|
|
45
|
+
getUniqueId: () => config.deviceId
|
|
46
|
+
});
|
|
47
|
+
extensions.push(reactNativePlugin);
|
|
48
|
+
}
|
|
49
|
+
this.client = new _applicationinsightsWeb.ApplicationInsights({
|
|
50
|
+
config: {
|
|
51
|
+
connectionString,
|
|
52
|
+
extensions,
|
|
53
|
+
disableCookiesUsage: true,
|
|
54
|
+
disableAjaxTracking: true,
|
|
55
|
+
disableFetchTracking: true,
|
|
56
|
+
disableExceptionTracking: true,
|
|
57
|
+
enableAutoRouteTracking: false
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.client.loadAppInsights();
|
|
61
|
+
}
|
|
62
|
+
track(event) {
|
|
63
|
+
const properties = {
|
|
64
|
+
...this.defaultProperties,
|
|
65
|
+
...event.properties,
|
|
66
|
+
app_id: this.appId,
|
|
67
|
+
session_id: this._sessionId,
|
|
68
|
+
event_name: event.eventName,
|
|
69
|
+
sequence_number: event.sequenceNumber,
|
|
70
|
+
severity: event.severity,
|
|
71
|
+
timestamp: event.timestamp
|
|
72
|
+
};
|
|
73
|
+
if (this.appVersion) properties.app_version = this.appVersion;
|
|
74
|
+
if (this.environment) properties.deployment_environment = this.environment;
|
|
75
|
+
if (this.tenantId) properties.tenant_id = this.tenantId;
|
|
76
|
+
const operationName = String(event.properties.operationName ?? event.eventName);
|
|
77
|
+
switch (event.severity) {
|
|
78
|
+
case 'error':
|
|
79
|
+
this.client.trackException({
|
|
80
|
+
exception: new Error(String(event.properties.error ?? operationName)),
|
|
81
|
+
severityLevel: _applicationinsightsWeb.SeverityLevel.Error
|
|
82
|
+
}, properties);
|
|
83
|
+
break;
|
|
84
|
+
case 'warning':
|
|
85
|
+
this.client.trackTrace({
|
|
86
|
+
message: operationName,
|
|
87
|
+
severityLevel: _applicationinsightsWeb.SeverityLevel.Warning
|
|
88
|
+
}, properties);
|
|
89
|
+
break;
|
|
90
|
+
case 'verbose':
|
|
91
|
+
this.client.trackTrace({
|
|
92
|
+
message: operationName,
|
|
93
|
+
severityLevel: _applicationinsightsWeb.SeverityLevel.Verbose
|
|
94
|
+
}, properties);
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
this.client.trackEvent({
|
|
98
|
+
name: operationName
|
|
99
|
+
}, properties);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async flush() {
|
|
104
|
+
const result = this.client.flush(true);
|
|
105
|
+
if (result && typeof result.then === 'function') {
|
|
106
|
+
await result;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async teardown() {
|
|
110
|
+
await this.flush();
|
|
111
|
+
}
|
|
112
|
+
get sessionId() {
|
|
113
|
+
return this._sessionId;
|
|
114
|
+
}
|
|
115
|
+
set sessionId(value) {
|
|
116
|
+
this._sessionId = value;
|
|
117
|
+
}
|
|
118
|
+
identifyUser(identity) {
|
|
119
|
+
this.tenantId = identity.tenantId;
|
|
120
|
+
if (this.includeUserId) {
|
|
121
|
+
this.client.setAuthenticatedUserContext(identity.objectId, identity.tenantId, false);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
setDefaultProperty(name, value) {
|
|
125
|
+
this.defaultProperties[name] = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.ApplicationInsightsTelemetryProvider = ApplicationInsightsTelemetryProvider;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.configureCustomerTelemetryLogger = configureCustomerTelemetryLogger;
|
|
7
|
+
exports.getCustomerTelemetryLogger = getCustomerTelemetryLogger;
|
|
8
|
+
var _Logger = require("./Logger.js");
|
|
9
|
+
var _stringifyError = require("./stringifyError.js");
|
|
10
|
+
/*!
|
|
11
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class CustomerTelemetryLogger {
|
|
15
|
+
constructor(logger) {
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
}
|
|
18
|
+
trackEvent(name, properties) {
|
|
19
|
+
this.logger.trackActivityEvent(name, this.withCustomerSource(properties));
|
|
20
|
+
}
|
|
21
|
+
trackError(name, error, properties) {
|
|
22
|
+
this.logger.trackErrorEvent(name, this.withCustomerSource({
|
|
23
|
+
...properties,
|
|
24
|
+
error: error === undefined ? undefined : (0, _stringifyError.stringifyError)(error)
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
trackScenario(name, properties) {
|
|
28
|
+
return this.logger.trackScenario(name, this.withCustomerSource(properties));
|
|
29
|
+
}
|
|
30
|
+
flush() {
|
|
31
|
+
return this.logger.flush();
|
|
32
|
+
}
|
|
33
|
+
withCustomerSource(properties) {
|
|
34
|
+
return {
|
|
35
|
+
...properties,
|
|
36
|
+
telemetry_source: 'customer'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let customerTelemetryLogger = new CustomerTelemetryLogger(new _Logger.Logger());
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Configures the customer telemetry singleton. Hosting infrastructure owns
|
|
44
|
+
* this function; application code should use getCustomerTelemetryLogger().
|
|
45
|
+
*/
|
|
46
|
+
function configureCustomerTelemetryLogger(logger) {
|
|
47
|
+
customerTelemetryLogger = new CustomerTelemetryLogger(logger);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the customer-owned telemetry logger. It is a safe no-op until the
|
|
52
|
+
* host configures an Application Insights provider.
|
|
53
|
+
*/
|
|
54
|
+
function getCustomerTelemetryLogger() {
|
|
55
|
+
return customerTelemetryLogger;
|
|
56
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { getAppLogger } from "../telemetry/AppLogger.js";
|
|
4
|
+
import { sanitizeErrorString } from "../telemetry/TelemetrySanitizer.js";
|
|
5
|
+
const CORRELATION_HEADERS = [['x-ms-request-id', 'xMsRequestId'], ['x-ms-service-request-id', 'xMsServiceRequestId'], ['request-id', 'requestId'], ['x-ms-client-request-id', 'xMsClientRequestId'], ['x-ms-correlation-request-id', 'xMsCorrelationRequestId'], ['x-ms-activity-id', 'xMsActivityId']];
|
|
6
|
+
const OPAQUE_CORRELATION_ID = /^(?:[0-9a-f]{16,64}|[0-9a-f]{8}-[0-9a-f-]{27,})(?:[:/.-][0-9a-f]+)*$/i;
|
|
7
|
+
const TELEMETRY_URL_BASE = 'https://telemetry.invalid';
|
|
8
|
+
function getTelemetryPath(url) {
|
|
9
|
+
try {
|
|
10
|
+
const pathname = new URL(url, TELEMETRY_URL_BASE).pathname;
|
|
11
|
+
let decodedPathname = pathname;
|
|
12
|
+
try {
|
|
13
|
+
decodedPathname = decodeURIComponent(pathname);
|
|
14
|
+
} catch {
|
|
15
|
+
// Keep the encoded pathname when it contains malformed escape sequences.
|
|
16
|
+
}
|
|
17
|
+
return sanitizeErrorString(decodedPathname).slice(0, 200);
|
|
18
|
+
} catch {
|
|
19
|
+
return '<invalid-url>';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isDevelopment() {
|
|
23
|
+
return globalThis.__DEV__ === true;
|
|
24
|
+
}
|
|
25
|
+
async function logFailedResponse(operationName, method, path, response, shouldLogToConsole) {
|
|
26
|
+
if (!shouldLogToConsole()) return;
|
|
27
|
+
try {
|
|
28
|
+
const body = await response.clone().text();
|
|
29
|
+
console.warn(`[${operationName}] HTTP ${response.status} for ${method} ${path} | res: ${body.slice(0, 1000)}`);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn(`[${operationName}] HTTP ${response.status} for ${method} ${path} | failed to read response body:`, error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function getHttpCorrelationProperties(headers) {
|
|
35
|
+
const properties = {};
|
|
36
|
+
for (const [headerName, propertyName] of CORRELATION_HEADERS) {
|
|
37
|
+
const value = headers.get(headerName);
|
|
38
|
+
if (value && value.length <= 256 && OPAQUE_CORRELATION_ID.test(value)) {
|
|
39
|
+
properties[propertyName] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return properties;
|
|
43
|
+
}
|
|
44
|
+
export class HttpClient {
|
|
45
|
+
constructor(operationName, shouldLogToConsole = isDevelopment) {
|
|
46
|
+
this.operationName = operationName;
|
|
47
|
+
this.shouldLogToConsole = shouldLogToConsole;
|
|
48
|
+
}
|
|
49
|
+
async request(url, init) {
|
|
50
|
+
const method = init?.method ?? 'GET';
|
|
51
|
+
const path = getTelemetryPath(url);
|
|
52
|
+
const scenario = getAppLogger().trackScenario(this.operationName, {
|
|
53
|
+
httpMethod: method,
|
|
54
|
+
url: path
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
const response = await globalThis.fetch(url, init);
|
|
58
|
+
const properties = {
|
|
59
|
+
httpStatus: response.status,
|
|
60
|
+
...getHttpCorrelationProperties(response.headers)
|
|
61
|
+
};
|
|
62
|
+
if (response.ok) scenario.complete(properties);else {
|
|
63
|
+
scenario.completeWithError(properties);
|
|
64
|
+
await logFailedResponse(this.operationName, method, path, response, this.shouldLogToConsole);
|
|
65
|
+
}
|
|
66
|
+
return response;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
scenario.fail(undefined, {
|
|
69
|
+
errorName: error instanceof Error ? error.constructor.name : typeof error
|
|
70
|
+
});
|
|
71
|
+
if (this.shouldLogToConsole()) {
|
|
72
|
+
console.warn(`[${this.operationName}] fetch THREW for ${method} ${path}:`, error);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
export { ConsoleAdapter } from "./telemetry/ConsoleAdapter.js";
|
|
9
9
|
export { Logger } from "./telemetry/Logger.js";
|
|
10
10
|
export { OneDsTelemetryProvider } from "./telemetry/OneDsTelemetryProvider.js";
|
|
11
|
+
export { ApplicationInsightsTelemetryProvider } from "./telemetry/ApplicationInsightsTelemetryProvider.js";
|
|
11
12
|
export { resolveTelemetryLocation } from "./telemetry/resolveTelemetryLocation.js";
|
|
12
13
|
export { stringifyError } from "./telemetry/stringifyError.js";
|
|
13
14
|
export { sanitizeErrorString, sanitizeUrl, sanitizeProperties } from "./telemetry/TelemetrySanitizer.js";
|
|
14
15
|
export { suppressKnownWarnings } from "./telemetry/suppressKnownWarnings.js";
|
|
16
|
+
export { HttpClient, getHttpCorrelationProperties } from "./http/HttpClient.js";
|
|
15
17
|
export { resolveDeviceId } from "./utils/DeviceIdUtils.js";
|
|
16
18
|
export { configureAppLogger, getAppLogger } from "./telemetry/AppLogger.js";
|
|
19
|
+
export { configureCustomerTelemetryLogger, getCustomerTelemetryLogger } from "./telemetry/CustomerTelemetryLogger.js";
|
|
17
20
|
export { ScenarioResults, TelemetryEventNames } from "./telemetry/TelemetryTypes.js";
|
|
18
21
|
export { Regions, regionToClusterCategory } from "./types/ClusterCategory.js";
|
|
@@ -23,8 +23,21 @@
|
|
|
23
23
|
* configureAppLogger(new Logger({ providers: [myProvider] }));
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const noopLogger = {
|
|
27
|
+
trackActivityEvent: () => {},
|
|
28
|
+
trackVerboseEvent: () => {},
|
|
29
|
+
trackErrorEvent: () => {},
|
|
30
|
+
trackScenario: () => ({
|
|
31
|
+
complete: () => {},
|
|
32
|
+
completeWithError: () => {},
|
|
33
|
+
fail: () => {}
|
|
34
|
+
}),
|
|
35
|
+
setDefaultProperty: () => {},
|
|
36
|
+
identifyUser: () => {},
|
|
37
|
+
sessionId: undefined,
|
|
38
|
+
flush: async () => {}
|
|
39
|
+
};
|
|
40
|
+
let _logger = noopLogger;
|
|
28
41
|
|
|
29
42
|
/**
|
|
30
43
|
* Replace the shared app logger with a configured instance.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { ApplicationInsights, SeverityLevel } from '@microsoft/applicationinsights-web';
|
|
8
|
+
import { ReactNativeManualDevicePlugin } from '@microsoft/applicationinsights-react-native/manual';
|
|
9
|
+
import { Platform } from 'react-native';
|
|
10
|
+
import { resolvePlatformInfo } from "../utils/PlatformInfoUtils.js";
|
|
11
|
+
/**
|
|
12
|
+
* Application Insights adapter for customer-owned mobile-app telemetry.
|
|
13
|
+
*
|
|
14
|
+
* The Microsoft React Native manual-device plugin avoids a dependency on
|
|
15
|
+
* react-native-device-info, which is important for apps loaded by the fixed
|
|
16
|
+
* Power Apps Dev Player binary.
|
|
17
|
+
*/
|
|
18
|
+
export class ApplicationInsightsTelemetryProvider {
|
|
19
|
+
defaultProperties = {};
|
|
20
|
+
constructor(config) {
|
|
21
|
+
const connectionString = config.connectionString.trim();
|
|
22
|
+
if (!connectionString) {
|
|
23
|
+
throw new Error('Application Insights connection string is required.');
|
|
24
|
+
}
|
|
25
|
+
if (!config.appId.trim()) {
|
|
26
|
+
throw new Error('Application Insights appId is required.');
|
|
27
|
+
}
|
|
28
|
+
this.appId = config.appId.trim();
|
|
29
|
+
this.appVersion = config.appVersion?.trim() || undefined;
|
|
30
|
+
this.environment = config.environment?.trim() || undefined;
|
|
31
|
+
this.includeUserId = config.includeUserId ?? false;
|
|
32
|
+
this.minSeverity = config.minSeverity ?? 'info';
|
|
33
|
+
this._sessionId = config.sessionId;
|
|
34
|
+
const platform = resolvePlatformInfo();
|
|
35
|
+
const extensions = [];
|
|
36
|
+
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
|
37
|
+
const reactNativePlugin = new ReactNativeManualDevicePlugin();
|
|
38
|
+
reactNativePlugin.setDeviceInfoModule({
|
|
39
|
+
getModel: () => platform.deviceModel || 'unknown',
|
|
40
|
+
getDeviceType: () => platform.deviceType || 'unknown',
|
|
41
|
+
getUniqueId: () => config.deviceId
|
|
42
|
+
});
|
|
43
|
+
extensions.push(reactNativePlugin);
|
|
44
|
+
}
|
|
45
|
+
this.client = new ApplicationInsights({
|
|
46
|
+
config: {
|
|
47
|
+
connectionString,
|
|
48
|
+
extensions,
|
|
49
|
+
disableCookiesUsage: true,
|
|
50
|
+
disableAjaxTracking: true,
|
|
51
|
+
disableFetchTracking: true,
|
|
52
|
+
disableExceptionTracking: true,
|
|
53
|
+
enableAutoRouteTracking: false
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
this.client.loadAppInsights();
|
|
57
|
+
}
|
|
58
|
+
track(event) {
|
|
59
|
+
const properties = {
|
|
60
|
+
...this.defaultProperties,
|
|
61
|
+
...event.properties,
|
|
62
|
+
app_id: this.appId,
|
|
63
|
+
session_id: this._sessionId,
|
|
64
|
+
event_name: event.eventName,
|
|
65
|
+
sequence_number: event.sequenceNumber,
|
|
66
|
+
severity: event.severity,
|
|
67
|
+
timestamp: event.timestamp
|
|
68
|
+
};
|
|
69
|
+
if (this.appVersion) properties.app_version = this.appVersion;
|
|
70
|
+
if (this.environment) properties.deployment_environment = this.environment;
|
|
71
|
+
if (this.tenantId) properties.tenant_id = this.tenantId;
|
|
72
|
+
const operationName = String(event.properties.operationName ?? event.eventName);
|
|
73
|
+
switch (event.severity) {
|
|
74
|
+
case 'error':
|
|
75
|
+
this.client.trackException({
|
|
76
|
+
exception: new Error(String(event.properties.error ?? operationName)),
|
|
77
|
+
severityLevel: SeverityLevel.Error
|
|
78
|
+
}, properties);
|
|
79
|
+
break;
|
|
80
|
+
case 'warning':
|
|
81
|
+
this.client.trackTrace({
|
|
82
|
+
message: operationName,
|
|
83
|
+
severityLevel: SeverityLevel.Warning
|
|
84
|
+
}, properties);
|
|
85
|
+
break;
|
|
86
|
+
case 'verbose':
|
|
87
|
+
this.client.trackTrace({
|
|
88
|
+
message: operationName,
|
|
89
|
+
severityLevel: SeverityLevel.Verbose
|
|
90
|
+
}, properties);
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
this.client.trackEvent({
|
|
94
|
+
name: operationName
|
|
95
|
+
}, properties);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async flush() {
|
|
100
|
+
const result = this.client.flush(true);
|
|
101
|
+
if (result && typeof result.then === 'function') {
|
|
102
|
+
await result;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async teardown() {
|
|
106
|
+
await this.flush();
|
|
107
|
+
}
|
|
108
|
+
get sessionId() {
|
|
109
|
+
return this._sessionId;
|
|
110
|
+
}
|
|
111
|
+
set sessionId(value) {
|
|
112
|
+
this._sessionId = value;
|
|
113
|
+
}
|
|
114
|
+
identifyUser(identity) {
|
|
115
|
+
this.tenantId = identity.tenantId;
|
|
116
|
+
if (this.includeUserId) {
|
|
117
|
+
this.client.setAuthenticatedUserContext(identity.objectId, identity.tenantId, false);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
setDefaultProperty(name, value) {
|
|
121
|
+
this.defaultProperties[name] = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Logger } from "./Logger.js";
|
|
8
|
+
import { stringifyError } from "./stringifyError.js";
|
|
9
|
+
class CustomerTelemetryLogger {
|
|
10
|
+
constructor(logger) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
trackEvent(name, properties) {
|
|
14
|
+
this.logger.trackActivityEvent(name, this.withCustomerSource(properties));
|
|
15
|
+
}
|
|
16
|
+
trackError(name, error, properties) {
|
|
17
|
+
this.logger.trackErrorEvent(name, this.withCustomerSource({
|
|
18
|
+
...properties,
|
|
19
|
+
error: error === undefined ? undefined : stringifyError(error)
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
trackScenario(name, properties) {
|
|
23
|
+
return this.logger.trackScenario(name, this.withCustomerSource(properties));
|
|
24
|
+
}
|
|
25
|
+
flush() {
|
|
26
|
+
return this.logger.flush();
|
|
27
|
+
}
|
|
28
|
+
withCustomerSource(properties) {
|
|
29
|
+
return {
|
|
30
|
+
...properties,
|
|
31
|
+
telemetry_source: 'customer'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let customerTelemetryLogger = new CustomerTelemetryLogger(new Logger());
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configures the customer telemetry singleton. Hosting infrastructure owns
|
|
39
|
+
* this function; application code should use getCustomerTelemetryLogger().
|
|
40
|
+
*/
|
|
41
|
+
export function configureCustomerTelemetryLogger(logger) {
|
|
42
|
+
customerTelemetryLogger = new CustomerTelemetryLogger(logger);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the customer-owned telemetry logger. It is a safe no-op until the
|
|
47
|
+
* host configures an Application Insights provider.
|
|
48
|
+
*/
|
|
49
|
+
export function getCustomerTelemetryLogger() {
|
|
50
|
+
return customerTelemetryLogger;
|
|
51
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function getHttpCorrelationProperties(headers: Pick<Headers, 'get'>): Record<string, string>;
|
|
2
|
+
export declare class HttpClient {
|
|
3
|
+
private readonly operationName;
|
|
4
|
+
private readonly shouldLogToConsole;
|
|
5
|
+
constructor(operationName: string, shouldLogToConsole?: () => boolean);
|
|
6
|
+
request(url: string, init?: RequestInit): Promise<Response>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -6,13 +6,17 @@ export { ConsoleAdapter } from './telemetry/ConsoleAdapter';
|
|
|
6
6
|
export type { ILogger, ScenarioTracker } from './telemetry/ILogger';
|
|
7
7
|
export { Logger } from './telemetry/Logger';
|
|
8
8
|
export { OneDsTelemetryProvider } from './telemetry/OneDsTelemetryProvider';
|
|
9
|
+
export { ApplicationInsightsTelemetryProvider } from './telemetry/ApplicationInsightsTelemetryProvider';
|
|
9
10
|
export { resolveTelemetryLocation } from './telemetry/resolveTelemetryLocation';
|
|
10
11
|
export { stringifyError } from './telemetry/stringifyError';
|
|
11
12
|
export { sanitizeErrorString, sanitizeUrl, sanitizeProperties } from './telemetry/TelemetrySanitizer';
|
|
12
13
|
export { suppressKnownWarnings } from './telemetry/suppressKnownWarnings';
|
|
14
|
+
export { HttpClient, getHttpCorrelationProperties } from './http/HttpClient';
|
|
13
15
|
export { resolveDeviceId } from './utils/DeviceIdUtils';
|
|
14
16
|
export { configureAppLogger, getAppLogger } from './telemetry/AppLogger';
|
|
15
|
-
export
|
|
17
|
+
export { configureCustomerTelemetryLogger, getCustomerTelemetryLogger, } from './telemetry/CustomerTelemetryLogger';
|
|
18
|
+
export type { ICustomerTelemetryLogger } from './telemetry/CustomerTelemetryLogger';
|
|
19
|
+
export type { ITelemetryProvider, LoggerConfig, OneDsTelemetryProviderConfig, ApplicationInsightsTelemetryProviderConfig, PropertyColumnMap, TelemetryEnvelope, TelemetryEvent, TelemetryLocation, TelemetrySeverity, UserIdentity, } from './telemetry/TelemetryTypes';
|
|
16
20
|
export { ScenarioResults, TelemetryEventNames } from './telemetry/TelemetryTypes';
|
|
17
21
|
export type { ClusterCategory, Region } from './types/ClusterCategory';
|
|
18
22
|
export { Regions, regionToClusterCategory } from './types/ClusterCategory';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { ApplicationInsightsTelemetryProviderConfig, ITelemetryProvider, TelemetryEvent, UserIdentity } from './TelemetryTypes';
|
|
5
|
+
/**
|
|
6
|
+
* Application Insights adapter for customer-owned mobile-app telemetry.
|
|
7
|
+
*
|
|
8
|
+
* The Microsoft React Native manual-device plugin avoids a dependency on
|
|
9
|
+
* react-native-device-info, which is important for apps loaded by the fixed
|
|
10
|
+
* Power Apps Dev Player binary.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ApplicationInsightsTelemetryProvider implements ITelemetryProvider {
|
|
13
|
+
readonly minSeverity: import("./TelemetryTypes").TelemetrySeverity;
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly appId;
|
|
16
|
+
private readonly appVersion?;
|
|
17
|
+
private readonly environment?;
|
|
18
|
+
private readonly includeUserId;
|
|
19
|
+
private readonly defaultProperties;
|
|
20
|
+
private _sessionId;
|
|
21
|
+
private tenantId?;
|
|
22
|
+
constructor(config: ApplicationInsightsTelemetryProviderConfig);
|
|
23
|
+
track(event: TelemetryEvent): void;
|
|
24
|
+
flush(): Promise<void>;
|
|
25
|
+
teardown(): Promise<void>;
|
|
26
|
+
get sessionId(): string;
|
|
27
|
+
set sessionId(value: string);
|
|
28
|
+
identifyUser(identity: UserIdentity): void;
|
|
29
|
+
setDefaultProperty(name: string, value: string): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ApplicationInsightsTelemetryProvider.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { ILogger, ScenarioTracker } from './ILogger';
|
|
5
|
+
export interface ICustomerTelemetryLogger {
|
|
6
|
+
trackEvent(name: string, properties?: Record<string, unknown>): void;
|
|
7
|
+
trackError(name: string, error?: unknown, properties?: Record<string, unknown>): void;
|
|
8
|
+
trackScenario(name: string, properties?: Record<string, unknown>): ScenarioTracker;
|
|
9
|
+
flush(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configures the customer telemetry singleton. Hosting infrastructure owns
|
|
13
|
+
* this function; application code should use getCustomerTelemetryLogger().
|
|
14
|
+
*/
|
|
15
|
+
export declare function configureCustomerTelemetryLogger(logger: ILogger): void;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the customer-owned telemetry logger. It is a safe no-op until the
|
|
18
|
+
* host configures an Application Insights provider.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCustomerTelemetryLogger(): ICustomerTelemetryLogger;
|
|
21
|
+
//# sourceMappingURL=CustomerTelemetryLogger.d.ts.map
|
|
@@ -85,4 +85,25 @@ export interface OneDsTelemetryProviderConfig {
|
|
|
85
85
|
propertyColumnMap?: PropertyColumnMap;
|
|
86
86
|
channelConfig?: Record<string, unknown>;
|
|
87
87
|
}
|
|
88
|
+
export interface ApplicationInsightsTelemetryProviderConfig {
|
|
89
|
+
/** Connection string for the C1-owned workspace-based Application Insights resource. */
|
|
90
|
+
connectionString: string;
|
|
91
|
+
/** Stable generated-app identifier added to every telemetry item. */
|
|
92
|
+
appId: string;
|
|
93
|
+
/** App version added to every telemetry item. */
|
|
94
|
+
appVersion?: string;
|
|
95
|
+
/** Deployment environment such as `development`, `test`, or `production`. */
|
|
96
|
+
environment?: string;
|
|
97
|
+
/** Minimum severity to export. Default: `info`. */
|
|
98
|
+
minSeverity?: TelemetrySeverity;
|
|
99
|
+
/** Stable device identifier supplied by the host. */
|
|
100
|
+
deviceId: string;
|
|
101
|
+
/** Shared logger session identifier supplied by the host. */
|
|
102
|
+
sessionId: string;
|
|
103
|
+
/**
|
|
104
|
+
* Include the signed-in user's object ID in authenticated-user context.
|
|
105
|
+
* Default is false because customer application telemetry should be anonymous.
|
|
106
|
+
*/
|
|
107
|
+
includeUserId?: boolean;
|
|
108
|
+
}
|
|
88
109
|
//# sourceMappingURL=TelemetryTypes.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function getHttpCorrelationProperties(headers: Pick<Headers, 'get'>): Record<string, string>;
|
|
2
|
+
export declare class HttpClient {
|
|
3
|
+
private readonly operationName;
|
|
4
|
+
private readonly shouldLogToConsole;
|
|
5
|
+
constructor(operationName: string, shouldLogToConsole?: () => boolean);
|
|
6
|
+
request(url: string, init?: RequestInit): Promise<Response>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -6,13 +6,17 @@ export { ConsoleAdapter } from './telemetry/ConsoleAdapter.js';
|
|
|
6
6
|
export type { ILogger, ScenarioTracker } from './telemetry/ILogger.js';
|
|
7
7
|
export { Logger } from './telemetry/Logger.js';
|
|
8
8
|
export { OneDsTelemetryProvider } from './telemetry/OneDsTelemetryProvider.js';
|
|
9
|
+
export { ApplicationInsightsTelemetryProvider } from './telemetry/ApplicationInsightsTelemetryProvider.js';
|
|
9
10
|
export { resolveTelemetryLocation } from './telemetry/resolveTelemetryLocation.js';
|
|
10
11
|
export { stringifyError } from './telemetry/stringifyError.js';
|
|
11
12
|
export { sanitizeErrorString, sanitizeUrl, sanitizeProperties } from './telemetry/TelemetrySanitizer.js';
|
|
12
13
|
export { suppressKnownWarnings } from './telemetry/suppressKnownWarnings.js';
|
|
14
|
+
export { HttpClient, getHttpCorrelationProperties } from './http/HttpClient.js';
|
|
13
15
|
export { resolveDeviceId } from './utils/DeviceIdUtils.js';
|
|
14
16
|
export { configureAppLogger, getAppLogger } from './telemetry/AppLogger.js';
|
|
15
|
-
export
|
|
17
|
+
export { configureCustomerTelemetryLogger, getCustomerTelemetryLogger, } from './telemetry/CustomerTelemetryLogger.js';
|
|
18
|
+
export type { ICustomerTelemetryLogger } from './telemetry/CustomerTelemetryLogger.js';
|
|
19
|
+
export type { ITelemetryProvider, LoggerConfig, OneDsTelemetryProviderConfig, ApplicationInsightsTelemetryProviderConfig, PropertyColumnMap, TelemetryEnvelope, TelemetryEvent, TelemetryLocation, TelemetrySeverity, UserIdentity, } from './telemetry/TelemetryTypes.js';
|
|
16
20
|
export { ScenarioResults, TelemetryEventNames } from './telemetry/TelemetryTypes.js';
|
|
17
21
|
export type { ClusterCategory, Region } from './types/ClusterCategory.js';
|
|
18
22
|
export { Regions, regionToClusterCategory } from './types/ClusterCategory.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { ApplicationInsightsTelemetryProviderConfig, ITelemetryProvider, TelemetryEvent, UserIdentity } from './TelemetryTypes.js';
|
|
5
|
+
/**
|
|
6
|
+
* Application Insights adapter for customer-owned mobile-app telemetry.
|
|
7
|
+
*
|
|
8
|
+
* The Microsoft React Native manual-device plugin avoids a dependency on
|
|
9
|
+
* react-native-device-info, which is important for apps loaded by the fixed
|
|
10
|
+
* Power Apps Dev Player binary.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ApplicationInsightsTelemetryProvider implements ITelemetryProvider {
|
|
13
|
+
readonly minSeverity: import("./TelemetryTypes.js").TelemetrySeverity;
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly appId;
|
|
16
|
+
private readonly appVersion?;
|
|
17
|
+
private readonly environment?;
|
|
18
|
+
private readonly includeUserId;
|
|
19
|
+
private readonly defaultProperties;
|
|
20
|
+
private _sessionId;
|
|
21
|
+
private tenantId?;
|
|
22
|
+
constructor(config: ApplicationInsightsTelemetryProviderConfig);
|
|
23
|
+
track(event: TelemetryEvent): void;
|
|
24
|
+
flush(): Promise<void>;
|
|
25
|
+
teardown(): Promise<void>;
|
|
26
|
+
get sessionId(): string;
|
|
27
|
+
set sessionId(value: string);
|
|
28
|
+
identifyUser(identity: UserIdentity): void;
|
|
29
|
+
setDefaultProperty(name: string, value: string): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ApplicationInsightsTelemetryProvider.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { ILogger, ScenarioTracker } from './ILogger.js';
|
|
5
|
+
export interface ICustomerTelemetryLogger {
|
|
6
|
+
trackEvent(name: string, properties?: Record<string, unknown>): void;
|
|
7
|
+
trackError(name: string, error?: unknown, properties?: Record<string, unknown>): void;
|
|
8
|
+
trackScenario(name: string, properties?: Record<string, unknown>): ScenarioTracker;
|
|
9
|
+
flush(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configures the customer telemetry singleton. Hosting infrastructure owns
|
|
13
|
+
* this function; application code should use getCustomerTelemetryLogger().
|
|
14
|
+
*/
|
|
15
|
+
export declare function configureCustomerTelemetryLogger(logger: ILogger): void;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the customer-owned telemetry logger. It is a safe no-op until the
|
|
18
|
+
* host configures an Application Insights provider.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCustomerTelemetryLogger(): ICustomerTelemetryLogger;
|
|
21
|
+
//# sourceMappingURL=CustomerTelemetryLogger.d.ts.map
|
|
@@ -85,4 +85,25 @@ export interface OneDsTelemetryProviderConfig {
|
|
|
85
85
|
propertyColumnMap?: PropertyColumnMap;
|
|
86
86
|
channelConfig?: Record<string, unknown>;
|
|
87
87
|
}
|
|
88
|
+
export interface ApplicationInsightsTelemetryProviderConfig {
|
|
89
|
+
/** Connection string for the C1-owned workspace-based Application Insights resource. */
|
|
90
|
+
connectionString: string;
|
|
91
|
+
/** Stable generated-app identifier added to every telemetry item. */
|
|
92
|
+
appId: string;
|
|
93
|
+
/** App version added to every telemetry item. */
|
|
94
|
+
appVersion?: string;
|
|
95
|
+
/** Deployment environment such as `development`, `test`, or `production`. */
|
|
96
|
+
environment?: string;
|
|
97
|
+
/** Minimum severity to export. Default: `info`. */
|
|
98
|
+
minSeverity?: TelemetrySeverity;
|
|
99
|
+
/** Stable device identifier supplied by the host. */
|
|
100
|
+
deviceId: string;
|
|
101
|
+
/** Shared logger session identifier supplied by the host. */
|
|
102
|
+
sessionId: string;
|
|
103
|
+
/**
|
|
104
|
+
* Include the signed-in user's object ID in authenticated-user context.
|
|
105
|
+
* Default is false because customer application telemetry should be anonymous.
|
|
106
|
+
*/
|
|
107
|
+
includeUserId?: boolean;
|
|
108
|
+
}
|
|
88
109
|
//# sourceMappingURL=TelemetryTypes.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/power-apps-native-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shared utilities and types for Power Apps native packages",
|
|
5
5
|
"author": "Microsoft Corporation",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
"default": "./lib/commonjs/index.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
+
"./http": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./lib/typescript/module/http/index.d.ts",
|
|
27
|
+
"default": "./lib/module/http/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./lib/typescript/commonjs/http/index.d.ts",
|
|
31
|
+
"default": "./lib/commonjs/http/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
24
34
|
"./package.json": "./package.json"
|
|
25
35
|
},
|
|
26
36
|
"files": [
|
|
@@ -30,6 +40,7 @@
|
|
|
30
40
|
"scripts": {
|
|
31
41
|
"prepack": "bob build && node ../../scripts/notices.js",
|
|
32
42
|
"build": "bob build && node ../../scripts/notices.js",
|
|
43
|
+
"test": "node --test test/*.test.js",
|
|
33
44
|
"type-check": "tsc --noEmit"
|
|
34
45
|
},
|
|
35
46
|
"peerDependencies": {
|
|
@@ -43,6 +54,8 @@
|
|
|
43
54
|
"dependencies": {
|
|
44
55
|
"@microsoft/1ds-post-js": "4.4.1",
|
|
45
56
|
"@microsoft/applicationinsights-core-js": "3.4.1",
|
|
57
|
+
"@microsoft/applicationinsights-react-native": "4.4.1",
|
|
58
|
+
"@microsoft/applicationinsights-web": "3.4.3",
|
|
46
59
|
"uuid": "^11.1.1"
|
|
47
60
|
},
|
|
48
61
|
"devDependencies": {
|