@salesforce/telemetry 6.5.2 → 6.6.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/README.md +2 -2
- package/lib/exported.d.ts +1 -1
- package/lib/o11yReporter.d.ts +16 -5
- package/lib/o11yReporter.js +25 -9
- package/lib/telemetryReporter.d.ts +15 -5
- package/lib/telemetryReporter.js +21 -5
- package/lib/types.d.ts +43 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -107,8 +107,8 @@ const reporter = await TelemetryReporter.create({
|
|
|
107
107
|
reporter.start();
|
|
108
108
|
// Default events use the default schema
|
|
109
109
|
reporter.sendTelemetryEvent('event-name', { foo: 'bar' });
|
|
110
|
-
//
|
|
111
|
-
reporter.sendTelemetryEventWithSchema(
|
|
110
|
+
// Schema-specific events: pass only attributes (must include all fields required by the schema; no properties added by reporter)
|
|
111
|
+
reporter.sendTelemetryEventWithSchema({ userId: 'user-1', action: 'view', eventName: 'pftEventName' }, pdpEventSchema);
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
**Note:** `sendTelemetryEventWithSchema` sends only to O11y (not AppInsights). Use it for events that must conform to a given schema; use `sendTelemetryEvent` for all other events.
|
package/lib/exported.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { TelemetryReporter } from './telemetryReporter';
|
|
|
2
2
|
export * from './telemetryReporter';
|
|
3
3
|
export { isEnabled } from './enabledCheck';
|
|
4
4
|
export default TelemetryReporter;
|
|
5
|
-
export type { Attributes, O11ySchema, O11yBatchingConfig } from './types';
|
|
5
|
+
export type { Attributes, O11ySchema, O11yBatchingConfig, PdpEvent } from './types';
|
package/lib/o11yReporter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BatchingOptions } from '@salesforce/o11y-reporter';
|
|
2
|
-
import { Attributes, O11ySchema, Properties, TelemetryOptions } from './types';
|
|
2
|
+
import { Attributes, O11ySchema, PdpEvent, Properties, TelemetryOptions } from './types';
|
|
3
3
|
import { BaseReporter } from './baseReporter';
|
|
4
4
|
export declare class O11yReporter extends BaseReporter {
|
|
5
5
|
private service;
|
|
@@ -40,12 +40,23 @@ export declare class O11yReporter extends BaseReporter {
|
|
|
40
40
|
* Use this method when you need to send events that conform to a particular schema
|
|
41
41
|
* (e.g. PFT/pdpEventSchema). Only the events you send via this method use the given schema;
|
|
42
42
|
* all other events use the default schema via sendTelemetryEvent.
|
|
43
|
+
* Only the caller-provided attributes are sent; no properties (e.g. eventName, common.*)
|
|
44
|
+
* are added by the reporter.
|
|
43
45
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
46
|
+
* The schema is the O11y encoding schema (e.g. from the o11y_schema package), not JSON Schema,
|
|
47
|
+
* so this library does not derive or run validation here. Callers should validate attributes
|
|
48
|
+
* (e.g. with zod) before calling, using the same schema context they use when importing the schema.
|
|
49
|
+
*
|
|
50
|
+
* @param attributes - Properties and measurements to publish (only these are sent; no properties added)
|
|
51
|
+
* @param schema - O11y encoding schema (e.g. from o11y_schema package)
|
|
52
|
+
*/
|
|
53
|
+
sendTelemetryEventWithSchema(attributes: Attributes, schema: O11ySchema): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Sends a PDP event via O11y service.
|
|
56
|
+
*
|
|
57
|
+
* @param event - PDP event to send.
|
|
47
58
|
*/
|
|
48
|
-
|
|
59
|
+
sendPdpEvent(event: PdpEvent): Promise<void>;
|
|
49
60
|
flush(): Promise<void>;
|
|
50
61
|
/**
|
|
51
62
|
* Publishes exception to O11y service
|
package/lib/o11yReporter.js
CHANGED
|
@@ -17,6 +17,9 @@ exports.O11yReporter = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const o11y_reporter_1 = require("@salesforce/o11y-reporter");
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
21
|
+
// @ts-ignore o11y_schema/sf_pdp.d.ts is not a valid module
|
|
22
|
+
const sf_pdp_1 = require("o11y_schema/sf_pdp");
|
|
20
23
|
const baseReporter_1 = require("./baseReporter");
|
|
21
24
|
const utils_1 = require("./utils");
|
|
22
25
|
class O11yReporter extends baseReporter_1.BaseReporter {
|
|
@@ -88,23 +91,36 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
88
91
|
* Use this method when you need to send events that conform to a particular schema
|
|
89
92
|
* (e.g. PFT/pdpEventSchema). Only the events you send via this method use the given schema;
|
|
90
93
|
* all other events use the default schema via sendTelemetryEvent.
|
|
94
|
+
* Only the caller-provided attributes are sent; no properties (e.g. eventName, common.*)
|
|
95
|
+
* are added by the reporter.
|
|
91
96
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
97
|
+
* The schema is the O11y encoding schema (e.g. from the o11y_schema package), not JSON Schema,
|
|
98
|
+
* so this library does not derive or run validation here. Callers should validate attributes
|
|
99
|
+
* (e.g. with zod) before calling, using the same schema context they use when importing the schema.
|
|
100
|
+
*
|
|
101
|
+
* @param attributes - Properties and measurements to publish (only these are sent; no properties added)
|
|
102
|
+
* @param schema - O11y encoding schema (e.g. from o11y_schema package)
|
|
95
103
|
*/
|
|
96
|
-
async sendTelemetryEventWithSchema(
|
|
104
|
+
async sendTelemetryEventWithSchema(attributes, schema) {
|
|
97
105
|
await this.initialized;
|
|
98
|
-
const
|
|
99
|
-
const eventData = {
|
|
100
|
-
eventName: `${this.extensionName}/${eventName}`,
|
|
101
|
-
...merged,
|
|
102
|
-
};
|
|
106
|
+
const eventData = { ...attributes };
|
|
103
107
|
this.service.logEventWithSchema(eventData, schema);
|
|
104
108
|
if (!this._batchingEnabled) {
|
|
105
109
|
await this.service.forceFlush();
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Sends a PDP event via O11y service.
|
|
114
|
+
*
|
|
115
|
+
* @param event - PDP event to send.
|
|
116
|
+
*/
|
|
117
|
+
async sendPdpEvent(event) {
|
|
118
|
+
await this.initialized;
|
|
119
|
+
this.service.logEventWithSchema(event, sf_pdp_1.pdpEventSchema);
|
|
120
|
+
if (!this._batchingEnabled) {
|
|
121
|
+
await this.service.forceFlush();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
108
124
|
async flush() {
|
|
109
125
|
// Wait for initialization to complete before using the service
|
|
110
126
|
await this.initialized;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncCreatable } from '@salesforce/kit';
|
|
2
2
|
import type { BatchingOptions } from '@salesforce/o11y-reporter';
|
|
3
3
|
import { TelemetryClient } from './appInsights';
|
|
4
|
-
import { Attributes, O11ySchema, Properties, TelemetryOptions } from './types';
|
|
4
|
+
import { Attributes, O11ySchema, PdpEvent, Properties, TelemetryOptions } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* This is the main telemetry reporter that should be used by consumers.
|
|
7
7
|
* It will check if telemetry is disabled and do GDPR checks.
|
|
@@ -38,12 +38,22 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
|
|
|
38
38
|
* Sends a telemetry event to O11y only with a specific schema.
|
|
39
39
|
* Use this for events that must conform to a given schema (e.g. PFT/pdpEventSchema).
|
|
40
40
|
* Does not send to AppInsights. Only sends when O11y is enabled and reporter is initialized.
|
|
41
|
+
* Only the caller-provided attributes are sent; no properties are added by the reporter.
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* The schema is the O11y encoding schema (e.g. from the o11y_schema package), not JSON Schema,
|
|
44
|
+
* so this library does not derive or run validation here. Callers should validate attributes
|
|
45
|
+
* (e.g. with zod) before calling, using the same schema context they use when importing the schema.
|
|
46
|
+
*
|
|
47
|
+
* @param attributes - Properties and measurements to publish (only these are sent)
|
|
48
|
+
* @param schema - O11y encoding schema (e.g. from o11y_schema package)
|
|
49
|
+
*/
|
|
50
|
+
sendTelemetryEventWithSchema(attributes: Attributes, schema: O11ySchema): void;
|
|
51
|
+
/**
|
|
52
|
+
* Sends a PDP event via O11y.
|
|
53
|
+
*
|
|
54
|
+
* @param event - PDP event data to send.
|
|
45
55
|
*/
|
|
46
|
-
|
|
56
|
+
sendPdpEvent(event: PdpEvent): void;
|
|
47
57
|
/**
|
|
48
58
|
* Sends message to both AppInsights and O11y (if enabled).
|
|
49
59
|
*
|
package/lib/telemetryReporter.js
CHANGED
|
@@ -191,18 +191,34 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
191
191
|
* Sends a telemetry event to O11y only with a specific schema.
|
|
192
192
|
* Use this for events that must conform to a given schema (e.g. PFT/pdpEventSchema).
|
|
193
193
|
* Does not send to AppInsights. Only sends when O11y is enabled and reporter is initialized.
|
|
194
|
+
* Only the caller-provided attributes are sent; no properties are added by the reporter.
|
|
194
195
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
196
|
+
* The schema is the O11y encoding schema (e.g. from the o11y_schema package), not JSON Schema,
|
|
197
|
+
* so this library does not derive or run validation here. Callers should validate attributes
|
|
198
|
+
* (e.g. with zod) before calling, using the same schema context they use when importing the schema.
|
|
199
|
+
*
|
|
200
|
+
* @param attributes - Properties and measurements to publish (only these are sent)
|
|
201
|
+
* @param schema - O11y encoding schema (e.g. from o11y_schema package)
|
|
198
202
|
*/
|
|
199
|
-
sendTelemetryEventWithSchema(
|
|
203
|
+
sendTelemetryEventWithSchema(attributes, schema) {
|
|
200
204
|
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
201
|
-
void this.o11yReporter.sendTelemetryEventWithSchema(
|
|
205
|
+
void this.o11yReporter.sendTelemetryEventWithSchema(attributes, schema).catch((error) => {
|
|
202
206
|
this.logger.debug('Failed to send event with schema to O11y:', error);
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Sends a PDP event via O11y.
|
|
212
|
+
*
|
|
213
|
+
* @param event - PDP event data to send.
|
|
214
|
+
*/
|
|
215
|
+
sendPdpEvent(event) {
|
|
216
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
217
|
+
void this.o11yReporter.sendPdpEvent(event).catch((error) => {
|
|
218
|
+
this.logger.debug('Failed to send PDP event to O11y:', error);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
206
222
|
/**
|
|
207
223
|
* Sends message to both AppInsights and O11y (if enabled).
|
|
208
224
|
*
|
package/lib/types.d.ts
CHANGED
|
@@ -15,6 +15,49 @@ export type Attributes = {
|
|
|
15
15
|
* (not a primitive, null, or undefined).
|
|
16
16
|
*/
|
|
17
17
|
export type O11ySchema = Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* PDP Product Feature Taxonomy (PFT) event sent via O11y.
|
|
20
|
+
*/
|
|
21
|
+
export type PdpEvent = {
|
|
22
|
+
/**
|
|
23
|
+
* Unique identifier for the event. Follows this naming convention:
|
|
24
|
+
* <object>.<action>
|
|
25
|
+
*
|
|
26
|
+
* object = Specific object within the Product Feature that give us context around the action in lowerCamelCase format.
|
|
27
|
+
* Note: The object name can include context around the Product Feature (eg. slackforceMessage).
|
|
28
|
+
* Examples: calculatedInsightsRecord,checkoutPaymentmethod, slackforceMessage, promptBuilderTemplate
|
|
29
|
+
*
|
|
30
|
+
* action = Action the user takes in past tense. This should only be ONE word, in lower case
|
|
31
|
+
* Examples: processed, selected, sent, saved
|
|
32
|
+
*/
|
|
33
|
+
eventName: `${string}.${string}`;
|
|
34
|
+
/**
|
|
35
|
+
* Product Feature ID from GUS.
|
|
36
|
+
*
|
|
37
|
+
* Examples:
|
|
38
|
+
* Salesforce CLI = aJCEE0000000mHP4AY
|
|
39
|
+
* Salesforce Extensions for VS Code = aJCEE0000000mLm4AI
|
|
40
|
+
*/
|
|
41
|
+
productFeatureId: `aJC${string}`;
|
|
42
|
+
/**
|
|
43
|
+
* Populate this if there is a unique component with your Event for which a distinct count would be a relevant metric
|
|
44
|
+
* E.g., CLI plugin command name (<pluginName.commandName>) or ext command name.
|
|
45
|
+
*/
|
|
46
|
+
componentId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Populate this if there is a unique quantity with your Event for which a sum would be a relevant metric for your
|
|
49
|
+
* Product Feature. E.g., rowsProcessed → total Rows processed for Data Streams.
|
|
50
|
+
*/
|
|
51
|
+
eventVolume?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Use this field to specify the name of your flexible attribute (eg. experimentId, buttonColor).
|
|
54
|
+
*/
|
|
55
|
+
contextName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Use this field to specify the value of your flexible attribute (eg. exp_123, green).
|
|
58
|
+
*/
|
|
59
|
+
contextValue?: string;
|
|
60
|
+
};
|
|
18
61
|
/**
|
|
19
62
|
* Batching configuration for O11y telemetry
|
|
20
63
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/telemetry",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"description": "Library for telemetry reporting to Application Insights and O11y",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"exports": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@salesforce/o11y-reporter": "1.7.3",
|
|
47
47
|
"applicationinsights": "^2.9.8",
|
|
48
48
|
"got": "^11",
|
|
49
|
+
"o11y_schema": "^260.41.0",
|
|
49
50
|
"proxy-agent": "^6.5.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|