@salesforce/telemetry 6.6.7 → 6.7.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/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, PdpEvent } from './types';
5
+ export type { Attributes, O11ySchema, O11yBatchingConfig, PdpEvent, TelemetryOptions } from './types';
@@ -16,10 +16,17 @@ exports.O11yReporter = void 0;
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
+ /* eslint-disable-next-line @typescript-eslint/triple-slash-reference -- needed so dynamic import('o11y_schema/sf_pdp') is typed when test tsconfig compiles */
20
+ /// <reference path="../types/o11y_schema_sf_pdp.d.ts" />
19
21
  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");
22
+ // o11y_schema is ESM-only; load via dynamic import() so it works when telemetry is required as CJS
23
+ let pdpEventSchemaPromise = null;
24
+ async function getPdpEventSchema() {
25
+ if (!pdpEventSchemaPromise) {
26
+ pdpEventSchemaPromise = import('o11y_schema/sf_pdp').then((m) => m.pdpEventSchema);
27
+ }
28
+ return pdpEventSchemaPromise;
29
+ }
23
30
  const baseReporter_1 = require("./baseReporter");
24
31
  const utils_1 = require("./utils");
25
32
  class O11yReporter extends baseReporter_1.BaseReporter {
@@ -33,7 +40,10 @@ class O11yReporter extends baseReporter_1.BaseReporter {
33
40
  super(options);
34
41
  this.extensionName = options.extensionName ?? options.project;
35
42
  this.service = o11y_reporter_1.O11yService.getInstance(this.extensionName);
36
- this.initialized = this.service.initialize(this.extensionName, options.o11yUploadEndpoint);
43
+ const dynamicO11yUploadEndpointPath = options.dynamicO11yUploadEndpoint
44
+ ? options.dynamicO11yUploadEndpoint
45
+ : undefined;
46
+ this.initialized = this.service.initialize(this.extensionName, options.o11yUploadEndpoint, options.getConnectionFn, dynamicO11yUploadEndpointPath ? { dynamicO11yUploadEndpointPath } : undefined);
37
47
  this.commonProperties = this.buildO11yCommonProperties(options.commonProperties);
38
48
  }
39
49
  async init() {
@@ -116,7 +126,8 @@ class O11yReporter extends baseReporter_1.BaseReporter {
116
126
  */
117
127
  async sendPdpEvent(event) {
118
128
  await this.initialized;
119
- this.service.logEventWithSchema(event, sf_pdp_1.pdpEventSchema);
129
+ const schema = await getPdpEventSchema();
130
+ this.service.logEventWithSchema(event, schema);
120
131
  if (!this._batchingEnabled) {
121
132
  await this.service.forceFlush();
122
133
  }
package/lib/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Env } from '@salesforce/kit';
2
+ import { Connection as O11yConnection } from '@salesforce/o11y-reporter';
2
3
  export type Properties = {
3
4
  [key: string]: string;
4
5
  };
@@ -96,6 +97,21 @@ export type TelemetryOptions = {
96
97
  project: string;
97
98
  key: string;
98
99
  commonProperties?: Properties;
100
+ /**
101
+ * Optional getConnection function used at upload time to resolve endpoint and token from the current org.
102
+ * If getConnection is missing or fails, uploads use the static o11yUploadEndpoint (no auth).
103
+ * E.g.,
104
+ * ```
105
+ * Connection.create({
106
+ * authInfo: await AuthInfo.create({ username: 'myAdminUsername' })
107
+ * })
108
+ * ```
109
+ * or
110
+ * ```
111
+ * WorkspaceContextUtil.getInstance().getConnection()
112
+ * ```
113
+ */
114
+ getConnectionFn?: () => Promise<O11yConnection>;
99
115
  contextTags?: Properties;
100
116
  env?: Env;
101
117
  gdprSensitiveKeys?: string[];
@@ -103,6 +119,11 @@ export type TelemetryOptions = {
103
119
  sessionId?: string;
104
120
  waitForConnection?: boolean;
105
121
  o11yUploadEndpoint?: string;
122
+ /**
123
+ * Optional path appended to the org instance URL for the dynamic endpoint.
124
+ * Default: /services/data/v65.0/connect/proxy/ui-telemetry.
125
+ */
126
+ dynamicO11yUploadEndpoint?: string;
106
127
  enableO11y?: boolean;
107
128
  enableAppInsights?: boolean;
108
129
  extensionName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/telemetry",
3
- "version": "6.6.7",
3
+ "version": "6.7.1",
4
4
  "description": "Library for telemetry reporting to Application Insights and O11y",
5
5
  "main": "lib/exported",
6
6
  "exports": {