@salesforce/telemetry 2.0.2 → 3.0.1
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 +51 -3
- package/lib/appInsights.d.ts +13 -7
- package/lib/appInsights.js +74 -46
- package/lib/exported.js +17 -4
- package/lib/telemetryReporter.d.ts +9 -5
- package/lib/telemetryReporter.js +18 -7
- package/package.json +37 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [3.0.1](https://github.com/forcedotcom/telemetry/compare/v3.0.0...v3.0.1) (2021-11-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* release 3.0.1 ([050953a](https://github.com/forcedotcom/telemetry/commit/050953a117a4f3c6c5a2100d2a47e80719e64976))
|
|
11
|
+
* replace homedir ([2bcb2ed](https://github.com/forcedotcom/telemetry/commit/2bcb2ede66dc7ef3c14cb40d530fb34530b84147))
|
|
12
|
+
* sanitizing exception strings ([b12c52c](https://github.com/forcedotcom/telemetry/commit/b12c52cad97b736bcb0e5968c8427ae89f0d8397))
|
|
13
|
+
* sinon types match sinon ([4cbefbf](https://github.com/forcedotcom/telemetry/commit/4cbefbf4ded50b4fdd1f451e27aba449c886b481))
|
|
14
|
+
|
|
15
|
+
## 3.0.0 (2021-07-08)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* publish ([9336302](https://github.com/forcedotcom/telemetry/commit/9336302f15b43bd824ec70fe604e05a6bb2f5ba2))
|
|
21
|
+
|
|
22
|
+
## [2.0.6](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.5...@salesforce/telemetry@2.0.6) (2021-05-11)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [2.0.5](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.4...@salesforce/telemetry@2.0.5) (2021-01-22)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## [2.0.4](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.3...@salesforce/telemetry@2.0.4) (2020-11-13)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## [2.0.3](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.2...@salesforce/telemetry@2.0.3) (2020-11-11)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @salesforce/telemetry
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
2
52
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
53
|
|
|
6
54
|
## [2.0.2](https://github.com/forcedotcom/cli-packages/compare/@salesforce/telemetry@2.0.1...@salesforce/telemetry@2.0.2) (2020-03-02)
|
|
7
55
|
|
package/lib/appInsights.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface TelemetryOptions {
|
|
|
22
22
|
sessionId?: string;
|
|
23
23
|
waitForConnection?: boolean;
|
|
24
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
|
+
};
|
|
25
31
|
/**
|
|
26
32
|
* This is a wrapper around appinsights sdk for convenience.
|
|
27
33
|
*
|
|
@@ -41,24 +47,28 @@ export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
|
41
47
|
init(): Promise<void>;
|
|
42
48
|
/**
|
|
43
49
|
* Publishes event to app insights dashboard
|
|
50
|
+
*
|
|
44
51
|
* @param eventName {string} - name of the event you want published. Will be concatenated with this.options.project
|
|
45
52
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
46
53
|
*/
|
|
47
54
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): void;
|
|
48
55
|
/**
|
|
49
56
|
* Publishes exception to app insights dashboard
|
|
57
|
+
*
|
|
50
58
|
* @param exception {Error} - exception you want published.
|
|
51
59
|
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
52
60
|
*/
|
|
53
61
|
sendTelemetryException(exception: Error, attributes?: Attributes): void;
|
|
54
62
|
/**
|
|
55
63
|
* Publishes diagnostic information to app insights dashboard
|
|
64
|
+
*
|
|
56
65
|
* @param message {string} - trace message to sen to app insights.
|
|
57
66
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
58
67
|
*/
|
|
59
68
|
sendTelemetryTrace(traceMessage: string, properties?: Properties): void;
|
|
60
69
|
/**
|
|
61
70
|
* Publishes metric to app insights dashboard
|
|
71
|
+
*
|
|
62
72
|
* @param name {string} - name of the metric you want published
|
|
63
73
|
* @param value {number} - value of the metric
|
|
64
74
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
@@ -72,19 +82,15 @@ export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
|
72
82
|
private createAppInsightsClient;
|
|
73
83
|
/**
|
|
74
84
|
* Builds the properties to send with every event
|
|
75
|
-
*
|
|
85
|
+
*
|
|
86
|
+
* @return {Properties} map of base properties and properties provided when class was created
|
|
76
87
|
*/
|
|
77
88
|
private buildCommonProperties;
|
|
78
89
|
/**
|
|
79
90
|
* Builds the context tags for appInsightsClient
|
|
91
|
+
*
|
|
80
92
|
* @return {Properties} map of tags to add to this.appInsightsClient.context.tags
|
|
81
93
|
*/
|
|
82
94
|
private buildContextTags;
|
|
83
95
|
private hideGDPRdata;
|
|
84
96
|
}
|
|
85
|
-
export declare function buildPropertiesAndMeasurements(attributes: Attributes): {
|
|
86
|
-
properties: Properties;
|
|
87
|
-
measurements: Measurements;
|
|
88
|
-
};
|
|
89
|
-
export declare function getPlatformVersion(): string;
|
|
90
|
-
export declare function getCpus(): string;
|
package/lib/appInsights.js
CHANGED
|
@@ -1,13 +1,72 @@
|
|
|
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) 2021, 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
|
+
const homeDir = os.homedir();
|
|
33
|
+
const sanitizeError = (err) => {
|
|
34
|
+
if (err.name) {
|
|
35
|
+
err.name = err.name.replace(homeDir, '~');
|
|
36
|
+
}
|
|
37
|
+
if (err.message) {
|
|
38
|
+
err.message = err.message.replace(homeDir, '~');
|
|
39
|
+
}
|
|
40
|
+
if (err.stack) {
|
|
41
|
+
// there might be lots of this one
|
|
42
|
+
err.stack = err.stack.replace(new RegExp(`\\b${homeDir}\\b`, 'gi'), '~');
|
|
43
|
+
}
|
|
44
|
+
return err;
|
|
45
|
+
};
|
|
46
|
+
function getSystemMemory() {
|
|
47
|
+
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
48
|
+
}
|
|
49
|
+
function isAsimovKey(key) {
|
|
50
|
+
return !!(key && key.startsWith('AIF-'));
|
|
51
|
+
}
|
|
52
|
+
function buildPropertiesAndMeasurements(attributes) {
|
|
53
|
+
const properties = {};
|
|
54
|
+
const measurements = {};
|
|
55
|
+
Object.keys(attributes).forEach((key) => {
|
|
56
|
+
const value = attributes[key];
|
|
57
|
+
if (ts_types_1.isString(value)) {
|
|
58
|
+
properties[key] = value.replace(homeDir, '~');
|
|
59
|
+
}
|
|
60
|
+
else if (ts_types_1.isNumber(value)) {
|
|
61
|
+
measurements[key] = value;
|
|
62
|
+
}
|
|
63
|
+
else if (ts_types_1.isBoolean(value)) {
|
|
64
|
+
properties[key] = value.toString();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return { properties, measurements };
|
|
68
|
+
}
|
|
69
|
+
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
11
70
|
/**
|
|
12
71
|
* This is a wrapper around appinsights sdk for convenience.
|
|
13
72
|
*
|
|
@@ -35,6 +94,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
35
94
|
}
|
|
36
95
|
/**
|
|
37
96
|
* Publishes event to app insights dashboard
|
|
97
|
+
*
|
|
38
98
|
* @param eventName {string} - name of the event you want published. Will be concatenated with this.options.project
|
|
39
99
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
40
100
|
*/
|
|
@@ -46,16 +106,19 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
46
106
|
}
|
|
47
107
|
/**
|
|
48
108
|
* Publishes exception to app insights dashboard
|
|
109
|
+
*
|
|
49
110
|
* @param exception {Error} - exception you want published.
|
|
50
111
|
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
51
112
|
*/
|
|
52
113
|
sendTelemetryException(exception, attributes = {}) {
|
|
53
|
-
|
|
114
|
+
const cleanException = sanitizeError(exception);
|
|
115
|
+
this.logger.debug(`Sending telemetry exception: ${cleanException.message}`);
|
|
54
116
|
const { properties, measurements } = buildPropertiesAndMeasurements(attributes);
|
|
55
|
-
this.appInsightsClient.trackException({ exception, properties, measurements });
|
|
117
|
+
this.appInsightsClient.trackException({ exception: cleanException, properties, measurements });
|
|
56
118
|
}
|
|
57
119
|
/**
|
|
58
120
|
* Publishes diagnostic information to app insights dashboard
|
|
121
|
+
*
|
|
59
122
|
* @param message {string} - trace message to sen to app insights.
|
|
60
123
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
61
124
|
*/
|
|
@@ -65,6 +128,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
65
128
|
}
|
|
66
129
|
/**
|
|
67
130
|
* Publishes metric to app insights dashboard
|
|
131
|
+
*
|
|
68
132
|
* @param name {string} - name of the metric you want published
|
|
69
133
|
* @param value {number} - value of the metric
|
|
70
134
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
@@ -102,7 +166,8 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
102
166
|
}
|
|
103
167
|
/**
|
|
104
168
|
* Builds the properties to send with every event
|
|
105
|
-
*
|
|
169
|
+
*
|
|
170
|
+
* @return {Properties} map of base properties and properties provided when class was created
|
|
106
171
|
*/
|
|
107
172
|
buildCommonProperties() {
|
|
108
173
|
const baseProperties = {
|
|
@@ -110,12 +175,13 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
110
175
|
'common.os': os.platform(),
|
|
111
176
|
'common.platformversion': getPlatformVersion(),
|
|
112
177
|
'common.systemmemory': getSystemMemory(),
|
|
113
|
-
'common.usertype': this.env.getString('SFDX_USER_TYPE') || 'normal'
|
|
178
|
+
'common.usertype': this.env.getString('SFDX_USER_TYPE') || 'normal',
|
|
114
179
|
};
|
|
115
180
|
return Object.assign(baseProperties, this.options.commonProperties);
|
|
116
181
|
}
|
|
117
182
|
/**
|
|
118
183
|
* Builds the context tags for appInsightsClient
|
|
184
|
+
*
|
|
119
185
|
* @return {Properties} map of tags to add to this.appInsightsClient.context.tags
|
|
120
186
|
*/
|
|
121
187
|
buildContextTags() {
|
|
@@ -125,52 +191,14 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
125
191
|
}
|
|
126
192
|
// filters out non-GDPR compliant tags
|
|
127
193
|
hideGDPRdata(tags) {
|
|
128
|
-
this.gdprSensitiveKeys.forEach(key => {
|
|
194
|
+
this.gdprSensitiveKeys.forEach((key) => {
|
|
129
195
|
tags[key] = AppInsights.GDPR_HIDDEN;
|
|
130
196
|
});
|
|
131
197
|
return tags;
|
|
132
198
|
}
|
|
133
199
|
}
|
|
200
|
+
exports.AppInsights = AppInsights;
|
|
134
201
|
AppInsights.GDPR_HIDDEN = '<GDPR_HIDDEN>';
|
|
135
202
|
AppInsights.APP_INSIGHTS_SERVER = 'https://dc.services.visualstudio.com';
|
|
136
203
|
AppInsights.ASIMOV_ENDPOINT = 'https://vortex.data.microsoft.com/collect/v1';
|
|
137
|
-
exports.AppInsights = AppInsights;
|
|
138
|
-
function buildPropertiesAndMeasurements(attributes) {
|
|
139
|
-
const properties = {};
|
|
140
|
-
const measurements = {};
|
|
141
|
-
Object.keys(attributes).forEach(key => {
|
|
142
|
-
const value = attributes[key];
|
|
143
|
-
if (ts_types_1.isString(value)) {
|
|
144
|
-
properties[key] = value;
|
|
145
|
-
}
|
|
146
|
-
else if (ts_types_1.isNumber(value)) {
|
|
147
|
-
measurements[key] = value;
|
|
148
|
-
}
|
|
149
|
-
else if (ts_types_1.isBoolean(value)) {
|
|
150
|
-
properties[key] = value.toString();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return { properties, measurements };
|
|
154
|
-
}
|
|
155
|
-
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
156
|
-
function getPlatformVersion() {
|
|
157
|
-
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
|
|
158
|
-
}
|
|
159
|
-
exports.getPlatformVersion = getPlatformVersion;
|
|
160
|
-
function getCpus() {
|
|
161
|
-
const cpus = os.cpus();
|
|
162
|
-
if (cpus && cpus.length > 0) {
|
|
163
|
-
return `${cpus[0].model}(${cpus.length} x ${cpus[0].speed})`;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
return '';
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.getCpus = getCpus;
|
|
170
|
-
function getSystemMemory() {
|
|
171
|
-
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
172
|
-
}
|
|
173
|
-
function isAsimovKey(key) {
|
|
174
|
-
return !!(key && key.indexOf('AIF-') === 0);
|
|
175
|
-
}
|
|
176
204
|
//# 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
|
|
@@ -32,24 +32,28 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
|
|
|
32
32
|
testConnection(): Promise<boolean>;
|
|
33
33
|
/**
|
|
34
34
|
* Sends message to child process.
|
|
35
|
+
*
|
|
35
36
|
* @param eventName {string} - name of the event you want published.
|
|
36
37
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
37
38
|
*/
|
|
38
39
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): void;
|
|
39
40
|
/**
|
|
40
41
|
* Sends exception to child process.
|
|
42
|
+
*
|
|
41
43
|
* @param exception {Error} - exception you want published.
|
|
42
44
|
* @param measurements {Measurements} - map of measurements to publish alongside the event.
|
|
43
45
|
*/
|
|
44
46
|
sendTelemetryException(exception: Error, attributes?: Attributes): void;
|
|
45
47
|
/**
|
|
46
48
|
* Publishes diagnostic information to app insights dashboard
|
|
49
|
+
*
|
|
47
50
|
* @param message {string} - trace message to sen to app insights.
|
|
48
51
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
49
52
|
*/
|
|
50
53
|
sendTelemetryTrace(traceMessage: string, properties?: Properties): void;
|
|
51
54
|
/**
|
|
52
55
|
* Publishes metric to app insights dashboard
|
|
56
|
+
*
|
|
53
57
|
* @param name {string} - name of the metric you want published
|
|
54
58
|
* @param value {number} - value of the metric
|
|
55
59
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
package/lib/telemetryReporter.js
CHANGED
|
@@ -1,17 +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
13
|
const axios_1 = require("axios");
|
|
6
|
-
const os = require("os");
|
|
7
14
|
const appInsights_1 = require("./appInsights");
|
|
8
15
|
const DISABLE_TELEMETRY = 'disableTelemetry';
|
|
9
16
|
var appInsights_2 = require("./appInsights");
|
|
10
|
-
exports
|
|
17
|
+
Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return appInsights_2.TelemetryClient; } });
|
|
11
18
|
/**
|
|
12
19
|
* Reports telemetry events to app insights. We do not send if the config 'disableTelemetry' is set.
|
|
13
20
|
*/
|
|
14
21
|
class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super(options);
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
15
26
|
/**
|
|
16
27
|
* Determine if the telemetry event should be logged.
|
|
17
28
|
* Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
|
|
@@ -25,10 +36,6 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
25
36
|
const isEnabled = !sfdxDisableInsights;
|
|
26
37
|
return isEnabled;
|
|
27
38
|
}
|
|
28
|
-
constructor(options) {
|
|
29
|
-
super(options);
|
|
30
|
-
this.options = options;
|
|
31
|
-
}
|
|
32
39
|
async init() {
|
|
33
40
|
this.logger = await core_1.Logger.child('TelemetryReporter');
|
|
34
41
|
if (!TelemetryReporter.config) {
|
|
@@ -73,7 +80,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
73
80
|
timeout,
|
|
74
81
|
cancelToken: cancelRequest.token,
|
|
75
82
|
// We want any status less than 500 to be resolved (not rejected)
|
|
76
|
-
validateStatus: (status) => status < 500
|
|
83
|
+
validateStatus: (status) => status < 500,
|
|
77
84
|
};
|
|
78
85
|
await axios_1.default.get(appInsights_1.AppInsights.APP_INSIGHTS_SERVER, options);
|
|
79
86
|
canConnect = true;
|
|
@@ -91,6 +98,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
91
98
|
}
|
|
92
99
|
/**
|
|
93
100
|
* Sends message to child process.
|
|
101
|
+
*
|
|
94
102
|
* @param eventName {string} - name of the event you want published.
|
|
95
103
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
96
104
|
*/
|
|
@@ -101,6 +109,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
101
109
|
}
|
|
102
110
|
/**
|
|
103
111
|
* Sends exception to child process.
|
|
112
|
+
*
|
|
104
113
|
* @param exception {Error} - exception you want published.
|
|
105
114
|
* @param measurements {Measurements} - map of measurements to publish alongside the event.
|
|
106
115
|
*/
|
|
@@ -114,6 +123,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
114
123
|
}
|
|
115
124
|
/**
|
|
116
125
|
* Publishes diagnostic information to app insights dashboard
|
|
126
|
+
*
|
|
117
127
|
* @param message {string} - trace message to sen to app insights.
|
|
118
128
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
119
129
|
*/
|
|
@@ -124,6 +134,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
* Publishes metric to app insights dashboard
|
|
137
|
+
*
|
|
127
138
|
* @param name {string} - name of the metric you want published
|
|
128
139
|
* @param value {number} - value of the metric
|
|
129
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": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Library for application insights",
|
|
5
5
|
"main": "lib/exported",
|
|
6
|
-
"repository": "
|
|
6
|
+
"repository": "forcedotcom/telemetry",
|
|
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,18 +33,37 @@
|
|
|
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
38
|
"applicationinsights": "^1.4.0",
|
|
38
|
-
"axios": "^0.
|
|
39
|
+
"axios": "^0.21.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@salesforce/dev-
|
|
42
|
-
"@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"
|
|
43
64
|
},
|
|
44
65
|
"types": "lib/exported.d.ts",
|
|
45
66
|
"publishConfig": {
|
|
46
67
|
"access": "public"
|
|
47
|
-
}
|
|
48
|
-
"gitHead": "b0f530d31fbbb22a171ff6042a590df9bf283ad1"
|
|
68
|
+
}
|
|
49
69
|
}
|