braintrust 3.2.0 → 3.3.0-rc.45
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/dev/dist/index.d.mts +6 -1
- package/dev/dist/index.d.ts +6 -1
- package/dev/dist/index.js +85 -73
- package/dev/dist/index.mjs +29 -17
- package/dist/browser.d.mts +8 -1
- package/dist/browser.d.ts +8 -1
- package/dist/browser.js +35 -17
- package/dist/browser.mjs +35 -17
- package/dist/cli.js +30 -18
- package/dist/edge-light.js +35 -17
- package/dist/edge-light.mjs +35 -17
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +100 -82
- package/dist/index.mjs +35 -17
- package/dist/instrumentation/index.js +27 -16
- package/dist/instrumentation/index.mjs +27 -16
- package/dist/workerd.js +35 -17
- package/dist/workerd.mjs +35 -17
- package/package.json +1 -1
|
@@ -5460,6 +5460,7 @@ function utf8ByteLength(value) {
|
|
|
5460
5460
|
function now() {
|
|
5461
5461
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
5462
5462
|
}
|
|
5463
|
+
var DEFAULT_FLUSH_BACKPRESSURE_BYTES = 10 * 1024 * 1024;
|
|
5463
5464
|
var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
|
|
5464
5465
|
var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
5465
5466
|
apiConn;
|
|
@@ -5478,7 +5479,8 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5478
5479
|
queueDropLoggingPeriod = 60;
|
|
5479
5480
|
failedPublishPayloadsDir = void 0;
|
|
5480
5481
|
allPublishPayloadsDir = void 0;
|
|
5481
|
-
|
|
5482
|
+
_flushBackpressureBytes = DEFAULT_FLUSH_BACKPRESSURE_BYTES;
|
|
5483
|
+
_pendingBytes = 0;
|
|
5482
5484
|
_disabled = false;
|
|
5483
5485
|
queueDropLoggingState = {
|
|
5484
5486
|
numDropped: 0,
|
|
@@ -5518,11 +5520,16 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5518
5520
|
if (!isNaN(queueDropLoggingPeriodEnv)) {
|
|
5519
5521
|
this.queueDropLoggingPeriod = queueDropLoggingPeriodEnv;
|
|
5520
5522
|
}
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
+
if (isomorph_default.getEnv("BRAINTRUST_LOG_FLUSH_CHUNK_SIZE")) {
|
|
5524
|
+
console.warn(
|
|
5525
|
+
"BRAINTRUST_LOG_FLUSH_CHUNK_SIZE is deprecated and no longer has any effect. Log flushing now sends all items at once and batches them automatically. This environment variable will be removed in a future major release."
|
|
5526
|
+
);
|
|
5527
|
+
}
|
|
5528
|
+
const flushBackpressureBytesEnv = Number(
|
|
5529
|
+
isomorph_default.getEnv("BRAINTRUST_FLUSH_BACKPRESSURE_BYTES")
|
|
5523
5530
|
);
|
|
5524
|
-
if (!isNaN(
|
|
5525
|
-
this.
|
|
5531
|
+
if (!isNaN(flushBackpressureBytesEnv) && flushBackpressureBytesEnv > 0) {
|
|
5532
|
+
this._flushBackpressureBytes = flushBackpressureBytesEnv;
|
|
5526
5533
|
}
|
|
5527
5534
|
const failedPublishPayloadsDirEnv = isomorph_default.getEnv(
|
|
5528
5535
|
"BRAINTRUST_FAILED_PUBLISH_PAYLOADS_DIR"
|
|
@@ -5546,6 +5553,12 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5546
5553
|
setMaskingFunction(maskingFunction) {
|
|
5547
5554
|
this.maskingFunction = maskingFunction;
|
|
5548
5555
|
}
|
|
5556
|
+
pendingFlushBytes() {
|
|
5557
|
+
return this._pendingBytes;
|
|
5558
|
+
}
|
|
5559
|
+
flushBackpressureBytes() {
|
|
5560
|
+
return this._flushBackpressureBytes;
|
|
5561
|
+
}
|
|
5549
5562
|
log(items) {
|
|
5550
5563
|
if (this._disabled) {
|
|
5551
5564
|
return;
|
|
@@ -5608,14 +5621,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5608
5621
|
if (wrappedItems.length === 0) {
|
|
5609
5622
|
return;
|
|
5610
5623
|
}
|
|
5611
|
-
|
|
5612
|
-
let index = 0;
|
|
5613
|
-
while (index < wrappedItems.length) {
|
|
5614
|
-
const chunk = wrappedItems.slice(index, index + chunkSize);
|
|
5615
|
-
await this.flushWrappedItemsChunk(chunk, batchSize);
|
|
5616
|
-
index += chunk.length;
|
|
5617
|
-
}
|
|
5618
|
-
wrappedItems.length = 0;
|
|
5624
|
+
await this.flushWrappedItemsChunk(wrappedItems, batchSize);
|
|
5619
5625
|
if (this.queue.length() > 0) {
|
|
5620
5626
|
await this.flushOnce(args);
|
|
5621
5627
|
}
|
|
@@ -5628,9 +5634,13 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5628
5634
|
if (allItems.length === 0) {
|
|
5629
5635
|
return;
|
|
5630
5636
|
}
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5637
|
+
let chunkBytes = 0;
|
|
5638
|
+
const allItemsWithMeta = allItems.map((item) => {
|
|
5639
|
+
const withMeta = stringifyWithOverflowMeta(item);
|
|
5640
|
+
chunkBytes += withMeta.str.length;
|
|
5641
|
+
return withMeta;
|
|
5642
|
+
});
|
|
5643
|
+
this._pendingBytes += chunkBytes;
|
|
5634
5644
|
const maxRequestSizeResult = await this.getMaxRequestSize();
|
|
5635
5645
|
const batches = batchItems({
|
|
5636
5646
|
items: allItemsWithMeta,
|
|
@@ -5649,6 +5659,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5649
5659
|
})()
|
|
5650
5660
|
);
|
|
5651
5661
|
const results = await Promise.all(postPromises);
|
|
5662
|
+
this._pendingBytes = Math.max(0, this._pendingBytes - chunkBytes);
|
|
5652
5663
|
const failingResultErrors = results.map((r) => r.type === "success" ? void 0 : r.value).filter((r) => r !== void 0);
|
|
5653
5664
|
if (failingResultErrors.length) {
|
|
5654
5665
|
throw new AggregateError(
|
package/dist/workerd.js
CHANGED
|
@@ -5855,6 +5855,7 @@ function utf8ByteLength(value) {
|
|
|
5855
5855
|
function now() {
|
|
5856
5856
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
5857
5857
|
}
|
|
5858
|
+
var DEFAULT_FLUSH_BACKPRESSURE_BYTES = 10 * 1024 * 1024;
|
|
5858
5859
|
var TestBackgroundLogger = class {
|
|
5859
5860
|
items = [];
|
|
5860
5861
|
maskingFunction = null;
|
|
@@ -5867,6 +5868,12 @@ var TestBackgroundLogger = class {
|
|
|
5867
5868
|
async flush() {
|
|
5868
5869
|
return Promise.resolve();
|
|
5869
5870
|
}
|
|
5871
|
+
pendingFlushBytes() {
|
|
5872
|
+
return 0;
|
|
5873
|
+
}
|
|
5874
|
+
flushBackpressureBytes() {
|
|
5875
|
+
return DEFAULT_FLUSH_BACKPRESSURE_BYTES;
|
|
5876
|
+
}
|
|
5870
5877
|
async drain() {
|
|
5871
5878
|
const items = this.items;
|
|
5872
5879
|
this.items = [];
|
|
@@ -5924,7 +5931,8 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5924
5931
|
queueDropLoggingPeriod = 60;
|
|
5925
5932
|
failedPublishPayloadsDir = void 0;
|
|
5926
5933
|
allPublishPayloadsDir = void 0;
|
|
5927
|
-
|
|
5934
|
+
_flushBackpressureBytes = DEFAULT_FLUSH_BACKPRESSURE_BYTES;
|
|
5935
|
+
_pendingBytes = 0;
|
|
5928
5936
|
_disabled = false;
|
|
5929
5937
|
queueDropLoggingState = {
|
|
5930
5938
|
numDropped: 0,
|
|
@@ -5964,11 +5972,16 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5964
5972
|
if (!isNaN(queueDropLoggingPeriodEnv)) {
|
|
5965
5973
|
this.queueDropLoggingPeriod = queueDropLoggingPeriodEnv;
|
|
5966
5974
|
}
|
|
5967
|
-
|
|
5968
|
-
|
|
5975
|
+
if (isomorph_default.getEnv("BRAINTRUST_LOG_FLUSH_CHUNK_SIZE")) {
|
|
5976
|
+
console.warn(
|
|
5977
|
+
"BRAINTRUST_LOG_FLUSH_CHUNK_SIZE is deprecated and no longer has any effect. Log flushing now sends all items at once and batches them automatically. This environment variable will be removed in a future major release."
|
|
5978
|
+
);
|
|
5979
|
+
}
|
|
5980
|
+
const flushBackpressureBytesEnv = Number(
|
|
5981
|
+
isomorph_default.getEnv("BRAINTRUST_FLUSH_BACKPRESSURE_BYTES")
|
|
5969
5982
|
);
|
|
5970
|
-
if (!isNaN(
|
|
5971
|
-
this.
|
|
5983
|
+
if (!isNaN(flushBackpressureBytesEnv) && flushBackpressureBytesEnv > 0) {
|
|
5984
|
+
this._flushBackpressureBytes = flushBackpressureBytesEnv;
|
|
5972
5985
|
}
|
|
5973
5986
|
const failedPublishPayloadsDirEnv = isomorph_default.getEnv(
|
|
5974
5987
|
"BRAINTRUST_FAILED_PUBLISH_PAYLOADS_DIR"
|
|
@@ -5992,6 +6005,12 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5992
6005
|
setMaskingFunction(maskingFunction) {
|
|
5993
6006
|
this.maskingFunction = maskingFunction;
|
|
5994
6007
|
}
|
|
6008
|
+
pendingFlushBytes() {
|
|
6009
|
+
return this._pendingBytes;
|
|
6010
|
+
}
|
|
6011
|
+
flushBackpressureBytes() {
|
|
6012
|
+
return this._flushBackpressureBytes;
|
|
6013
|
+
}
|
|
5995
6014
|
log(items) {
|
|
5996
6015
|
if (this._disabled) {
|
|
5997
6016
|
return;
|
|
@@ -6054,14 +6073,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
6054
6073
|
if (wrappedItems.length === 0) {
|
|
6055
6074
|
return;
|
|
6056
6075
|
}
|
|
6057
|
-
|
|
6058
|
-
let index = 0;
|
|
6059
|
-
while (index < wrappedItems.length) {
|
|
6060
|
-
const chunk = wrappedItems.slice(index, index + chunkSize);
|
|
6061
|
-
await this.flushWrappedItemsChunk(chunk, batchSize);
|
|
6062
|
-
index += chunk.length;
|
|
6063
|
-
}
|
|
6064
|
-
wrappedItems.length = 0;
|
|
6076
|
+
await this.flushWrappedItemsChunk(wrappedItems, batchSize);
|
|
6065
6077
|
if (this.queue.length() > 0) {
|
|
6066
6078
|
await this.flushOnce(args);
|
|
6067
6079
|
}
|
|
@@ -6074,9 +6086,13 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
6074
6086
|
if (allItems.length === 0) {
|
|
6075
6087
|
return;
|
|
6076
6088
|
}
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6089
|
+
let chunkBytes = 0;
|
|
6090
|
+
const allItemsWithMeta = allItems.map((item) => {
|
|
6091
|
+
const withMeta = stringifyWithOverflowMeta(item);
|
|
6092
|
+
chunkBytes += withMeta.str.length;
|
|
6093
|
+
return withMeta;
|
|
6094
|
+
});
|
|
6095
|
+
this._pendingBytes += chunkBytes;
|
|
6080
6096
|
const maxRequestSizeResult = await this.getMaxRequestSize();
|
|
6081
6097
|
const batches = batchItems({
|
|
6082
6098
|
items: allItemsWithMeta,
|
|
@@ -6095,6 +6111,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
6095
6111
|
})()
|
|
6096
6112
|
);
|
|
6097
6113
|
const results = await Promise.all(postPromises);
|
|
6114
|
+
this._pendingBytes = Math.max(0, this._pendingBytes - chunkBytes);
|
|
6098
6115
|
const failingResultErrors = results.map((r) => r.type === "success" ? void 0 : r.value).filter((r) => r !== void 0);
|
|
6099
6116
|
if (failingResultErrors.length) {
|
|
6100
6117
|
throw new AggregateError(
|
|
@@ -16679,7 +16696,8 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
16679
16696
|
});
|
|
16680
16697
|
} else {
|
|
16681
16698
|
const result = await experiment.traced(callback, baseEvent);
|
|
16682
|
-
|
|
16699
|
+
const bgLogger = experiment.loggingState.bgLogger();
|
|
16700
|
+
if (evaluator.maxConcurrency !== void 0 && bgLogger.pendingFlushBytes() >= bgLogger.flushBackpressureBytes()) {
|
|
16683
16701
|
await experiment.flush();
|
|
16684
16702
|
}
|
|
16685
16703
|
return result;
|
package/dist/workerd.mjs
CHANGED
|
@@ -5697,6 +5697,7 @@ function utf8ByteLength(value) {
|
|
|
5697
5697
|
function now() {
|
|
5698
5698
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
5699
5699
|
}
|
|
5700
|
+
var DEFAULT_FLUSH_BACKPRESSURE_BYTES = 10 * 1024 * 1024;
|
|
5700
5701
|
var TestBackgroundLogger = class {
|
|
5701
5702
|
items = [];
|
|
5702
5703
|
maskingFunction = null;
|
|
@@ -5709,6 +5710,12 @@ var TestBackgroundLogger = class {
|
|
|
5709
5710
|
async flush() {
|
|
5710
5711
|
return Promise.resolve();
|
|
5711
5712
|
}
|
|
5713
|
+
pendingFlushBytes() {
|
|
5714
|
+
return 0;
|
|
5715
|
+
}
|
|
5716
|
+
flushBackpressureBytes() {
|
|
5717
|
+
return DEFAULT_FLUSH_BACKPRESSURE_BYTES;
|
|
5718
|
+
}
|
|
5712
5719
|
async drain() {
|
|
5713
5720
|
const items = this.items;
|
|
5714
5721
|
this.items = [];
|
|
@@ -5766,7 +5773,8 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5766
5773
|
queueDropLoggingPeriod = 60;
|
|
5767
5774
|
failedPublishPayloadsDir = void 0;
|
|
5768
5775
|
allPublishPayloadsDir = void 0;
|
|
5769
|
-
|
|
5776
|
+
_flushBackpressureBytes = DEFAULT_FLUSH_BACKPRESSURE_BYTES;
|
|
5777
|
+
_pendingBytes = 0;
|
|
5770
5778
|
_disabled = false;
|
|
5771
5779
|
queueDropLoggingState = {
|
|
5772
5780
|
numDropped: 0,
|
|
@@ -5806,11 +5814,16 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5806
5814
|
if (!isNaN(queueDropLoggingPeriodEnv)) {
|
|
5807
5815
|
this.queueDropLoggingPeriod = queueDropLoggingPeriodEnv;
|
|
5808
5816
|
}
|
|
5809
|
-
|
|
5810
|
-
|
|
5817
|
+
if (isomorph_default.getEnv("BRAINTRUST_LOG_FLUSH_CHUNK_SIZE")) {
|
|
5818
|
+
console.warn(
|
|
5819
|
+
"BRAINTRUST_LOG_FLUSH_CHUNK_SIZE is deprecated and no longer has any effect. Log flushing now sends all items at once and batches them automatically. This environment variable will be removed in a future major release."
|
|
5820
|
+
);
|
|
5821
|
+
}
|
|
5822
|
+
const flushBackpressureBytesEnv = Number(
|
|
5823
|
+
isomorph_default.getEnv("BRAINTRUST_FLUSH_BACKPRESSURE_BYTES")
|
|
5811
5824
|
);
|
|
5812
|
-
if (!isNaN(
|
|
5813
|
-
this.
|
|
5825
|
+
if (!isNaN(flushBackpressureBytesEnv) && flushBackpressureBytesEnv > 0) {
|
|
5826
|
+
this._flushBackpressureBytes = flushBackpressureBytesEnv;
|
|
5814
5827
|
}
|
|
5815
5828
|
const failedPublishPayloadsDirEnv = isomorph_default.getEnv(
|
|
5816
5829
|
"BRAINTRUST_FAILED_PUBLISH_PAYLOADS_DIR"
|
|
@@ -5834,6 +5847,12 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5834
5847
|
setMaskingFunction(maskingFunction) {
|
|
5835
5848
|
this.maskingFunction = maskingFunction;
|
|
5836
5849
|
}
|
|
5850
|
+
pendingFlushBytes() {
|
|
5851
|
+
return this._pendingBytes;
|
|
5852
|
+
}
|
|
5853
|
+
flushBackpressureBytes() {
|
|
5854
|
+
return this._flushBackpressureBytes;
|
|
5855
|
+
}
|
|
5837
5856
|
log(items) {
|
|
5838
5857
|
if (this._disabled) {
|
|
5839
5858
|
return;
|
|
@@ -5896,14 +5915,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5896
5915
|
if (wrappedItems.length === 0) {
|
|
5897
5916
|
return;
|
|
5898
5917
|
}
|
|
5899
|
-
|
|
5900
|
-
let index = 0;
|
|
5901
|
-
while (index < wrappedItems.length) {
|
|
5902
|
-
const chunk = wrappedItems.slice(index, index + chunkSize);
|
|
5903
|
-
await this.flushWrappedItemsChunk(chunk, batchSize);
|
|
5904
|
-
index += chunk.length;
|
|
5905
|
-
}
|
|
5906
|
-
wrappedItems.length = 0;
|
|
5918
|
+
await this.flushWrappedItemsChunk(wrappedItems, batchSize);
|
|
5907
5919
|
if (this.queue.length() > 0) {
|
|
5908
5920
|
await this.flushOnce(args);
|
|
5909
5921
|
}
|
|
@@ -5916,9 +5928,13 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5916
5928
|
if (allItems.length === 0) {
|
|
5917
5929
|
return;
|
|
5918
5930
|
}
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5931
|
+
let chunkBytes = 0;
|
|
5932
|
+
const allItemsWithMeta = allItems.map((item) => {
|
|
5933
|
+
const withMeta = stringifyWithOverflowMeta(item);
|
|
5934
|
+
chunkBytes += withMeta.str.length;
|
|
5935
|
+
return withMeta;
|
|
5936
|
+
});
|
|
5937
|
+
this._pendingBytes += chunkBytes;
|
|
5922
5938
|
const maxRequestSizeResult = await this.getMaxRequestSize();
|
|
5923
5939
|
const batches = batchItems({
|
|
5924
5940
|
items: allItemsWithMeta,
|
|
@@ -5937,6 +5953,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5937
5953
|
})()
|
|
5938
5954
|
);
|
|
5939
5955
|
const results = await Promise.all(postPromises);
|
|
5956
|
+
this._pendingBytes = Math.max(0, this._pendingBytes - chunkBytes);
|
|
5940
5957
|
const failingResultErrors = results.map((r) => r.type === "success" ? void 0 : r.value).filter((r) => r !== void 0);
|
|
5941
5958
|
if (failingResultErrors.length) {
|
|
5942
5959
|
throw new AggregateError(
|
|
@@ -16521,7 +16538,8 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
16521
16538
|
});
|
|
16522
16539
|
} else {
|
|
16523
16540
|
const result = await experiment.traced(callback, baseEvent);
|
|
16524
|
-
|
|
16541
|
+
const bgLogger = experiment.loggingState.bgLogger();
|
|
16542
|
+
if (evaluator.maxConcurrency !== void 0 && bgLogger.pendingFlushBytes() >= bgLogger.flushBackpressureBytes()) {
|
|
16525
16543
|
await experiment.flush();
|
|
16526
16544
|
}
|
|
16527
16545
|
return result;
|