@salesforce/telemetry 6.2.13 → 6.3.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 +37 -0
- package/lib/exported.d.ts +1 -1
- package/lib/o11yReporter.d.ts +10 -1
- package/lib/o11yReporter.js +58 -16
- package/lib/types.d.ts +8 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,6 +76,43 @@ const reporter = await TelemetryReporter.create({
|
|
|
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
|
|
80
|
+
|
|
81
|
+
The telemetry reporter supports consumer-provided O11y schemas. This allows consumers to use custom schemas from the `o11y_schema` package instead of the default `sf_a4dInstrumentation` schema.
|
|
82
|
+
|
|
83
|
+
**Step 1: Add `o11y_schema` to your `package.json`:**
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"o11y_schema": "^256.154.0"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Step 2: Import and pass the schema to the telemetry reporter:**
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
import TelemetryReporter from '@salesforce/telemetry';
|
|
97
|
+
// Import the schema object from o11y_schema
|
|
98
|
+
import { a4dInstrumentationSchema } from 'o11y_schema/sf_a4dInstrumentation';
|
|
99
|
+
|
|
100
|
+
const reporter = await TelemetryReporter.create({
|
|
101
|
+
project: 'my-project-name',
|
|
102
|
+
enableO11y: true,
|
|
103
|
+
o11yUploadEndpoint: 'https://your-o11y-endpoint.com/upload',
|
|
104
|
+
o11ySchema: a4dInstrumentationSchema, // Pass the schema object
|
|
105
|
+
extensionName: 'my-extension'
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
reporter.start();
|
|
109
|
+
reporter.sendTelemetryEvent('event-name', { foo: 'bar' });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Note:** When `o11ySchema` is provided, the reporter will use `logEventWithSchema()` to log events with your custom schema. If `o11ySchema` is not provided, it falls back to the default `sf_a4dInstrumentation` schema.
|
|
113
|
+
|
|
114
|
+
**Note:** The `o11y_schema` package doesn't provide TypeScript declarations. If your TypeScript configuration doesn't include `skipLibCheck: true`, you may need to add type declarations or use `@ts-expect-error` comments. However, with proper TypeScript configuration, the import should work without additional annotations.
|
|
115
|
+
|
|
79
116
|
## Env Variables
|
|
80
117
|
|
|
81
118
|
`SF_DISABLE_TELEMETRY`: Set to `true` if you want to disable telemetry.
|
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 } from './types';
|
|
5
|
+
export type { Attributes, O11ySchema } from './types';
|
package/lib/o11yReporter.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Attributes, Properties, TelemetryOptions } from './types';
|
|
1
|
+
import { Attributes, O11ySchema, Properties, TelemetryOptions } from './types';
|
|
2
2
|
import { BaseReporter } from './baseReporter';
|
|
3
3
|
export declare class O11yReporter extends BaseReporter {
|
|
4
4
|
private service;
|
|
5
5
|
private initialized;
|
|
6
6
|
private commonProperties;
|
|
7
7
|
private extensionName;
|
|
8
|
+
private customSchema;
|
|
8
9
|
constructor(options: TelemetryOptions);
|
|
9
10
|
init(): Promise<void>;
|
|
10
11
|
sendTelemetryEvent(eventName: string, attributes?: Attributes): Promise<void>;
|
|
@@ -31,5 +32,13 @@ export declare class O11yReporter extends BaseReporter {
|
|
|
31
32
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
32
33
|
*/
|
|
33
34
|
sendTelemetryMetric(metricName: string, value: number, properties?: Properties): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the currently loaded schema object
|
|
37
|
+
*/
|
|
38
|
+
getCurrentSchema(): O11ySchema | null;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a custom schema is being used
|
|
41
|
+
*/
|
|
42
|
+
hasCustomSchema(): boolean;
|
|
34
43
|
private buildO11yCommonProperties;
|
|
35
44
|
}
|
package/lib/o11yReporter.js
CHANGED
|
@@ -17,17 +17,20 @@ exports.O11yReporter = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const o11y_reporter_1 = require("@salesforce/o11y-reporter");
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
20
|
const baseReporter_1 = require("./baseReporter");
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
22
|
class O11yReporter extends baseReporter_1.BaseReporter {
|
|
23
23
|
service;
|
|
24
24
|
initialized;
|
|
25
25
|
commonProperties;
|
|
26
26
|
extensionName = '';
|
|
27
|
+
customSchema = null; // Schema object provided by consumer
|
|
27
28
|
constructor(options) {
|
|
28
29
|
super(options);
|
|
29
30
|
this.extensionName = options.extensionName ?? options.project;
|
|
30
31
|
this.service = o11y_reporter_1.O11yService.getInstance(this.extensionName);
|
|
32
|
+
// Store the schema object provided by consumer (if any)
|
|
33
|
+
this.customSchema = options.o11ySchema ?? null;
|
|
31
34
|
this.initialized = this.service.initialize(this.extensionName, options.o11yUploadEndpoint);
|
|
32
35
|
this.commonProperties = this.buildO11yCommonProperties(options.commonProperties);
|
|
33
36
|
}
|
|
@@ -38,7 +41,18 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
38
41
|
// Wait for initialization to complete before using the service
|
|
39
42
|
await this.initialized;
|
|
40
43
|
const merged = { ...this.commonProperties, ...attributes };
|
|
41
|
-
|
|
44
|
+
// Create event data
|
|
45
|
+
const eventData = {
|
|
46
|
+
eventName: `${this.extensionName}/${eventName}`,
|
|
47
|
+
...merged,
|
|
48
|
+
};
|
|
49
|
+
// Use logEventWithSchema if custom schema is loaded, otherwise use default logEvent
|
|
50
|
+
if (this.customSchema) {
|
|
51
|
+
this.service.logEventWithSchema(eventData, this.customSchema);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.service.logEvent(eventData);
|
|
55
|
+
}
|
|
42
56
|
await this.service.upload();
|
|
43
57
|
}
|
|
44
58
|
async flush() {
|
|
@@ -59,14 +73,20 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
59
73
|
const { properties, measurements } = (0, utils_1.buildPropertiesAndMeasurements)(attributes);
|
|
60
74
|
// Create exception event with sanitized error information
|
|
61
75
|
const exceptionEvent = {
|
|
62
|
-
eventName:
|
|
76
|
+
eventName: `${this.extensionName}/exception`,
|
|
63
77
|
exceptionName: cleanException.name,
|
|
64
78
|
exceptionMessage: cleanException.message,
|
|
65
79
|
exceptionStack: cleanException.stack,
|
|
66
80
|
...properties,
|
|
67
81
|
...measurements,
|
|
68
82
|
};
|
|
69
|
-
|
|
83
|
+
// Use custom schema if available
|
|
84
|
+
if (this.customSchema) {
|
|
85
|
+
this.service.logEventWithSchema(exceptionEvent, this.customSchema);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.service.logEvent(exceptionEvent);
|
|
89
|
+
}
|
|
70
90
|
await this.service.upload();
|
|
71
91
|
}
|
|
72
92
|
/**
|
|
@@ -75,15 +95,20 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
75
95
|
* @param traceMessage {string} - trace message to send to O11y.
|
|
76
96
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
77
97
|
*/
|
|
78
|
-
async sendTelemetryTrace(traceMessage, properties) {
|
|
79
|
-
// Wait for initialization to complete before using the service
|
|
98
|
+
async sendTelemetryTrace(traceMessage, properties = {}) {
|
|
80
99
|
await this.initialized;
|
|
81
|
-
const
|
|
82
|
-
|
|
100
|
+
const merged = { ...this.commonProperties, ...properties };
|
|
101
|
+
const eventData = {
|
|
102
|
+
eventName: `${this.extensionName}/trace`,
|
|
83
103
|
message: traceMessage,
|
|
84
|
-
...
|
|
104
|
+
...merged,
|
|
85
105
|
};
|
|
86
|
-
this.
|
|
106
|
+
if (this.customSchema) {
|
|
107
|
+
this.service.logEventWithSchema(eventData, this.customSchema);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.service.logEvent(eventData);
|
|
111
|
+
}
|
|
87
112
|
await this.service.upload();
|
|
88
113
|
}
|
|
89
114
|
/**
|
|
@@ -93,18 +118,35 @@ class O11yReporter extends baseReporter_1.BaseReporter {
|
|
|
93
118
|
* @param value {number} - value of the metric
|
|
94
119
|
* @param properties {Properties} - map of properties to publish alongside the event.
|
|
95
120
|
*/
|
|
96
|
-
async sendTelemetryMetric(metricName, value, properties) {
|
|
97
|
-
// Wait for initialization to complete before using the service
|
|
121
|
+
async sendTelemetryMetric(metricName, value, properties = {}) {
|
|
98
122
|
await this.initialized;
|
|
99
|
-
const
|
|
100
|
-
|
|
123
|
+
const merged = { ...this.commonProperties, ...properties };
|
|
124
|
+
const eventData = {
|
|
125
|
+
eventName: `${this.extensionName}/metric`,
|
|
101
126
|
metricName,
|
|
102
127
|
value,
|
|
103
|
-
...
|
|
128
|
+
...merged,
|
|
104
129
|
};
|
|
105
|
-
this.
|
|
130
|
+
if (this.customSchema) {
|
|
131
|
+
this.service.logEventWithSchema(eventData, this.customSchema);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.service.logEvent(eventData);
|
|
135
|
+
}
|
|
106
136
|
await this.service.upload();
|
|
107
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets the currently loaded schema object
|
|
140
|
+
*/
|
|
141
|
+
getCurrentSchema() {
|
|
142
|
+
return this.customSchema;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a custom schema is being used
|
|
146
|
+
*/
|
|
147
|
+
hasCustomSchema() {
|
|
148
|
+
return this.customSchema !== null;
|
|
149
|
+
}
|
|
108
150
|
buildO11yCommonProperties(extra) {
|
|
109
151
|
const baseProperties = this.buildCommonProperties(extra);
|
|
110
152
|
baseProperties['common.extensionName'] = this.extensionName;
|
package/lib/types.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export type Measurements = {
|
|
|
8
8
|
export type Attributes = {
|
|
9
9
|
[key: string]: string | number | boolean | null | undefined;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Basic type for O11y schema objects.
|
|
13
|
+
* Schemas from o11y_schema package are objects that define the structure
|
|
14
|
+
* for telemetry events. This type enforces that a schema must be an object
|
|
15
|
+
* (not a primitive, null, or undefined).
|
|
16
|
+
*/
|
|
17
|
+
export type O11ySchema = Record<string, unknown>;
|
|
11
18
|
export type TelemetryOptions = {
|
|
12
19
|
project: string;
|
|
13
20
|
key: string;
|
|
@@ -22,4 +29,5 @@ export type TelemetryOptions = {
|
|
|
22
29
|
enableO11y?: boolean;
|
|
23
30
|
enableAppInsights?: boolean;
|
|
24
31
|
extensionName?: string;
|
|
32
|
+
o11ySchema?: O11ySchema;
|
|
25
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/telemetry",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.1",
|
|
4
4
|
"description": "Library for telemetry reporting to Application Insights and O11y",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"exports": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@salesforce/core": "^8.23.4",
|
|
45
45
|
"@salesforce/kit": "^3.2.4",
|
|
46
|
-
"@salesforce/o11y-reporter": "1.
|
|
46
|
+
"@salesforce/o11y-reporter": "1.6.0",
|
|
47
47
|
"applicationinsights": "^2.9.8",
|
|
48
48
|
"got": "^11",
|
|
49
49
|
"proxy-agent": "^6.5.0"
|