@salesforce/telemetry 6.4.8 → 6.5.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 +18 -15
- package/lib/o11yReporter.d.ts +11 -9
- package/lib/o11yReporter.js +26 -41
- package/lib/telemetryReporter.d.ts +11 -1
- package/lib/telemetryReporter.js +16 -0
- package/lib/types.d.ts +0 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ const reporter = await TelemetryReporter.create({
|
|
|
56
56
|
key: 'my-instrumentation-key', // Required for Application Insights
|
|
57
57
|
enableO11y: true,
|
|
58
58
|
o11yUploadEndpoint: 'https://your-o11y-endpoint.com/upload',
|
|
59
|
-
extensionName: 'my-extension' // Optional, defaults to project name
|
|
59
|
+
extensionName: 'my-extension', // Optional, defaults to project name
|
|
60
60
|
});
|
|
61
61
|
```
|
|
62
62
|
|
|
@@ -70,15 +70,15 @@ const reporter = await TelemetryReporter.create({
|
|
|
70
70
|
enableO11y: true,
|
|
71
71
|
enableAppInsights: false, // Disable AppInsights
|
|
72
72
|
o11yUploadEndpoint: 'https://your-o11y-endpoint.com/upload',
|
|
73
|
-
extensionName: 'my-extension' // Optional, defaults to project name
|
|
73
|
+
extensionName: 'my-extension', // Optional, defaults to project name
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
**Note:** O11y telemetry respects the same telemetry enablement settings as Application Insights. If telemetry is disabled via `SF_DISABLE_TELEMETRY` or other configuration, O11y events will not be sent.
|
|
78
78
|
|
|
79
|
-
#### Custom Schema Support
|
|
79
|
+
#### Custom Schema Support (sendTelemetryEventWithSchema)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
To send events that conform to a specific O11y schema (e.g. PFT/pdpEventSchema), use `sendTelemetryEventWithSchema` instead of passing a schema in config. This keeps default events on the default schema and restricts schema-specific events (e.g. PFT) to the method that accepts a schema per call.
|
|
82
82
|
|
|
83
83
|
**Step 1: Add `o11y_schema` to your `package.json`:**
|
|
84
84
|
|
|
@@ -90,32 +90,35 @@ The telemetry reporter supports consumer-provided O11y schemas. This allows cons
|
|
|
90
90
|
}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
**Step 2:
|
|
93
|
+
**Step 2: Send events with a schema only when needed:**
|
|
94
94
|
|
|
95
95
|
```javascript
|
|
96
96
|
import TelemetryReporter from '@salesforce/telemetry';
|
|
97
|
-
// Import the schema object from o11y_schema
|
|
98
|
-
import {
|
|
97
|
+
// Import the schema object from o11y_schema (e.g. for PFT events)
|
|
98
|
+
import { pdpEventSchema } from 'o11y_schema/sf_pdpEvent';
|
|
99
99
|
|
|
100
100
|
const reporter = await TelemetryReporter.create({
|
|
101
101
|
project: 'my-project-name',
|
|
102
102
|
enableO11y: true,
|
|
103
103
|
o11yUploadEndpoint: 'https://your-o11y-endpoint.com/upload',
|
|
104
|
-
|
|
105
|
-
extensionName: 'my-extension'
|
|
104
|
+
extensionName: 'my-extension',
|
|
106
105
|
});
|
|
107
106
|
|
|
108
107
|
reporter.start();
|
|
108
|
+
// Default events use the default schema
|
|
109
109
|
reporter.sendTelemetryEvent('event-name', { foo: 'bar' });
|
|
110
|
+
// PFT or other schema-specific events: pass schema per call
|
|
111
|
+
reporter.sendTelemetryEventWithSchema('pftEventName', { userId: 'user-1', action: 'view' }, pdpEventSchema);
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
**Note:**
|
|
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.
|
|
113
115
|
|
|
114
|
-
**Note:** The `o11y_schema` package
|
|
116
|
+
**Note:** The `o11y_schema` package may not provide TypeScript declarations. If your TypeScript configuration doesn't include `skipLibCheck: true`, you may need type declarations or `@ts-expect-error` for schema imports.
|
|
115
117
|
|
|
116
118
|
#### O11y Telemetry Batching
|
|
117
119
|
|
|
118
120
|
O11y telemetry supports automatic batching of events to improve performance and reduce network overhead. By default, batching is enabled with a 30-second flush interval. Events are automatically uploaded when:
|
|
121
|
+
|
|
119
122
|
- The buffer reaches 50KB in size, or
|
|
120
123
|
- The flush interval (default: 30 seconds) elapses, or
|
|
121
124
|
- The process exits (via shutdown hooks)
|
|
@@ -131,8 +134,8 @@ const reporter = await TelemetryReporter.create({
|
|
|
131
134
|
enableAutoBatching: true, // Default: true
|
|
132
135
|
flushInterval: 60_000, // 60 seconds (default: 30_000)
|
|
133
136
|
enableShutdownHook: true, // Default: true
|
|
134
|
-
enableBeforeExitHook: true // Default: true (may not fire for STDIO servers)
|
|
135
|
-
}
|
|
137
|
+
enableBeforeExitHook: true, // Default: true (may not fire for STDIO servers)
|
|
138
|
+
},
|
|
136
139
|
});
|
|
137
140
|
```
|
|
138
141
|
|
|
@@ -144,8 +147,8 @@ const reporter = await TelemetryReporter.create({
|
|
|
144
147
|
enableO11y: true,
|
|
145
148
|
o11yUploadEndpoint: 'https://your-o11y-endpoint.com/upload',
|
|
146
149
|
o11yBatching: {
|
|
147
|
-
enableAutoBatching: false // Events will be uploaded immediately
|
|
148
|
-
}
|
|
150
|
+
enableAutoBatching: false, // Events will be uploaded immediately
|
|
151
|
+
},
|
|
149
152
|
});
|
|
150
153
|
```
|
|
151
154
|
|
package/lib/o11yReporter.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export declare class O11yReporter extends BaseReporter {
|
|
|
6
6
|
private initialized;
|
|
7
7
|
private commonProperties;
|
|
8
8
|
private extensionName;
|
|
9
|
-
private customSchema;
|
|
10
9
|
private _batchingCleanup;
|
|
11
10
|
private _batchingEnabled;
|
|
12
11
|
constructor(options: TelemetryOptions);
|
|
@@ -36,6 +35,17 @@ export declare class O11yReporter extends BaseReporter {
|
|
|
36
35
|
*/
|
|
37
36
|
isBatchingEnabled(): boolean;
|
|
38
37
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Sends a telemetry event with a specific O11y schema.
|
|
40
|
+
* Use this method when you need to send events that conform to a particular schema
|
|
41
|
+
* (e.g. PFT/pdpEventSchema). Only the events you send via this method use the given schema;
|
|
42
|
+
* all other events use the default schema via sendTelemetryEvent.
|
|
43
|
+
*
|
|
44
|
+
* @param eventName - Name of the event
|
|
45
|
+
* @param attributes - Properties and measurements to publish alongside the event
|
|
46
|
+
* @param schema - O11y schema object (e.g. from o11y_schema package)
|
|
47
|
+
*/
|
|
48
|
+
sendTelemetryEventWithSchema(eventName: string, attributes: Attributes, schema: O11ySchema): Promise<void>;
|
|
39
49
|
flush(): Promise<void>;
|
|
40
50
|
/**
|
|
41
51
|
* Publishes exception to O11y service
|
|
@@ -59,13 +69,5 @@ export declare class O11yReporter extends BaseReporter {
|
|
|
59
69
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
60
70
|
*/
|
|
61
71
|
sendTelemetryMetric(metricName: string, value: number, properties?: Properties): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Gets the currently loaded schema object
|
|
64
|
-
*/
|
|
65
|
-
getCurrentSchema(): O11ySchema | null;
|
|
66
|
-
/**
|
|
67
|
-
* Checks if a custom schema is being used
|
|
68
|
-
*/
|
|
69
|
-
hasCustomSchema(): boolean;
|
|
70
72
|
private buildO11yCommonProperties;
|
|
71
73
|
}
|
package/lib/o11yReporter.js
CHANGED
|
@@ -24,15 +24,12 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
24
24
|
initialized;
|
|
25
25
|
commonProperties;
|
|
26
26
|
extensionName = '';
|
|
27
|
-
customSchema = null; // Schema object provided by consumer
|
|
28
27
|
_batchingCleanup = null; // Cleanup function for auto-batching
|
|
29
28
|
_batchingEnabled = false; // Track if batching is enabled
|
|
30
29
|
constructor(options) {
|
|
31
30
|
super(options);
|
|
32
31
|
this.extensionName = options.extensionName ?? options.project;
|
|
33
32
|
this.service = o11y_reporter_1.O11yService.getInstance(this.extensionName);
|
|
34
|
-
// Store the schema object provided by consumer (if any)
|
|
35
|
-
this.customSchema = options.o11ySchema ?? null;
|
|
36
33
|
this.initialized = this.service.initialize(this.extensionName, options.o11yUploadEndpoint);
|
|
37
34
|
this.commonProperties = this.buildO11yCommonProperties(options.commonProperties);
|
|
38
35
|
}
|
|
@@ -78,13 +75,7 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
78
75
|
eventName: `${this.extensionName}/${eventName}`,
|
|
79
76
|
...merged,
|
|
80
77
|
};
|
|
81
|
-
|
|
82
|
-
if (this.customSchema) {
|
|
83
|
-
this.service.logEventWithSchema(eventData, this.customSchema);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.service.logEvent(eventData);
|
|
87
|
-
}
|
|
78
|
+
this.service.logEvent(eventData);
|
|
88
79
|
// If batching is not enabled, upload immediately for backward compatibility
|
|
89
80
|
if (!this._batchingEnabled) {
|
|
90
81
|
await this.service.forceFlush();
|
|
@@ -92,6 +83,28 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
92
83
|
// If batching is enabled, events will be automatically uploaded based on
|
|
93
84
|
// threshold (50KB) or periodic flush interval.
|
|
94
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Sends a telemetry event with a specific O11y schema.
|
|
88
|
+
* Use this method when you need to send events that conform to a particular schema
|
|
89
|
+
* (e.g. PFT/pdpEventSchema). Only the events you send via this method use the given schema;
|
|
90
|
+
* all other events use the default schema via sendTelemetryEvent.
|
|
91
|
+
*
|
|
92
|
+
* @param eventName - Name of the event
|
|
93
|
+
* @param attributes - Properties and measurements to publish alongside the event
|
|
94
|
+
* @param schema - O11y schema object (e.g. from o11y_schema package)
|
|
95
|
+
*/
|
|
96
|
+
async sendTelemetryEventWithSchema(eventName, attributes, schema) {
|
|
97
|
+
await this.initialized;
|
|
98
|
+
const merged = { ...this.commonProperties, ...attributes };
|
|
99
|
+
const eventData = {
|
|
100
|
+
eventName: `${this.extensionName}/${eventName}`,
|
|
101
|
+
...merged,
|
|
102
|
+
};
|
|
103
|
+
this.service.logEventWithSchema(eventData, schema);
|
|
104
|
+
if (!this._batchingEnabled) {
|
|
105
|
+
await this.service.forceFlush();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
95
108
|
async flush() {
|
|
96
109
|
// Wait for initialization to complete before using the service
|
|
97
110
|
await this.initialized;
|
|
@@ -118,13 +131,7 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
118
131
|
...properties,
|
|
119
132
|
...measurements,
|
|
120
133
|
};
|
|
121
|
-
|
|
122
|
-
if (this.customSchema) {
|
|
123
|
-
this.service.logEventWithSchema(exceptionEvent, this.customSchema);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
this.service.logEvent(exceptionEvent);
|
|
127
|
-
}
|
|
134
|
+
this.service.logEvent(exceptionEvent);
|
|
128
135
|
// If batching is not enabled, upload immediately for backward compatibility
|
|
129
136
|
if (!this._batchingEnabled) {
|
|
130
137
|
await this.service.forceFlush();
|
|
@@ -146,12 +153,7 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
146
153
|
message: traceMessage,
|
|
147
154
|
...merged,
|
|
148
155
|
};
|
|
149
|
-
|
|
150
|
-
this.service.logEventWithSchema(traceEvent, this.customSchema);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
this.service.logEvent(traceEvent);
|
|
154
|
-
}
|
|
156
|
+
this.service.logEvent(traceEvent);
|
|
155
157
|
// If batching is not enabled, upload immediately for backward compatibility
|
|
156
158
|
if (!this._batchingEnabled) {
|
|
157
159
|
await this.service.forceFlush();
|
|
@@ -173,29 +175,12 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
173
175
|
value,
|
|
174
176
|
...merged,
|
|
175
177
|
};
|
|
176
|
-
|
|
177
|
-
this.service.logEventWithSchema(metricEvent, this.customSchema);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
this.service.logEvent(metricEvent);
|
|
181
|
-
}
|
|
178
|
+
this.service.logEvent(metricEvent);
|
|
182
179
|
// If batching is not enabled, upload immediately for backward compatibility
|
|
183
180
|
if (!this._batchingEnabled) {
|
|
184
181
|
await this.service.forceFlush();
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets the currently loaded schema object
|
|
189
|
-
*/
|
|
190
|
-
getCurrentSchema() {
|
|
191
|
-
return this.customSchema;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Checks if a custom schema is being used
|
|
195
|
-
*/
|
|
196
|
-
hasCustomSchema() {
|
|
197
|
-
return this.customSchema !== null;
|
|
198
|
-
}
|
|
199
184
|
buildO11yCommonProperties(extra) {
|
|
200
185
|
const baseProperties = this.buildCommonProperties(extra);
|
|
201
186
|
baseProperties['common.extensionName'] = this.extensionName;
|
|
@@ -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, Properties, TelemetryOptions } from './types';
|
|
4
|
+
import { Attributes, O11ySchema, 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.
|
|
@@ -34,6 +34,16 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
|
|
|
34
34
|
stop(): void;
|
|
35
35
|
waitForConnection(): Promise<void>;
|
|
36
36
|
testConnection(): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Sends a telemetry event to O11y only with a specific schema.
|
|
39
|
+
* Use this for events that must conform to a given schema (e.g. PFT/pdpEventSchema).
|
|
40
|
+
* Does not send to AppInsights. Only sends when O11y is enabled and reporter is initialized.
|
|
41
|
+
*
|
|
42
|
+
* @param eventName - Name of the event
|
|
43
|
+
* @param attributes - Properties and measurements to publish alongside the event
|
|
44
|
+
* @param schema - O11y schema object (e.g. from o11y_schema package)
|
|
45
|
+
*/
|
|
46
|
+
sendTelemetryEventWithSchema(eventName: string, attributes: Attributes, schema: O11ySchema): void;
|
|
37
47
|
/**
|
|
38
48
|
* Sends message to both AppInsights and O11y (if enabled).
|
|
39
49
|
*
|
package/lib/telemetryReporter.js
CHANGED
|
@@ -187,6 +187,22 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
|
|
|
187
187
|
return false;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Sends a telemetry event to O11y only with a specific schema.
|
|
192
|
+
* Use this for events that must conform to a given schema (e.g. PFT/pdpEventSchema).
|
|
193
|
+
* Does not send to AppInsights. Only sends when O11y is enabled and reporter is initialized.
|
|
194
|
+
*
|
|
195
|
+
* @param eventName - Name of the event
|
|
196
|
+
* @param attributes - Properties and measurements to publish alongside the event
|
|
197
|
+
* @param schema - O11y schema object (e.g. from o11y_schema package)
|
|
198
|
+
*/
|
|
199
|
+
sendTelemetryEventWithSchema(eventName, attributes, schema) {
|
|
200
|
+
if (this.isSfdxTelemetryEnabled() && this.enableO11y && this.o11yReporter) {
|
|
201
|
+
void this.o11yReporter.sendTelemetryEventWithSchema(eventName, attributes, schema).catch((error) => {
|
|
202
|
+
this.logger.debug('Failed to send event with schema to O11y:', error);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
190
206
|
/**
|
|
191
207
|
* Sends message to both AppInsights and O11y (if enabled).
|
|
192
208
|
*
|
package/lib/types.d.ts
CHANGED
|
@@ -63,7 +63,6 @@ export type TelemetryOptions = {
|
|
|
63
63
|
enableO11y?: boolean;
|
|
64
64
|
enableAppInsights?: boolean;
|
|
65
65
|
extensionName?: string;
|
|
66
|
-
o11ySchema?: O11ySchema;
|
|
67
66
|
/**
|
|
68
67
|
* Batching configuration for O11y telemetry
|
|
69
68
|
* Batching is enabled by default. Set o11yBatching.enableAutoBatching to false to disable batching
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/telemetry",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.1",
|
|
4
4
|
"description": "Library for telemetry reporting to Application Insights and O11y",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"exports": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"!lib/**/*.map"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@salesforce/core": "^8.25.
|
|
44
|
+
"@salesforce/core": "^8.25.1",
|
|
45
45
|
"@salesforce/kit": "^3.2.4",
|
|
46
46
|
"@salesforce/o11y-reporter": "1.7.0",
|
|
47
47
|
"applicationinsights": "^2.9.8",
|