@oxygen-agent/cli 1.1014.777 → 1.1014.779

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
@@ -34,4 +34,4 @@ oxygen update
34
34
 
35
35
  For product documentation, visit https://oxygen-agent.com/docs. For support, visit https://oxygen-agent.com.
36
36
 
37
- Version: 1.1014.777
37
+ Version: 1.1014.779
@@ -39,6 +39,7 @@ export type OtlpLogSinkOptions = {
39
39
  serviceName: string;
40
40
  /** Resource attributes merged after the defaults, so a caller can override them. */
41
41
  resource?: Record<string, string | null | undefined> | undefined;
42
+ /** Positive safe integer; invalid values use the default batch size. */
42
43
  batchSize?: number | undefined;
43
44
  /** `0` disables the interval timer, for runtimes that flush off a request lifecycle. */
44
45
  flushIntervalMs?: number | undefined;
@@ -210,7 +210,9 @@ function toLogRecord(record) {
210
210
  };
211
211
  }
212
212
  export function createOtlpLogSink(options) {
213
- const batchSize = options.batchSize && options.batchSize > 0 ? options.batchSize : DEFAULT_BATCH_SIZE;
213
+ const requestedBatchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
214
+ const batchSize = Number.isSafeInteger(requestedBatchSize) && requestedBatchSize > 0
215
+ ? requestedBatchSize : DEFAULT_BATCH_SIZE;
214
216
  const maxQueue = options.maxQueue && options.maxQueue > 0 ? options.maxQueue : DEFAULT_MAX_QUEUE;
215
217
  const flushIntervalMs = options.flushIntervalMs === undefined
216
218
  ? DEFAULT_FLUSH_INTERVAL_MS
@@ -332,64 +334,66 @@ export function createOtlpLogSink(options) {
332
334
  : {}),
333
335
  })));
334
336
  };
335
- const flush = async () => {
336
- if (inFlight)
337
- return inFlight;
338
- if (queue.length === 0)
339
- return undefined;
340
- const batch = queue.splice(0, batchSize);
337
+ const postBatch = async (batch) => {
341
338
  const payload = JSON.stringify({
342
- resourceLogs: [
343
- {
339
+ resourceLogs: [{
344
340
  resource: { attributes: resourceAttributes },
345
- scopeLogs: [
346
- {
347
- scope: { name: "oxygen" },
348
- logRecords: batch.map(toLogRecord),
349
- },
350
- ],
351
- },
352
- ],
341
+ scopeLogs: [{ scope: { name: "oxygen" }, logRecords: batch.map(toLogRecord) }],
342
+ }],
353
343
  });
354
- const run = (async () => {
355
- try {
356
- const response = await doFetch(options.endpoint, {
357
- method: "POST",
358
- headers: { "Content-Type": "application/json", ...options.headers },
359
- body: payload,
360
- signal: AbortSignal.timeout(EXPORT_TIMEOUT_MS),
361
- });
362
- if (response.ok) {
363
- try {
364
- const rejected = await rejectedRecords(response, batch.length);
365
- if (rejected)
366
- report(rejected, { status: response.status, error_code: "partial_rejection" });
367
- }
368
- catch {
369
- report(batch.length, { status: response.status, error_code: "invalid_response" });
344
+ try {
345
+ const response = await doFetch(options.endpoint, {
346
+ method: "POST",
347
+ headers: { "Content-Type": "application/json", ...options.headers },
348
+ body: payload,
349
+ signal: AbortSignal.timeout(EXPORT_TIMEOUT_MS),
350
+ });
351
+ if (response.ok) {
352
+ try {
353
+ const rejected = await rejectedRecords(response, batch.length);
354
+ if (rejected) {
355
+ report(rejected, { status: response.status, error_code: "partial_rejection" });
356
+ return false;
370
357
  }
371
- return;
358
+ return true;
359
+ }
360
+ catch {
361
+ report(batch.length, { status: response.status, error_code: "invalid_response" });
362
+ return false;
372
363
  }
373
- // Receivers/proxies can echo rejected payloads or credentials. Never
374
- // read arbitrary response text into operational diagnostics.
375
- await response.body?.cancel().catch(() => undefined);
376
- // The batch is gone deliberately: retrying into an unhealthy collector
377
- // is how a telemetry path turns an ingest blip into memory pressure.
378
- report(batch.length, { status: response.status, error_code: "receiver_rejected" });
379
- }
380
- catch (error) {
381
- report(batch.length, {
382
- error_code: "transport_failed",
383
- error_cause: sanitizedErrorCause(error),
384
- });
385
- }
386
- finally {
387
- reportOverflow();
388
364
  }
389
- })();
390
- inFlight = run.finally(() => {
391
- inFlight = null;
392
- });
365
+ // Receivers/proxies can echo payloads or credentials. Keep diagnostics fixed.
366
+ await response.body?.cancel().catch(() => undefined);
367
+ report(batch.length, { status: response.status, error_code: "receiver_rejected" });
368
+ return false;
369
+ }
370
+ catch (error) {
371
+ report(batch.length, {
372
+ error_code: "transport_failed",
373
+ error_cause: sanitizedErrorCause(error),
374
+ });
375
+ return false;
376
+ }
377
+ finally {
378
+ reportOverflow();
379
+ }
380
+ };
381
+ const flush = async () => {
382
+ if (inFlight)
383
+ return inFlight;
384
+ if (queue.length === 0)
385
+ return undefined;
386
+ // Keep one POST in flight. Healthy full batches continue immediately so the
387
+ // timer does not cap production at 500/2s. Failure keeps the existing loss
388
+ // accounting/backoff; neither a rejected batch nor a partial reply is retried.
389
+ const drain = async () => {
390
+ do {
391
+ const accepted = await postBatch(queue.splice(0, batchSize));
392
+ if (!accepted || queue.length < batchSize)
393
+ return;
394
+ } while (queue.length > 0);
395
+ };
396
+ inFlight = Promise.resolve().then(drain).finally(() => { inFlight = null; });
393
397
  return inFlight;
394
398
  };
395
399
  const timer = flushIntervalMs > 0
@@ -404,7 +408,7 @@ export function createOtlpLogSink(options) {
404
408
  if (timer)
405
409
  clearInterval(timer);
406
410
  // Drain rather than flush once: a shutdown's final lines are usually the
407
- // interesting ones, and one flush ships only the oldest `batchSize`.
411
+ // interesting ones. Flush the final partial batch as well as healthy full batches.
408
412
  while (queue.length > 0) {
409
413
  await flush();
410
414
  }
@@ -1 +1 @@
1
- export declare const OXYGEN_BUILD_VERSION = "1.1014.777";
1
+ export declare const OXYGEN_BUILD_VERSION = "1.1014.779";
@@ -1,2 +1,2 @@
1
1
  // GENERATED by scripts/ci/version-stamp.mjs from VERSION + git history. Do not edit; do not commit.
2
- export const OXYGEN_BUILD_VERSION = "1.1014.777";
2
+ export const OXYGEN_BUILD_VERSION = "1.1014.779";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxygen-agent/cli",
3
- "version": "1.1014.777",
3
+ "version": "1.1014.779",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",