@salesforce/telemetry 6.7.2 → 6.8.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/README.md CHANGED
@@ -44,6 +44,14 @@ reporter.sendTelemetryEvent('event-name', { foo: 'bar', executionTime: 0.5912 })
44
44
  reporter.stop();
45
45
  ```
46
46
 
47
+ To ensure all buffered events are flushed before process exit (e.g. when using O11y batching), use `stopAsync()`:
48
+
49
+ ```javascript
50
+ // Await shutdown so all events are sent before exiting
51
+ await reporter.stopAsync();
52
+ process.exit(0);
53
+ ```
54
+
47
55
  **Note:** For short lived processes, the telemetry can take 0-3 seconds to send all events to the server on stop, and even longer if there is a timeout. It is recommended to send telemetry in a detached spawned process. i.e. `spawn(..., { stdio: 'ignore'}).unref();`
48
56
 
49
57
  ### O11y (Observability) Telemetry
@@ -159,6 +167,14 @@ You can also manually flush buffered events when needed (e.g., before critical o
159
167
  await reporter.flush();
160
168
  ```
161
169
 
170
+ For graceful shutdown that stops the batching interval and flushes all events, use `stopAsync()`:
171
+
172
+ ```javascript
173
+ // Stop batching, flush remaining events, and dispose
174
+ await reporter.stopAsync();
175
+ process.exit(0);
176
+ ```
177
+
162
178
  **Note:** When batching is disabled, events are uploaded immediately after each `sendTelemetryEvent()`, `sendTelemetryException()`, `sendTelemetryTrace()`, or `sendTelemetryMetric()` call for backward compatibility.
163
179
 
164
180
  ## Env Variables
@@ -58,6 +58,17 @@ export declare class O11yReporter extends BaseReporter {
58
58
  */
59
59
  sendPdpEvent(event: PdpEvent): Promise<void>;
60
60
  flush(): Promise<void>;
61
+ /**
62
+ * Stop batching (if enabled), flush any remaining events, and clean up.
63
+ * Call this before process exit to ensure all events are sent and timers are cleared.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * await reporter.stop();
68
+ * process.exit(0);
69
+ * ```
70
+ */
71
+ stop(): Promise<void>;
61
72
  /**
62
73
  * Publishes exception to O11y service
63
74
  *
@@ -138,6 +138,25 @@ class O11yReporter extends baseReporter_1.BaseReporter {
138
138
  // Use forceFlush for explicit manual flush
139
139
  await this.service.forceFlush();
140
140
  }
141
+ /**
142
+ * Stop batching (if enabled), flush any remaining events, and clean up.
143
+ * Call this before process exit to ensure all events are sent and timers are cleared.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * await reporter.stop();
148
+ * process.exit(0);
149
+ * ```
150
+ */
151
+ async stop() {
152
+ await this.initialized;
153
+ if (this._batchingCleanup) {
154
+ this._batchingCleanup();
155
+ this._batchingCleanup = null;
156
+ this._batchingEnabled = false;
157
+ }
158
+ await this.service.forceFlush();
159
+ }
141
160
  /**
142
161
  * Publishes exception to O11y service
143
162
  *
@@ -32,6 +32,17 @@ export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions>
32
32
  * not counting timeouts.
33
33
  */
34
34
  stop(): void;
35
+ /**
36
+ * Async version of stop() that awaits O11y cleanup (batching interval stop + flush).
37
+ * Use this when you need to ensure telemetry is fully shut down before process exit.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * await reporter.stopAsync();
42
+ * process.exit(0);
43
+ * ```
44
+ */
45
+ stopAsync(): Promise<void>;
35
46
  waitForConnection(): Promise<void>;
36
47
  testConnection(): Promise<boolean>;
37
48
  /**
@@ -150,7 +150,21 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
150
150
  */
151
151
  stop() {
152
152
  this.reporter?.stop();
153
- void this.o11yReporter?.flush();
153
+ void this.o11yReporter?.stop();
154
+ }
155
+ /**
156
+ * Async version of stop() that awaits O11y cleanup (batching interval stop + flush).
157
+ * Use this when you need to ensure telemetry is fully shut down before process exit.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * await reporter.stopAsync();
162
+ * process.exit(0);
163
+ * ```
164
+ */
165
+ async stopAsync() {
166
+ this.reporter?.stop();
167
+ await this.o11yReporter?.stop();
154
168
  }
155
169
  async waitForConnection() {
156
170
  const canConnect = await this.testConnection();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/telemetry",
3
- "version": "6.7.2",
3
+ "version": "6.8.0",
4
4
  "description": "Library for telemetry reporting to Application Insights and O11y",
5
5
  "main": "lib/exported",
6
6
  "exports": {
@@ -46,7 +46,7 @@
46
46
  "@salesforce/o11y-reporter": "1.8.1",
47
47
  "applicationinsights": "^2.9.8",
48
48
  "got": "^11",
49
- "o11y_schema": "^260.46.0",
49
+ "o11y_schema": "^260.47.0",
50
50
  "proxy-agent": "^6.5.0"
51
51
  },
52
52
  "devDependencies": {