@salesforce/telemetry 2.0.1 → 2.0.5
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/CHANGELOG.md +35 -0
- package/lib/appInsights.d.ts +14 -6
- package/lib/appInsights.js +57 -43
- package/lib/exported.js +17 -4
- package/lib/telemetryReporter.d.ts +11 -5
- package/lib/telemetryReporter.js +56 -6
- package/package.json +37 -15
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.5](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.4...@salesforce/telemetry@2.0.5) (2021-01-22)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.0.4](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.3...@salesforce/telemetry@2.0.4) (2020-11-13)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.0.3](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.2...@salesforce/telemetry@2.0.3) (2020-11-11)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [2.0.2](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.1...@salesforce/telemetry@2.0.2) (2020-03-02)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* check connection to app insights ([d4d5748](https://github.com/forcedotcom/cli-packages/commit/d4d5748))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
## [2.0.1](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.0...@salesforce/telemetry@2.0.1) (2020-01-31)
|
|
7
42
|
|
|
8
43
|
|
package/lib/appInsights.d.ts
CHANGED
|
@@ -20,7 +20,14 @@ export interface TelemetryOptions {
|
|
|
20
20
|
gdprSensitiveKeys?: string[];
|
|
21
21
|
userId?: string;
|
|
22
22
|
sessionId?: string;
|
|
23
|
+
waitForConnection?: boolean;
|
|
23
24
|
}
|
|
25
|
+
export declare function getPlatformVersion(): string;
|
|
26
|
+
export declare function getCpus(): string;
|
|
27
|
+
export declare function buildPropertiesAndMeasurements(attributes: Attributes): {
|
|
28
|
+
properties: Properties;
|
|
29
|
+
measurements: Measurements;
|
|
30
|
+
};
|
|
24
31
|
/**
|
|
25
32
|
* This is a wrapper around appinsights sdk for convenience.
|
|
26
33
|
*
|
|
@@ -29,6 +36,7 @@ export interface TelemetryOptions {
|
|
|
29
36
|
*/
|
|
30
37
|
export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
31
38
|
static GDPR_HIDDEN: string;
|
|
39
|
+
static APP_INSIGHTS_SERVER: string;
|
|
32
40
|
private static ASIMOV_ENDPOINT;
|
|
33
41
|
appInsightsClient: appInsights.TelemetryClient;
|
|
34
42
|
private options;
|
|
@@ -39,24 +47,28 @@ export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
|
39
47
|
init(): Promise<void>;
|
|
40
48
|
/**
|
|
41
49
|
* Publishes event to app insights dashboard
|
|
50
|
+
*
|
|
42
51
|
* @param eventName {string} - name of the event you want published. Will be concatenated with this.options.project
|
|
43
52
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
44
53
|
*/
|
|
45
54
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): void;
|
|
46
55
|
/**
|
|
47
56
|
* Publishes exception to app insights dashboard
|
|
57
|
+
*
|
|
48
58
|
* @param exception {Error} - exception you want published.
|
|
49
59
|
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
50
60
|
*/
|
|
51
61
|
sendTelemetryException(exception: Error, attributes?: Attributes): void;
|
|
52
62
|
/**
|
|
53
63
|
* Publishes diagnostic information to app insights dashboard
|
|
64
|
+
*
|
|
54
65
|
* @param message {string} - trace message to sen to app insights.
|
|
55
66
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
56
67
|
*/
|
|
57
68
|
sendTelemetryTrace(traceMessage: string, properties?: Properties): void;
|
|
58
69
|
/**
|
|
59
70
|
* Publishes metric to app insights dashboard
|
|
71
|
+
*
|
|
60
72
|
* @param name {string} - name of the metric you want published
|
|
61
73
|
* @param value {number} - value of the metric
|
|
62
74
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
@@ -70,19 +82,15 @@ export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
|
70
82
|
private createAppInsightsClient;
|
|
71
83
|
/**
|
|
72
84
|
* Builds the properties to send with every event
|
|
85
|
+
*
|
|
73
86
|
* @return {Properties} map of base properites and properties provided when class was created
|
|
74
87
|
*/
|
|
75
88
|
private buildCommonProperties;
|
|
76
89
|
/**
|
|
77
90
|
* Builds the context tags for appInsightsClient
|
|
91
|
+
*
|
|
78
92
|
* @return {Properties} map of tags to add to this.appInsightsClient.context.tags
|
|
79
93
|
*/
|
|
80
94
|
private buildContextTags;
|
|
81
95
|
private hideGDPRdata;
|
|
82
96
|
}
|
|
83
|
-
export declare function buildPropertiesAndMeasurements(attributes: Attributes): {
|
|
84
|
-
properties: Properties;
|
|
85
|
-
measurements: Measurements;
|
|
86
|
-
};
|
|
87
|
-
export declare function getPlatformVersion(): string;
|
|
88
|
-
export declare function getCpus(): string;
|
package/lib/appInsights.js
CHANGED
|
@@ -1,13 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppInsights = exports.buildPropertiesAndMeasurements = exports.getCpus = exports.getPlatformVersion = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const os = require("os");
|
|
3
11
|
const core_1 = require("@salesforce/core");
|
|
4
12
|
const kit_1 = require("@salesforce/kit");
|
|
5
13
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
6
14
|
const appInsights = require("applicationinsights");
|
|
7
|
-
const os = require("os");
|
|
8
15
|
var applicationinsights_1 = require("applicationinsights");
|
|
9
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return applicationinsights_1.TelemetryClient; } });
|
|
10
17
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
18
|
+
function getPlatformVersion() {
|
|
19
|
+
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
|
|
20
|
+
}
|
|
21
|
+
exports.getPlatformVersion = getPlatformVersion;
|
|
22
|
+
function getCpus() {
|
|
23
|
+
const cpus = os.cpus();
|
|
24
|
+
if (cpus && cpus.length > 0) {
|
|
25
|
+
return `${cpus[0].model}(${cpus.length} x ${cpus[0].speed})`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.getCpus = getCpus;
|
|
32
|
+
function getSystemMemory() {
|
|
33
|
+
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
34
|
+
}
|
|
35
|
+
function isAsimovKey(key) {
|
|
36
|
+
return !!(key && key.startsWith('AIF-'));
|
|
37
|
+
}
|
|
38
|
+
function buildPropertiesAndMeasurements(attributes) {
|
|
39
|
+
const properties = {};
|
|
40
|
+
const measurements = {};
|
|
41
|
+
Object.keys(attributes).forEach((key) => {
|
|
42
|
+
const value = attributes[key];
|
|
43
|
+
if (ts_types_1.isString(value)) {
|
|
44
|
+
properties[key] = value;
|
|
45
|
+
}
|
|
46
|
+
else if (ts_types_1.isNumber(value)) {
|
|
47
|
+
measurements[key] = value;
|
|
48
|
+
}
|
|
49
|
+
else if (ts_types_1.isBoolean(value)) {
|
|
50
|
+
properties[key] = value.toString();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return { properties, measurements };
|
|
54
|
+
}
|
|
55
|
+
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
11
56
|
/**
|
|
12
57
|
* This is a wrapper around appinsights sdk for convenience.
|
|
13
58
|
*
|
|
@@ -35,6 +80,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
35
80
|
}
|
|
36
81
|
/**
|
|
37
82
|
* Publishes event to app insights dashboard
|
|
83
|
+
*
|
|
38
84
|
* @param eventName {string} - name of the event you want published. Will be concatenated with this.options.project
|
|
39
85
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
40
86
|
*/
|
|
@@ -46,6 +92,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
46
92
|
}
|
|
47
93
|
/**
|
|
48
94
|
* Publishes exception to app insights dashboard
|
|
95
|
+
*
|
|
49
96
|
* @param exception {Error} - exception you want published.
|
|
50
97
|
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
51
98
|
*/
|
|
@@ -56,6 +103,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
56
103
|
}
|
|
57
104
|
/**
|
|
58
105
|
* Publishes diagnostic information to app insights dashboard
|
|
106
|
+
*
|
|
59
107
|
* @param message {string} - trace message to sen to app insights.
|
|
60
108
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
61
109
|
*/
|
|
@@ -65,6 +113,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
65
113
|
}
|
|
66
114
|
/**
|
|
67
115
|
* Publishes metric to app insights dashboard
|
|
116
|
+
*
|
|
68
117
|
* @param name {string} - name of the metric you want published
|
|
69
118
|
* @param value {number} - value of the metric
|
|
70
119
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
@@ -102,6 +151,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
102
151
|
}
|
|
103
152
|
/**
|
|
104
153
|
* Builds the properties to send with every event
|
|
154
|
+
*
|
|
105
155
|
* @return {Properties} map of base properites and properties provided when class was created
|
|
106
156
|
*/
|
|
107
157
|
buildCommonProperties() {
|
|
@@ -110,12 +160,13 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
110
160
|
'common.os': os.platform(),
|
|
111
161
|
'common.platformversion': getPlatformVersion(),
|
|
112
162
|
'common.systemmemory': getSystemMemory(),
|
|
113
|
-
'common.usertype': this.env.getString('SFDX_USER_TYPE') || 'normal'
|
|
163
|
+
'common.usertype': this.env.getString('SFDX_USER_TYPE') || 'normal',
|
|
114
164
|
};
|
|
115
165
|
return Object.assign(baseProperties, this.options.commonProperties);
|
|
116
166
|
}
|
|
117
167
|
/**
|
|
118
168
|
* Builds the context tags for appInsightsClient
|
|
169
|
+
*
|
|
119
170
|
* @return {Properties} map of tags to add to this.appInsightsClient.context.tags
|
|
120
171
|
*/
|
|
121
172
|
buildContextTags() {
|
|
@@ -125,51 +176,14 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
125
176
|
}
|
|
126
177
|
// filters out non-GDPR compliant tags
|
|
127
178
|
hideGDPRdata(tags) {
|
|
128
|
-
this.gdprSensitiveKeys.forEach(key => {
|
|
179
|
+
this.gdprSensitiveKeys.forEach((key) => {
|
|
129
180
|
tags[key] = AppInsights.GDPR_HIDDEN;
|
|
130
181
|
});
|
|
131
182
|
return tags;
|
|
132
183
|
}
|
|
133
184
|
}
|
|
185
|
+
exports.AppInsights = AppInsights;
|
|
134
186
|
AppInsights.GDPR_HIDDEN = '<GDPR_HIDDEN>';
|
|
187
|
+
AppInsights.APP_INSIGHTS_SERVER = 'https://dc.services.visualstudio.com';
|
|
135
188
|
AppInsights.ASIMOV_ENDPOINT = 'https://vortex.data.microsoft.com/collect/v1';
|
|
136
|
-
exports.AppInsights = AppInsights;
|
|
137
|
-
function buildPropertiesAndMeasurements(attributes) {
|
|
138
|
-
const properties = {};
|
|
139
|
-
const measurements = {};
|
|
140
|
-
Object.keys(attributes).forEach(key => {
|
|
141
|
-
const value = attributes[key];
|
|
142
|
-
if (ts_types_1.isString(value)) {
|
|
143
|
-
properties[key] = value;
|
|
144
|
-
}
|
|
145
|
-
else if (ts_types_1.isNumber(value)) {
|
|
146
|
-
measurements[key] = value;
|
|
147
|
-
}
|
|
148
|
-
else if (ts_types_1.isBoolean(value)) {
|
|
149
|
-
properties[key] = value.toString();
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
return { properties, measurements };
|
|
153
|
-
}
|
|
154
|
-
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
155
|
-
function getPlatformVersion() {
|
|
156
|
-
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
|
|
157
|
-
}
|
|
158
|
-
exports.getPlatformVersion = getPlatformVersion;
|
|
159
|
-
function getCpus() {
|
|
160
|
-
const cpus = os.cpus();
|
|
161
|
-
if (cpus && cpus.length > 0) {
|
|
162
|
-
return `${cpus[0].model}(${cpus.length} x ${cpus[0].speed})`;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
return '';
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.getCpus = getCpus;
|
|
169
|
-
function getSystemMemory() {
|
|
170
|
-
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
171
|
-
}
|
|
172
|
-
function isAsimovKey(key) {
|
|
173
|
-
return !!(key && key.indexOf('AIF-') === 0);
|
|
174
|
-
}
|
|
175
189
|
//# sourceMappingURL=appInsights.js.map
|
package/lib/exported.js
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
1
7
|
'use strict';
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
5
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
19
|
const telemetryReporter_1 = require("./telemetryReporter");
|
|
7
|
-
|
|
20
|
+
__exportStar(require("./telemetryReporter"), exports);
|
|
8
21
|
exports.default = telemetryReporter_1.TelemetryReporter;
|
|
9
22
|
//# sourceMappingURL=exported.js.map
|
|
@@ -6,17 +6,17 @@ export { TelemetryOptions, Attributes, Properties, TelemetryClient } from './app
|
|
|
6
6
|
* Reports telemetry events to app insights. We do not send if the config 'disableTelemetry' is set.
|
|
7
7
|
*/
|
|
8
8
|
export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
|
|
9
|
-
/**
|
|
10
|
-
* Determine if the telemetry event should be logged.
|
|
11
|
-
* Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
|
|
12
|
-
*/
|
|
13
|
-
static determineSfdxTelemetryEnabled(): Promise<boolean>;
|
|
14
9
|
private static config;
|
|
15
10
|
private options;
|
|
16
11
|
private logger;
|
|
17
12
|
private config;
|
|
18
13
|
private reporter;
|
|
19
14
|
constructor(options: TelemetryOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Determine if the telemetry event should be logged.
|
|
17
|
+
* Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
|
|
18
|
+
*/
|
|
19
|
+
static determineSfdxTelemetryEnabled(): Promise<boolean>;
|
|
20
20
|
init(): Promise<void>;
|
|
21
21
|
/**
|
|
22
22
|
* Starts data collection services. This is for long running processes. Short lived
|
|
@@ -28,26 +28,32 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
|
|
|
28
28
|
* not counting timeouts.
|
|
29
29
|
*/
|
|
30
30
|
stop(): void;
|
|
31
|
+
waitForConnection(): Promise<void>;
|
|
32
|
+
testConnection(): Promise<boolean>;
|
|
31
33
|
/**
|
|
32
34
|
* Sends message to child process.
|
|
35
|
+
*
|
|
33
36
|
* @param eventName {string} - name of the event you want published.
|
|
34
37
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
35
38
|
*/
|
|
36
39
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): void;
|
|
37
40
|
/**
|
|
38
41
|
* Sends exception to child process.
|
|
42
|
+
*
|
|
39
43
|
* @param exception {Error} - exception you want published.
|
|
40
44
|
* @param measurements {Measurements} - map of measurements to publish alongside the event.
|
|
41
45
|
*/
|
|
42
46
|
sendTelemetryException(exception: Error, attributes?: Attributes): void;
|
|
43
47
|
/**
|
|
44
48
|
* Publishes diagnostic information to app insights dashboard
|
|
49
|
+
*
|
|
45
50
|
* @param message {string} - trace message to sen to app insights.
|
|
46
51
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
47
52
|
*/
|
|
48
53
|
sendTelemetryTrace(traceMessage: string, properties?: Properties): void;
|
|
49
54
|
/**
|
|
50
55
|
* Publishes metric to app insights dashboard
|
|
56
|
+
*
|
|
51
57
|
* @param name {string} - name of the metric you want published
|
|
52
58
|
* @param value {number} - value of the metric
|
|
53
59
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
package/lib/telemetryReporter.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelemetryReporter = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const os = require("os");
|
|
3
11
|
const core_1 = require("@salesforce/core");
|
|
4
12
|
const kit_1 = require("@salesforce/kit");
|
|
5
|
-
const
|
|
13
|
+
const axios_1 = require("axios");
|
|
6
14
|
const appInsights_1 = require("./appInsights");
|
|
7
15
|
const DISABLE_TELEMETRY = 'disableTelemetry';
|
|
8
16
|
var appInsights_2 = require("./appInsights");
|
|
9
|
-
exports
|
|
17
|
+
Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return appInsights_2.TelemetryClient; } });
|
|
10
18
|
/**
|
|
11
19
|
* Reports telemetry events to app insights. We do not send if the config 'disableTelemetry' is set.
|
|
12
20
|
*/
|
|
13
21
|
class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super(options);
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
14
26
|
/**
|
|
15
27
|
* Determine if the telemetry event should be logged.
|
|
16
28
|
* Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
|
|
@@ -24,16 +36,14 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
24
36
|
const isEnabled = !sfdxDisableInsights;
|
|
25
37
|
return isEnabled;
|
|
26
38
|
}
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super(options);
|
|
29
|
-
this.options = options;
|
|
30
|
-
}
|
|
31
39
|
async init() {
|
|
32
40
|
this.logger = await core_1.Logger.child('TelemetryReporter');
|
|
33
41
|
if (!TelemetryReporter.config) {
|
|
34
42
|
TelemetryReporter.config = await core_1.ConfigAggregator.create({});
|
|
35
43
|
}
|
|
36
44
|
this.config = TelemetryReporter.config;
|
|
45
|
+
if (this.options.waitForConnection)
|
|
46
|
+
await this.waitForConnection();
|
|
37
47
|
this.reporter = await appInsights_1.AppInsights.create(this.options);
|
|
38
48
|
}
|
|
39
49
|
/**
|
|
@@ -50,8 +60,45 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
50
60
|
stop() {
|
|
51
61
|
this.reporter.stop();
|
|
52
62
|
}
|
|
63
|
+
async waitForConnection() {
|
|
64
|
+
const canConnect = await this.testConnection();
|
|
65
|
+
if (!canConnect) {
|
|
66
|
+
throw new Error('Unable to connect to app insights.');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async testConnection() {
|
|
70
|
+
const timeout = parseInt(kit_1.env.getString('SFDX_TELEMETRY_TIMEOUT', '1000'), 10);
|
|
71
|
+
this.logger.debug(`Testing connection to ${appInsights_1.AppInsights.APP_INSIGHTS_SERVER} with timeout of ${timeout} ms`);
|
|
72
|
+
// set up a CancelToken to handle connection timeouts because
|
|
73
|
+
// the built in timeout functionality only handles response timeouts
|
|
74
|
+
// see here: https://github.com/axios/axios/issues/647#issuecomment-322209906
|
|
75
|
+
const cancelRequest = axios_1.default.CancelToken.source();
|
|
76
|
+
setTimeout(() => cancelRequest.cancel('connection timeout'), timeout);
|
|
77
|
+
let canConnect;
|
|
78
|
+
try {
|
|
79
|
+
const options = {
|
|
80
|
+
timeout,
|
|
81
|
+
cancelToken: cancelRequest.token,
|
|
82
|
+
// We want any status less than 500 to be resolved (not rejected)
|
|
83
|
+
validateStatus: (status) => status < 500,
|
|
84
|
+
};
|
|
85
|
+
await axios_1.default.get(appInsights_1.AppInsights.APP_INSIGHTS_SERVER, options);
|
|
86
|
+
canConnect = true;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
canConnect = false;
|
|
90
|
+
}
|
|
91
|
+
if (canConnect) {
|
|
92
|
+
this.logger.debug(`Successfully made a connection to ${appInsights_1.AppInsights.APP_INSIGHTS_SERVER}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.logger.warn(`Connection to ${appInsights_1.AppInsights.APP_INSIGHTS_SERVER} timed out after ${timeout} ms`);
|
|
96
|
+
}
|
|
97
|
+
return canConnect;
|
|
98
|
+
}
|
|
53
99
|
/**
|
|
54
100
|
* Sends message to child process.
|
|
101
|
+
*
|
|
55
102
|
* @param eventName {string} - name of the event you want published.
|
|
56
103
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
57
104
|
*/
|
|
@@ -62,6 +109,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
62
109
|
}
|
|
63
110
|
/**
|
|
64
111
|
* Sends exception to child process.
|
|
112
|
+
*
|
|
65
113
|
* @param exception {Error} - exception you want published.
|
|
66
114
|
* @param measurements {Measurements} - map of measurements to publish alongside the event.
|
|
67
115
|
*/
|
|
@@ -75,6 +123,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
75
123
|
}
|
|
76
124
|
/**
|
|
77
125
|
* Publishes diagnostic information to app insights dashboard
|
|
126
|
+
*
|
|
78
127
|
* @param message {string} - trace message to sen to app insights.
|
|
79
128
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
80
129
|
*/
|
|
@@ -85,6 +134,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
85
134
|
}
|
|
86
135
|
/**
|
|
87
136
|
* Publishes metric to app insights dashboard
|
|
137
|
+
*
|
|
88
138
|
* @param name {string} - name of the metric you want published
|
|
89
139
|
* @param value {number} - value of the metric
|
|
90
140
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/telemetry",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Library for application insights",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"repository": "https://github.com/forcedotcom/cli-packages",
|
|
7
7
|
"author": "Salesforce",
|
|
8
8
|
"license": "BSD-3-Clause",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"clean": "
|
|
12
|
-
"clean-all": "
|
|
13
|
-
"compile": "
|
|
14
|
-
"docs": "
|
|
15
|
-
"format": "
|
|
16
|
-
"lint": "
|
|
10
|
+
"build": "sf-build",
|
|
11
|
+
"clean": "sf-clean",
|
|
12
|
+
"clean-all": "sf-clean all",
|
|
13
|
+
"compile": "sf-compile",
|
|
14
|
+
"docs": "sf-docs",
|
|
15
|
+
"format": "sf-format",
|
|
16
|
+
"lint": "sf-lint",
|
|
17
17
|
"lint-fix": "yarn sfdx-lint --fix",
|
|
18
|
-
"prepack": "
|
|
18
|
+
"prepack": "sf-build",
|
|
19
19
|
"prepare": "npm run build",
|
|
20
|
-
"
|
|
20
|
+
"pretest": "sf-compile-test",
|
|
21
|
+
"test": "sf-test"
|
|
21
22
|
},
|
|
22
23
|
"keywords": [
|
|
23
24
|
"force",
|
|
@@ -32,17 +33,38 @@
|
|
|
32
33
|
"!lib/**/*.map"
|
|
33
34
|
],
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@salesforce/core": "^2.
|
|
36
|
+
"@salesforce/core": "^2.15.2",
|
|
36
37
|
"@salesforce/ts-types": "^1.2.1",
|
|
37
|
-
"applicationinsights": "^1.4.0"
|
|
38
|
+
"applicationinsights": "^1.4.0",
|
|
39
|
+
"axios": "^0.21.1"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@salesforce/dev-
|
|
41
|
-
"@salesforce/
|
|
42
|
+
"@salesforce/dev-config": "^2.0.0",
|
|
43
|
+
"@salesforce/dev-scripts": "^0.6.2",
|
|
44
|
+
"@salesforce/prettier-config": "^0.0.1",
|
|
45
|
+
"@salesforce/ts-sinon": "^1.1.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^2.30.0",
|
|
47
|
+
"@typescript-eslint/parser": "^2.30.0",
|
|
48
|
+
"chai": "^4.2.0",
|
|
49
|
+
"eslint": "^6.8.0",
|
|
50
|
+
"eslint-config-prettier": "^6.11.0",
|
|
51
|
+
"eslint-config-salesforce": "^0.1.0",
|
|
52
|
+
"eslint-config-salesforce-license": "^0.1.0",
|
|
53
|
+
"eslint-config-salesforce-typescript": "^0.1.0",
|
|
54
|
+
"eslint-plugin-header": "^3.0.0",
|
|
55
|
+
"eslint-plugin-import": "^2.20.2",
|
|
56
|
+
"eslint-plugin-jsdoc": "^27.0.3",
|
|
57
|
+
"eslint-plugin-prettier": "^3.1.3",
|
|
58
|
+
"mocha": "^7.2.0",
|
|
59
|
+
"nyc": "^15.1.0",
|
|
60
|
+
"prettier": "^2.0.5",
|
|
61
|
+
"sinon": "^9.0.2",
|
|
62
|
+
"ts-node": "^8.10.2",
|
|
63
|
+
"typescript": "^3.9.3"
|
|
42
64
|
},
|
|
43
65
|
"types": "lib/exported.d.ts",
|
|
44
66
|
"publishConfig": {
|
|
45
67
|
"access": "public"
|
|
46
68
|
},
|
|
47
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "b089ff3508131aa35774ee088376b7a98dcb3167"
|
|
48
70
|
}
|