@inference-net/otel-cf-workers 2.5.0 → 2.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/dist/index.d.ts CHANGED
@@ -549,7 +549,7 @@ declare class TraceState {
549
549
  addSpan(span: Span_2): void;
550
550
  endSpan(span: ReadableSpan): void;
551
551
  sample(): void;
552
- flush(): Promise<void>;
552
+ flush(): Promise<boolean>;
553
553
  private isSpanInProgress;
554
554
  private exportSpans;
555
555
  }
package/dist/index.js CHANGED
@@ -96,7 +96,7 @@ function passthroughGet(target, prop, thisArg) {
96
96
  }
97
97
  }
98
98
 
99
- const PACKAGE_VERSION = "2.5.0";
99
+ const PACKAGE_VERSION = "2.5.1";
100
100
  const PACKAGE_NAME = "@inference-net/otel-cf-workers";
101
101
  const ATTR_CLOUDFLARE_COLO = "cloudflare.colo";
102
102
  const ATTR_CLOUDFLARE_RAY_ID = "cloudflare.ray_id";
@@ -358,9 +358,11 @@ class TraceState {
358
358
  this.exportPromises.push(this.exportSpans(this.unexportedSpans));
359
359
  this.unexportedSpans = [];
360
360
  }
361
- if (this.exportPromises.length > 0) {
361
+ const exportCount = this.exportPromises.length;
362
+ if (exportCount > 0) {
362
363
  await Promise.allSettled(this.exportPromises);
363
364
  }
365
+ return this.inprogressSpans.size === 0 && this.unexportedSpans.length === 0 && this.exportPromises.length === exportCount;
364
366
  }
365
367
  isSpanInProgress(span) {
366
368
  return this.inprogressSpans.has(span.spanContext().spanId);
@@ -399,11 +401,13 @@ class BatchTraceSpanProcessor {
399
401
  this.getTraceState(traceId).endSpan(span);
400
402
  }
401
403
  async forceFlush(traceId) {
402
- if (traceId) {
403
- await this.getTraceState(traceId).flush();
404
- } else {
405
- const promises = Object.values(this.traces).map((traceState) => traceState.flush);
406
- await Promise.allSettled(promises);
404
+ if (!traceId) {
405
+ await Promise.allSettled(Object.keys(this.traces).map((id) => this.forceFlush(id)));
406
+ return;
407
+ }
408
+ const state = this.traces[traceId];
409
+ if (state && await state.flush() && this.traces[traceId] === state) {
410
+ delete this.traces[traceId];
407
411
  }
408
412
  }
409
413
  async shutdown() {