@salesforce/telemetry 6.0.38 → 6.1.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/LICENSE.txt +200 -6
- package/lib/appInsights.d.ts +4 -29
- package/lib/appInsights.js +27 -70
- package/lib/baseReporter.d.ts +9 -0
- package/lib/baseReporter.js +92 -0
- package/lib/exported.d.ts +1 -0
- package/lib/o11yReporter.d.ts +35 -0
- package/lib/o11yReporter.js +96 -0
- package/lib/telemetryReporter.d.ts +11 -9
- package/lib/telemetryReporter.js +82 -19
- package/lib/types.d.ts +25 -0
- package/lib/types.js +3 -0
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +21 -0
- package/package.json +8 -6
package/LICENSE.txt
CHANGED
|
@@ -1,12 +1,206 @@
|
|
|
1
|
-
|
|
1
|
+
Apache License Version 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Salesforce, Inc.
|
|
2
4
|
All rights reserved.
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
5
193
|
|
|
6
|
-
|
|
194
|
+
Copyright {yyyy} {name of copyright owner}
|
|
7
195
|
|
|
8
|
-
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
9
199
|
|
|
10
|
-
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
201
|
|
|
12
|
-
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
package/lib/appInsights.d.ts
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
import { AsyncCreatable, Env } from '@salesforce/kit';
|
|
2
1
|
import * as appInsights from 'applicationinsights';
|
|
2
|
+
import { Properties, Attributes, TelemetryOptions } from './types';
|
|
3
|
+
import { BaseReporter } from './baseReporter';
|
|
3
4
|
export { TelemetryClient } from 'applicationinsights';
|
|
4
|
-
export type Properties = {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
};
|
|
7
|
-
export type Measurements = {
|
|
8
|
-
[key: string]: number;
|
|
9
|
-
};
|
|
10
|
-
export type Attributes = {
|
|
11
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
12
|
-
};
|
|
13
|
-
export type TelemetryOptions = {
|
|
14
|
-
project: string;
|
|
15
|
-
key: string;
|
|
16
|
-
commonProperties?: Properties;
|
|
17
|
-
contextTags?: Properties;
|
|
18
|
-
env?: Env;
|
|
19
|
-
gdprSensitiveKeys?: string[];
|
|
20
|
-
userId?: string;
|
|
21
|
-
sessionId?: string;
|
|
22
|
-
waitForConnection?: boolean;
|
|
23
|
-
};
|
|
24
|
-
export declare function getPlatformVersion(): string;
|
|
25
|
-
export declare function getCpus(): string;
|
|
26
|
-
export declare function buildPropertiesAndMeasurements(attributes: Attributes): {
|
|
27
|
-
properties: Properties;
|
|
28
|
-
measurements: Measurements;
|
|
29
|
-
};
|
|
30
5
|
/**
|
|
31
6
|
* This is a wrapper around appinsights sdk for convenience.
|
|
32
7
|
*
|
|
33
8
|
* NOTE: THis should not be used directly. Use TelemetryReporter which
|
|
34
9
|
* will check if telemetry is disabled and do GDPR checks.
|
|
35
10
|
*/
|
|
36
|
-
export declare class AppInsights extends
|
|
11
|
+
export declare class AppInsights extends BaseReporter {
|
|
37
12
|
static GDPR_HIDDEN: string;
|
|
38
13
|
static APP_INSIGHTS_SERVER: string;
|
|
39
14
|
private static ASIMOV_ENDPOINT;
|
|
@@ -84,7 +59,7 @@ export declare class AppInsights extends AsyncCreatable<TelemetryOptions> {
|
|
|
84
59
|
*
|
|
85
60
|
* @return {Properties} map of base properties and properties provided when class was created
|
|
86
61
|
*/
|
|
87
|
-
private
|
|
62
|
+
private buildAppInsightsCommonProperties;
|
|
88
63
|
/**
|
|
89
64
|
* Builds the context tags for appInsightsClient
|
|
90
65
|
*
|
package/lib/appInsights.js
CHANGED
|
@@ -15,86 +15,48 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.AppInsights = exports.TelemetryClient = void 0;
|
|
27
|
-
exports.getPlatformVersion = getPlatformVersion;
|
|
28
|
-
exports.getCpus = getCpus;
|
|
29
|
-
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
30
37
|
/*
|
|
31
38
|
* Copyright (c) 2021, salesforce.com, inc.
|
|
32
39
|
* All rights reserved.
|
|
33
40
|
* Licensed under the BSD 3-Clause license.
|
|
34
41
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
35
42
|
*/
|
|
36
|
-
const os = __importStar(require("node:os"));
|
|
37
43
|
const logger_1 = require("@salesforce/core/logger");
|
|
38
44
|
const kit_1 = require("@salesforce/kit");
|
|
39
45
|
const appInsights = __importStar(require("applicationinsights"));
|
|
46
|
+
const utils_1 = require("./utils");
|
|
47
|
+
const baseReporter_1 = require("./baseReporter");
|
|
40
48
|
var applicationinsights_1 = require("applicationinsights");
|
|
41
49
|
Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return applicationinsights_1.TelemetryClient; } });
|
|
42
|
-
function getPlatformVersion() {
|
|
43
|
-
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
|
|
44
|
-
}
|
|
45
|
-
function getCpus() {
|
|
46
|
-
const cpus = os.cpus();
|
|
47
|
-
if (cpus && cpus.length > 0) {
|
|
48
|
-
return `${cpus[0].model}(${cpus.length} x ${cpus[0].speed})`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return '';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const homeDir = os.homedir();
|
|
55
|
-
const sanitizeError = (err) => {
|
|
56
|
-
if (err.name) {
|
|
57
|
-
err.name = err.name.replace(homeDir, '~');
|
|
58
|
-
}
|
|
59
|
-
if (err.message) {
|
|
60
|
-
err.message = err.message.replace(homeDir, '~');
|
|
61
|
-
}
|
|
62
|
-
if (err.stack) {
|
|
63
|
-
// there might be lots of this one
|
|
64
|
-
err.stack = err.stack.replace(new RegExp(`\b${homeDir}\b`, 'gi'), '~');
|
|
65
|
-
}
|
|
66
|
-
return err;
|
|
67
|
-
};
|
|
68
|
-
function getSystemMemory() {
|
|
69
|
-
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
70
|
-
}
|
|
71
50
|
function isAsimovKey(key) {
|
|
72
51
|
return !!key?.startsWith('AIF-');
|
|
73
52
|
}
|
|
74
|
-
function buildPropertiesAndMeasurements(attributes) {
|
|
75
|
-
const properties = {};
|
|
76
|
-
const measurements = {};
|
|
77
|
-
Object.keys(attributes).forEach((key) => {
|
|
78
|
-
const value = attributes[key];
|
|
79
|
-
if (typeof value === 'string') {
|
|
80
|
-
properties[key] = value.replace(homeDir, '~');
|
|
81
|
-
}
|
|
82
|
-
else if (typeof value === 'number') {
|
|
83
|
-
measurements[key] = value;
|
|
84
|
-
}
|
|
85
|
-
else if (typeof value === 'boolean') {
|
|
86
|
-
properties[key] = value.toString();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return { properties, measurements };
|
|
90
|
-
}
|
|
91
53
|
/**
|
|
92
54
|
* This is a wrapper around appinsights sdk for convenience.
|
|
93
55
|
*
|
|
94
56
|
* NOTE: THis should not be used directly. Use TelemetryReporter which
|
|
95
57
|
* will check if telemetry is disabled and do GDPR checks.
|
|
96
58
|
*/
|
|
97
|
-
class AppInsights extends
|
|
59
|
+
class AppInsights extends baseReporter_1.BaseReporter {
|
|
98
60
|
static GDPR_HIDDEN = '<GDPR_HIDDEN>';
|
|
99
61
|
static APP_INSIGHTS_SERVER = 'https://dc.services.visualstudio.com';
|
|
100
62
|
static ASIMOV_ENDPOINT = 'https://vortex.data.microsoft.com/collect/v1';
|
|
@@ -129,7 +91,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
129
91
|
sendTelemetryEvent(eventName, attributes = {}) {
|
|
130
92
|
const name = `${this.options.project}/${eventName}`;
|
|
131
93
|
this.logger.debug(`Sending telemetry event: ${name}`);
|
|
132
|
-
const { properties, measurements } = buildPropertiesAndMeasurements(attributes);
|
|
94
|
+
const { properties, measurements } = (0, utils_1.buildPropertiesAndMeasurements)(attributes);
|
|
133
95
|
this.appInsightsClient.trackEvent({ name, properties, measurements });
|
|
134
96
|
}
|
|
135
97
|
/**
|
|
@@ -139,9 +101,9 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
139
101
|
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
140
102
|
*/
|
|
141
103
|
sendTelemetryException(exception, attributes = {}) {
|
|
142
|
-
const cleanException = sanitizeError(exception);
|
|
104
|
+
const cleanException = this.sanitizeError(exception);
|
|
143
105
|
this.logger.debug(`Sending telemetry exception: ${cleanException.message}`);
|
|
144
|
-
const { properties, measurements } = buildPropertiesAndMeasurements(attributes);
|
|
106
|
+
const { properties, measurements } = (0, utils_1.buildPropertiesAndMeasurements)(attributes);
|
|
145
107
|
this.appInsightsClient.trackException({ exception: cleanException, properties, measurements });
|
|
146
108
|
}
|
|
147
109
|
/**
|
|
@@ -181,7 +143,7 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
181
143
|
this.logger.debug('creating appInsightsClient');
|
|
182
144
|
appInsights.setup(this.options.key);
|
|
183
145
|
this.appInsightsClient = appInsights.defaultClient;
|
|
184
|
-
this.appInsightsClient.commonProperties = this.
|
|
146
|
+
this.appInsightsClient.commonProperties = this.buildAppInsightsCommonProperties();
|
|
185
147
|
this.appInsightsClient.context.tags = this.buildContextTags();
|
|
186
148
|
if (isAsimovKey(this.options.key)) {
|
|
187
149
|
this.appInsightsClient.config.endpointUrl = AppInsights.ASIMOV_ENDPOINT;
|
|
@@ -198,14 +160,9 @@ class AppInsights extends kit_1.AsyncCreatable {
|
|
|
198
160
|
*
|
|
199
161
|
* @return {Properties} map of base properties and properties provided when class was created
|
|
200
162
|
*/
|
|
201
|
-
|
|
202
|
-
const baseProperties =
|
|
203
|
-
|
|
204
|
-
'common.os': os.platform(),
|
|
205
|
-
'common.platformversion': getPlatformVersion(),
|
|
206
|
-
'common.systemmemory': getSystemMemory(),
|
|
207
|
-
'common.usertype': this.env.getString('SFDX_USER_TYPE') ?? 'normal',
|
|
208
|
-
};
|
|
163
|
+
buildAppInsightsCommonProperties() {
|
|
164
|
+
const baseProperties = this.buildCommonProperties();
|
|
165
|
+
baseProperties['common.usertype'] = this.env.getString('SFDX_USER_TYPE') ?? 'normal';
|
|
209
166
|
return Object.assign(baseProperties, this.options.commonProperties);
|
|
210
167
|
}
|
|
211
168
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncCreatable } from '@salesforce/kit';
|
|
2
|
+
import { Properties, TelemetryOptions } from './types';
|
|
3
|
+
export declare abstract class BaseReporter extends AsyncCreatable<TelemetryOptions> {
|
|
4
|
+
protected getPlatformVersion(): string;
|
|
5
|
+
protected getCpus(): string;
|
|
6
|
+
protected getSystemMemory(): string;
|
|
7
|
+
protected sanitizeError(err: Error): Error;
|
|
8
|
+
protected buildCommonProperties(extra?: Properties): Properties;
|
|
9
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.BaseReporter = void 0;
|
|
37
|
+
/*
|
|
38
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
39
|
+
* All rights reserved.
|
|
40
|
+
* Licensed under the BSD 3-Clause license.
|
|
41
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
42
|
+
*/
|
|
43
|
+
const os = __importStar(require("node:os"));
|
|
44
|
+
const kit_1 = require("@salesforce/kit");
|
|
45
|
+
class BaseReporter extends kit_1.AsyncCreatable {
|
|
46
|
+
// eslint-disable-next-line class-methods-use-this
|
|
47
|
+
getPlatformVersion() {
|
|
48
|
+
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line class-methods-use-this
|
|
51
|
+
getCpus() {
|
|
52
|
+
const cpus = os.cpus();
|
|
53
|
+
if (cpus && cpus.length > 0) {
|
|
54
|
+
return `${cpus[0].model}(${cpus.length} x ${cpus[0].speed})`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line class-methods-use-this
|
|
61
|
+
getSystemMemory() {
|
|
62
|
+
return `${(os.totalmem() / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line class-methods-use-this
|
|
65
|
+
sanitizeError(err) {
|
|
66
|
+
const homeDir = os.homedir();
|
|
67
|
+
const sanitizedErr = new Error(err.message);
|
|
68
|
+
sanitizedErr.name = err.name;
|
|
69
|
+
if (sanitizedErr.name) {
|
|
70
|
+
sanitizedErr.name = sanitizedErr.name.replace(homeDir, '~');
|
|
71
|
+
}
|
|
72
|
+
if (sanitizedErr.message) {
|
|
73
|
+
sanitizedErr.message = sanitizedErr.message.replace(homeDir, '~');
|
|
74
|
+
}
|
|
75
|
+
if (err.stack) {
|
|
76
|
+
// there might be lots of this one
|
|
77
|
+
sanitizedErr.stack = err.stack.replace(new RegExp(`\b${homeDir}\b`, 'gi'), '~');
|
|
78
|
+
}
|
|
79
|
+
return sanitizedErr;
|
|
80
|
+
}
|
|
81
|
+
buildCommonProperties(extra) {
|
|
82
|
+
const baseProperties = {
|
|
83
|
+
'common.cpus': this.getCpus(),
|
|
84
|
+
'common.os': os.platform(),
|
|
85
|
+
'common.platformversion': this.getPlatformVersion(),
|
|
86
|
+
'common.systemmemory': this.getSystemMemory(),
|
|
87
|
+
};
|
|
88
|
+
return Object.assign(baseProperties, extra);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BaseReporter = BaseReporter;
|
|
92
|
+
//# sourceMappingURL=baseReporter.js.map
|
package/lib/exported.d.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Attributes, Properties, TelemetryOptions } from './types';
|
|
2
|
+
import { BaseReporter } from './baseReporter';
|
|
3
|
+
export declare class O11yReporter extends BaseReporter {
|
|
4
|
+
private service;
|
|
5
|
+
private initialized;
|
|
6
|
+
private commonProperties;
|
|
7
|
+
private extensionName;
|
|
8
|
+
constructor(options: TelemetryOptions);
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
sendTelemetryEvent(eventName: string, attributes?: Attributes): Promise<void>;
|
|
11
|
+
flush(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Publishes exception to O11y service
|
|
14
|
+
*
|
|
15
|
+
* @param exception {Error} - exception you want published.
|
|
16
|
+
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
17
|
+
*/
|
|
18
|
+
sendTelemetryException(exception: Error, attributes?: Attributes): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Publishes diagnostic information to O11y service
|
|
21
|
+
*
|
|
22
|
+
* @param traceMessage {string} - trace message to send to O11y.
|
|
23
|
+
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
24
|
+
*/
|
|
25
|
+
sendTelemetryTrace(traceMessage: string, properties?: Properties): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Publishes metric to O11y service
|
|
28
|
+
*
|
|
29
|
+
* @param metricName {string} - name of the metric you want published
|
|
30
|
+
* @param value {number} - value of the metric
|
|
31
|
+
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
32
|
+
*/
|
|
33
|
+
sendTelemetryMetric(metricName: string, value: number, properties?: Properties): Promise<void>;
|
|
34
|
+
private buildO11yCommonProperties;
|
|
35
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.O11yReporter = 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 o11y_reporter_1 = require("@salesforce/o11y-reporter");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const baseReporter_1 = require("./baseReporter");
|
|
13
|
+
class O11yReporter extends baseReporter_1.BaseReporter {
|
|
14
|
+
service;
|
|
15
|
+
initialized;
|
|
16
|
+
commonProperties;
|
|
17
|
+
extensionName = '';
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
this.extensionName = options.extensionName ?? options.project;
|
|
21
|
+
this.service = o11y_reporter_1.O11yService.getInstance(this.extensionName);
|
|
22
|
+
this.initialized = this.service.initialize(this.extensionName, options.o11yUploadEndpoint);
|
|
23
|
+
this.commonProperties = this.buildO11yCommonProperties(options.commonProperties);
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
await this.initialized;
|
|
27
|
+
}
|
|
28
|
+
async sendTelemetryEvent(eventName, attributes = {}) {
|
|
29
|
+
const merged = { ...this.commonProperties, ...attributes };
|
|
30
|
+
this.service.logEvent({ eventName: `${this.extensionName}/${eventName}`, ...merged });
|
|
31
|
+
await this.service.upload();
|
|
32
|
+
}
|
|
33
|
+
async flush() {
|
|
34
|
+
await this.service.upload();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Publishes exception to O11y service
|
|
38
|
+
*
|
|
39
|
+
* @param exception {Error} - exception you want published.
|
|
40
|
+
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
41
|
+
*/
|
|
42
|
+
async sendTelemetryException(exception, attributes = {}) {
|
|
43
|
+
const cleanException = this.sanitizeError(exception);
|
|
44
|
+
const { properties, measurements } = (0, utils_1.buildPropertiesAndMeasurements)(attributes);
|
|
45
|
+
// Create exception event with sanitized error information
|
|
46
|
+
const exceptionEvent = {
|
|
47
|
+
eventName: 'exception',
|
|
48
|
+
exceptionName: cleanException.name,
|
|
49
|
+
exceptionMessage: cleanException.message,
|
|
50
|
+
exceptionStack: cleanException.stack,
|
|
51
|
+
...properties,
|
|
52
|
+
...measurements,
|
|
53
|
+
};
|
|
54
|
+
this.service.logEvent(exceptionEvent);
|
|
55
|
+
await this.service.upload();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Publishes diagnostic information to O11y service
|
|
59
|
+
*
|
|
60
|
+
* @param traceMessage {string} - trace message to send to O11y.
|
|
61
|
+
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
62
|
+
*/
|
|
63
|
+
async sendTelemetryTrace(traceMessage, properties) {
|
|
64
|
+
const traceEvent = {
|
|
65
|
+
eventName: 'trace',
|
|
66
|
+
message: traceMessage,
|
|
67
|
+
...properties,
|
|
68
|
+
};
|
|
69
|
+
this.service.logEvent(traceEvent);
|
|
70
|
+
await this.service.upload();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Publishes metric to O11y service
|
|
74
|
+
*
|
|
75
|
+
* @param metricName {string} - name of the metric you want published
|
|
76
|
+
* @param value {number} - value of the metric
|
|
77
|
+
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
78
|
+
*/
|
|
79
|
+
async sendTelemetryMetric(metricName, value, properties) {
|
|
80
|
+
const metricEvent = {
|
|
81
|
+
eventName: 'metric',
|
|
82
|
+
metricName,
|
|
83
|
+
value,
|
|
84
|
+
...properties,
|
|
85
|
+
};
|
|
86
|
+
this.service.logEvent(metricEvent);
|
|
87
|
+
await this.service.upload();
|
|
88
|
+
}
|
|
89
|
+
buildO11yCommonProperties(extra) {
|
|
90
|
+
const baseProperties = this.buildCommonProperties(extra);
|
|
91
|
+
baseProperties['common.extensionName'] = this.extensionName;
|
|
92
|
+
return baseProperties;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.O11yReporter = O11yReporter;
|
|
96
|
+
//# sourceMappingURL=o11yReporter.js.map
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { AsyncCreatable } from '@salesforce/kit';
|
|
2
|
-
import { type Attributes, type Properties, type TelemetryOptions } from './appInsights';
|
|
3
2
|
import { TelemetryClient } from './appInsights';
|
|
4
|
-
|
|
3
|
+
import { Attributes, Properties, TelemetryOptions } from './types';
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* This is the main telemetry reporter that should be used by consumers.
|
|
6
|
+
* It will check if telemetry is disabled and do GDPR checks.
|
|
7
7
|
*/
|
|
8
8
|
export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
|
|
9
9
|
private enabled;
|
|
10
10
|
private options;
|
|
11
11
|
private logger;
|
|
12
12
|
private reporter;
|
|
13
|
+
private enableO11y;
|
|
14
|
+
private o11yReporter?;
|
|
13
15
|
constructor(options: TelemetryOptions);
|
|
14
16
|
/**
|
|
15
17
|
* @deprecated Use the standalone function isEnabled() instead.
|
|
@@ -31,28 +33,28 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
|
|
|
31
33
|
waitForConnection(): Promise<void>;
|
|
32
34
|
testConnection(): Promise<boolean>;
|
|
33
35
|
/**
|
|
34
|
-
* Sends message to
|
|
36
|
+
* Sends message to both AppInsights and O11y (if enabled).
|
|
35
37
|
*
|
|
36
38
|
* @param eventName {string} - name of the event you want published.
|
|
37
39
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
38
40
|
*/
|
|
39
41
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): void;
|
|
40
42
|
/**
|
|
41
|
-
* Sends exception to
|
|
43
|
+
* Sends exception to both AppInsights and O11y (if enabled).
|
|
42
44
|
*
|
|
43
45
|
* @param exception {Error} - exception you want published.
|
|
44
|
-
* @param attributes {Attributes} - map of measurements to publish alongside the
|
|
46
|
+
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
45
47
|
*/
|
|
46
48
|
sendTelemetryException(exception: Error, attributes?: Attributes): void;
|
|
47
49
|
/**
|
|
48
|
-
* Publishes diagnostic information to
|
|
50
|
+
* Publishes diagnostic information to both AppInsights and O11y (if enabled).
|
|
49
51
|
*
|
|
50
|
-
* @param traceMessage {string} - trace message to
|
|
52
|
+
* @param traceMessage {string} - trace message to send to app insights.
|
|
51
53
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
52
54
|
*/
|
|
53
55
|
sendTelemetryTrace(traceMessage: string, properties?: Properties): void;
|
|
54
56
|
/**
|
|
55
|
-
* Publishes metric to
|
|
57
|
+
* Publishes metric to both AppInsights and O11y (if enabled).
|
|
56
58
|
*
|
|
57
59
|
* @param metricName {string} - name of the metric you want published
|
|
58
60
|
* @param value {number} - value of the metric
|
package/lib/telemetryReporter.js
CHANGED
|
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.TelemetryReporter =
|
|
39
|
+
exports.TelemetryReporter = void 0;
|
|
30
40
|
/*
|
|
31
41
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
32
42
|
* All rights reserved.
|
|
@@ -40,19 +50,22 @@ const got_1 = __importDefault(require("got"));
|
|
|
40
50
|
const proxy_agent_1 = require("proxy-agent");
|
|
41
51
|
const appInsights_1 = require("./appInsights");
|
|
42
52
|
const enabledCheck_1 = require("./enabledCheck");
|
|
43
|
-
|
|
44
|
-
Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return appInsights_2.TelemetryClient; } });
|
|
53
|
+
const o11yReporter_1 = require("./o11yReporter");
|
|
45
54
|
/**
|
|
46
|
-
*
|
|
55
|
+
* This is the main telemetry reporter that should be used by consumers.
|
|
56
|
+
* It will check if telemetry is disabled and do GDPR checks.
|
|
47
57
|
*/
|
|
48
58
|
class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
49
59
|
enabled = false;
|
|
50
60
|
options;
|
|
51
61
|
logger;
|
|
52
62
|
reporter;
|
|
63
|
+
enableO11y;
|
|
64
|
+
o11yReporter;
|
|
53
65
|
constructor(options) {
|
|
54
66
|
super(options);
|
|
55
67
|
this.options = options;
|
|
68
|
+
this.enableO11y = options.enableO11y ?? false; // default to false for backward compatibility
|
|
56
69
|
}
|
|
57
70
|
/**
|
|
58
71
|
* @deprecated Use the standalone function isEnabled() instead.
|
|
@@ -68,6 +81,22 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
68
81
|
if (this.options.waitForConnection)
|
|
69
82
|
await this.waitForConnection();
|
|
70
83
|
this.reporter = await appInsights_1.AppInsights.create(this.options);
|
|
84
|
+
// Only initialize O11yReporter if telemetry is enabled, enableO11y is true AND o11yUploadEndpoint is provided
|
|
85
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y) {
|
|
86
|
+
if (this.options.o11yUploadEndpoint) {
|
|
87
|
+
try {
|
|
88
|
+
this.o11yReporter = new o11yReporter_1.O11yReporter(this.options);
|
|
89
|
+
this.logger.debug('O11y reporter initialized successfully');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
this.logger.warn('Failed to initialize O11y reporter:', error);
|
|
93
|
+
this.o11yReporter = undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.logger.warn('O11y reporter not initialized: o11yUploadEndpoint is missing.');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
71
100
|
}
|
|
72
101
|
/**
|
|
73
102
|
* Starts data collection services. This is for long running processes. Short lived
|
|
@@ -82,6 +111,7 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
82
111
|
*/
|
|
83
112
|
stop() {
|
|
84
113
|
this.reporter.stop();
|
|
114
|
+
void this.o11yReporter?.flush();
|
|
85
115
|
}
|
|
86
116
|
async waitForConnection() {
|
|
87
117
|
const canConnect = await this.testConnection();
|
|
@@ -119,51 +149,84 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
119
149
|
}
|
|
120
150
|
}
|
|
121
151
|
/**
|
|
122
|
-
* Sends message to
|
|
152
|
+
* Sends message to both AppInsights and O11y (if enabled).
|
|
123
153
|
*
|
|
124
154
|
* @param eventName {string} - name of the event you want published.
|
|
125
155
|
* @param attributes {Attributes} - map of properties to publish alongside the event.
|
|
126
156
|
*/
|
|
127
157
|
sendTelemetryEvent(eventName, attributes = {}) {
|
|
158
|
+
// Send to AppInsights only if SFDX telemetry is enabled
|
|
128
159
|
if (this.isSfdxTelemetryEnabled()) {
|
|
129
160
|
this.reporter.sendTelemetryEvent(eventName, attributes);
|
|
130
161
|
}
|
|
162
|
+
// Send to O11y if telemetry is enabled and O11y is enabled
|
|
163
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
164
|
+
void this.o11yReporter.sendTelemetryEvent(eventName, attributes).catch((error) => {
|
|
165
|
+
this.logger.debug('Failed to send event to O11y:', error);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
131
168
|
}
|
|
132
169
|
/**
|
|
133
|
-
* Sends exception to
|
|
170
|
+
* Sends exception to both AppInsights and O11y (if enabled).
|
|
134
171
|
*
|
|
135
172
|
* @param exception {Error} - exception you want published.
|
|
136
|
-
* @param attributes {Attributes} - map of measurements to publish alongside the
|
|
173
|
+
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
|
|
137
174
|
*/
|
|
138
175
|
sendTelemetryException(exception, attributes = {}) {
|
|
176
|
+
// Send to AppInsights only if SFDX telemetry is enabled
|
|
139
177
|
if (this.isSfdxTelemetryEnabled()) {
|
|
140
178
|
// Scrub stack for GDPR
|
|
141
|
-
|
|
142
|
-
|
|
179
|
+
const sanitizedException = new Error(exception.message);
|
|
180
|
+
sanitizedException.name = exception.name;
|
|
181
|
+
sanitizedException.stack = exception.stack?.replace(new RegExp(os.homedir(), 'g'), appInsights_1.AppInsights.GDPR_HIDDEN);
|
|
182
|
+
// Send to AppInsights
|
|
183
|
+
this.reporter.sendTelemetryException(sanitizedException, attributes);
|
|
184
|
+
}
|
|
185
|
+
// Send to O11y if telemetry is enabled and O11y is enabled
|
|
186
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
187
|
+
void this.o11yReporter.sendTelemetryException(exception, attributes).catch((error) => {
|
|
188
|
+
this.logger.debug('Failed to send exception to O11y:', error);
|
|
189
|
+
});
|
|
143
190
|
}
|
|
144
191
|
}
|
|
145
192
|
/**
|
|
146
|
-
* Publishes diagnostic information to
|
|
193
|
+
* Publishes diagnostic information to both AppInsights and O11y (if enabled).
|
|
147
194
|
*
|
|
148
|
-
* @param traceMessage {string} - trace message to
|
|
195
|
+
* @param traceMessage {string} - trace message to send to app insights.
|
|
149
196
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
150
197
|
*/
|
|
151
198
|
sendTelemetryTrace(traceMessage, properties) {
|
|
199
|
+
// Send to AppInsights only if SFDX telemetry is enabled
|
|
152
200
|
if (this.isSfdxTelemetryEnabled()) {
|
|
201
|
+
// Send to AppInsights
|
|
153
202
|
this.reporter.sendTelemetryTrace(traceMessage, properties);
|
|
154
203
|
}
|
|
204
|
+
// Send to O11y if telemetry is enabled and O11y is enabled
|
|
205
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
206
|
+
void this.o11yReporter.sendTelemetryTrace(traceMessage, properties).catch((error) => {
|
|
207
|
+
this.logger.debug('Failed to send trace to O11y:', error);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
155
210
|
}
|
|
156
211
|
/**
|
|
157
|
-
* Publishes metric to
|
|
212
|
+
* Publishes metric to both AppInsights and O11y (if enabled).
|
|
158
213
|
*
|
|
159
214
|
* @param metricName {string} - name of the metric you want published
|
|
160
215
|
* @param value {number} - value of the metric
|
|
161
216
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
162
217
|
*/
|
|
163
218
|
sendTelemetryMetric(metricName, value, properties) {
|
|
219
|
+
// Send to AppInsights only if SFDX telemetry is enabled
|
|
164
220
|
if (this.isSfdxTelemetryEnabled()) {
|
|
221
|
+
// Send to AppInsights
|
|
165
222
|
this.reporter.sendTelemetryMetric(metricName, value, properties);
|
|
166
223
|
}
|
|
224
|
+
// Send to O11y if telemetry is enabled and O11y is enabled
|
|
225
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
226
|
+
void this.o11yReporter.sendTelemetryMetric(metricName, value, properties).catch((error) => {
|
|
227
|
+
this.logger.debug('Failed to send metric to O11y:', error);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
167
230
|
}
|
|
168
231
|
/**
|
|
169
232
|
* Determine if the telemetry event should be logged.
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Env } from '@salesforce/kit';
|
|
2
|
+
export type Properties = {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
export type Measurements = {
|
|
6
|
+
[key: string]: number;
|
|
7
|
+
};
|
|
8
|
+
export type Attributes = {
|
|
9
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type TelemetryOptions = {
|
|
12
|
+
project: string;
|
|
13
|
+
key: string;
|
|
14
|
+
commonProperties?: Properties;
|
|
15
|
+
contextTags?: Properties;
|
|
16
|
+
env?: Env;
|
|
17
|
+
gdprSensitiveKeys?: string[];
|
|
18
|
+
userId?: string;
|
|
19
|
+
sessionId?: string;
|
|
20
|
+
waitForConnection?: boolean;
|
|
21
|
+
o11yUploadEndpoint?: string;
|
|
22
|
+
enableO11y?: boolean;
|
|
23
|
+
enableAppInsights?: boolean;
|
|
24
|
+
extensionName?: string;
|
|
25
|
+
};
|
package/lib/types.js
ADDED
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPropertiesAndMeasurements = buildPropertiesAndMeasurements;
|
|
4
|
+
function buildPropertiesAndMeasurements(attributes) {
|
|
5
|
+
const properties = {};
|
|
6
|
+
const measurements = {};
|
|
7
|
+
Object.keys(attributes).forEach((key) => {
|
|
8
|
+
const value = attributes[key];
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
properties[key] = value.replace(process.env.HOME ?? '', '~');
|
|
11
|
+
}
|
|
12
|
+
else if (typeof value === 'number') {
|
|
13
|
+
measurements[key] = value;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof value === 'boolean') {
|
|
16
|
+
properties[key] = value.toString();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return { properties, measurements };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/telemetry",
|
|
3
|
-
"version": "6.0
|
|
4
|
-
"description": "Library for
|
|
3
|
+
"version": "6.1.0",
|
|
4
|
+
"description": "Library for telemetry reporting to Application Insights and O11y",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./enabledCheck": "./lib/enabledCheck.js",
|
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": "forcedotcom/telemetry",
|
|
11
11
|
"author": "Salesforce",
|
|
12
|
-
"license": "
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "wireit",
|
|
15
15
|
"clean": "sf-clean",
|
|
16
16
|
"clean-all": "sf-clean all",
|
|
17
17
|
"compile": "wireit",
|
|
18
18
|
"docs": "sf-docs",
|
|
19
|
+
"fix-license": "eslint src test --fix --rule \"header/header: [2]\"",
|
|
19
20
|
"format": "wireit",
|
|
20
21
|
"link-check": "wireit",
|
|
21
22
|
"lint": "wireit",
|
|
@@ -42,12 +43,13 @@
|
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@salesforce/core": "^8.8.0",
|
|
44
45
|
"@salesforce/kit": "^3.2.3",
|
|
46
|
+
"@salesforce/o11y-reporter": "1.1.1",
|
|
45
47
|
"applicationinsights": "^2.9.6",
|
|
46
48
|
"got": "^11",
|
|
47
|
-
"proxy-agent": "^6.
|
|
49
|
+
"proxy-agent": "^6.5.0"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@salesforce/dev-scripts": "^
|
|
52
|
+
"@salesforce/dev-scripts": "^11.0.2",
|
|
51
53
|
"ts-node": "^10.9.2",
|
|
52
54
|
"typescript": "^5.5.4"
|
|
53
55
|
},
|
|
@@ -128,7 +130,7 @@
|
|
|
128
130
|
"output": []
|
|
129
131
|
},
|
|
130
132
|
"link-check": {
|
|
131
|
-
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
|
|
133
|
+
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|localhost|%s\" --markdown --retry --directory-listing --verbosity error",
|
|
132
134
|
"files": [
|
|
133
135
|
"./*.md",
|
|
134
136
|
"./!(CHANGELOG).md",
|