braintrust 3.20.0 → 3.22.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/NOTICE +20 -0
- package/README.md +6 -0
- package/dev/dist/index.d.mts +1338 -199
- package/dev/dist/index.d.ts +1338 -199
- package/dev/dist/index.js +2904 -997
- package/dev/dist/index.mjs +2418 -511
- package/dist/apply-auto-instrumentation.js +781 -199
- package/dist/apply-auto-instrumentation.mjs +588 -6
- package/dist/auto-instrumentations/bundler/esbuild.cjs +594 -2
- package/dist/auto-instrumentations/bundler/esbuild.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/esbuild.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/esbuild.mjs +3 -3
- package/dist/auto-instrumentations/bundler/next.cjs +594 -2
- package/dist/auto-instrumentations/bundler/next.mjs +4 -4
- package/dist/auto-instrumentations/bundler/rollup.cjs +594 -2
- package/dist/auto-instrumentations/bundler/rollup.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/rollup.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/rollup.mjs +3 -3
- package/dist/auto-instrumentations/bundler/vite.cjs +594 -2
- package/dist/auto-instrumentations/bundler/vite.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/vite.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/vite.mjs +3 -3
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +593 -9
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +68 -1
- package/dist/auto-instrumentations/bundler/webpack.cjs +594 -2
- package/dist/auto-instrumentations/bundler/webpack.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/webpack.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/webpack.mjs +4 -4
- package/dist/auto-instrumentations/{chunk-W4E36GIW.mjs → chunk-BRQX23KL.mjs} +16 -0
- package/dist/auto-instrumentations/chunk-M6DLIJ2Z.mjs +784 -0
- package/dist/auto-instrumentations/{chunk-K74TZGGM.mjs → chunk-T6J4C7LX.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-S4374IP6.mjs → chunk-TKRPRPGD.mjs} +4 -6
- package/dist/auto-instrumentations/chunk-VT6DDNKM.mjs +856 -0
- package/dist/auto-instrumentations/hook.mjs +824 -56
- package/dist/auto-instrumentations/index.cjs +16 -0
- package/dist/auto-instrumentations/index.d.mts +2 -3
- package/dist/auto-instrumentations/index.d.ts +2 -3
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +578 -4
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -7
- package/dist/auto-instrumentations/loader/esm-hook.mjs +2 -6
- package/dist/auto-instrumentations/{plugin-D7nDswtC.d.mts → plugin-D0KHwSJv.d.mts} +1 -1
- package/dist/auto-instrumentations/{plugin-D7nDswtC.d.ts → plugin-G6fgxk1b.d.ts} +1 -1
- package/dist/auto-instrumentations/types-RNPaKi9o.d.mts +70 -0
- package/dist/auto-instrumentations/types-RNPaKi9o.d.ts +70 -0
- package/dist/browser.d.mts +4411 -719
- package/dist/browser.d.ts +4411 -719
- package/dist/browser.js +4274 -480
- package/dist/browser.mjs +4274 -480
- package/dist/{chunk-LPC4W2WX.js → chunk-BFGIH2ZJ.js} +4 -0
- package/dist/{chunk-Y7W7WP6H.mjs → chunk-KMGUTPB7.mjs} +4 -0
- package/dist/{chunk-POCCIJAL.js → chunk-MWVVR5LR.js} +3278 -1334
- package/dist/{chunk-F73OMF66.mjs → chunk-ZG2O3XVF.mjs} +2542 -598
- package/dist/cli.js +2338 -419
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +4274 -480
- package/dist/edge-light.mjs +4274 -480
- package/dist/index.d.mts +4926 -1234
- package/dist/index.d.ts +4926 -1234
- package/dist/index.js +2303 -435
- package/dist/index.mjs +1914 -46
- package/dist/instrumentation/index.d.mts +1026 -20
- package/dist/instrumentation/index.d.ts +1026 -20
- package/dist/instrumentation/index.js +3864 -483
- package/dist/instrumentation/index.mjs +3862 -483
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +4274 -480
- package/dist/workerd.mjs +4274 -480
- package/licenses/import-in-the-middle/LICENSE +201 -0
- package/licenses/import-in-the-middle/LICENSE-3rdparty.csv +4 -0
- package/licenses/import-in-the-middle/NOTICE +34 -0
- package/licenses/orchestrion-js/LICENSE +202 -0
- package/licenses/orchestrion-js/LICENSE-3rdparty.csv +8 -0
- package/licenses/orchestrion-js/NOTICE +3 -0
- package/licenses/require-in-the-middle/LICENSE +23 -0
- package/package.json +16 -4
- package/util/dist/index.d.mts +1 -0
- package/util/dist/index.d.ts +1 -0
- package/util/dist/index.js +4 -4
- package/util/dist/index.mjs +2 -2
- package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +0 -208
- package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +0 -280
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applySpecialCasePatch,
|
|
3
|
+
create,
|
|
3
4
|
getPackageName,
|
|
4
5
|
getPackageVersion,
|
|
5
6
|
installMastraExporterFactory
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VT6DDNKM.mjs";
|
|
7
8
|
|
|
8
9
|
// src/auto-instrumentations/hook.mts
|
|
9
10
|
import { register } from "module";
|
|
@@ -365,8 +366,291 @@ var UUIDGenerator = class extends IDGenerator {
|
|
|
365
366
|
return true;
|
|
366
367
|
}
|
|
367
368
|
};
|
|
369
|
+
function generateHexId(bytes) {
|
|
370
|
+
let result = "";
|
|
371
|
+
for (let i = 0; i < bytes; i++) {
|
|
372
|
+
result += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
var OTELIDGenerator = class extends IDGenerator {
|
|
377
|
+
getSpanId() {
|
|
378
|
+
return generateHexId(8);
|
|
379
|
+
}
|
|
380
|
+
getTraceId() {
|
|
381
|
+
return generateHexId(16);
|
|
382
|
+
}
|
|
383
|
+
shareRootSpanId() {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
function parseEnvBool(name) {
|
|
388
|
+
const raw = isomorph_default.getEnv(name);
|
|
389
|
+
if (raw === void 0 || raw === null) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
const normalized = raw.trim().toLowerCase();
|
|
393
|
+
return normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "y" || normalized === "on";
|
|
394
|
+
}
|
|
395
|
+
var _warnedLegacyUuidConflict = false;
|
|
396
|
+
function resolveUseLegacyUuidIds() {
|
|
397
|
+
const legacy = parseEnvBool("BRAINTRUST_LEGACY_IDS");
|
|
398
|
+
if (parseEnvBool("BRAINTRUST_OTEL_COMPAT")) {
|
|
399
|
+
if (legacy && !_warnedLegacyUuidConflict) {
|
|
400
|
+
_warnedLegacyUuidConflict = true;
|
|
401
|
+
debugLogger.warn(
|
|
402
|
+
"BRAINTRUST_LEGACY_IDS is ignored because BRAINTRUST_OTEL_COMPAT requires OpenTelemetry-compatible hex span IDs. Using hex IDs."
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
return legacy;
|
|
408
|
+
}
|
|
368
409
|
function getIdGenerator() {
|
|
369
|
-
|
|
410
|
+
if (globalThis.BRAINTRUST_ID_GENERATOR !== void 0) {
|
|
411
|
+
return new globalThis.BRAINTRUST_ID_GENERATOR();
|
|
412
|
+
}
|
|
413
|
+
return resolveUseLegacyUuidIds() ? new UUIDGenerator() : new OTELIDGenerator();
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/propagation.ts
|
|
417
|
+
var TRACEPARENT_HEADER = "traceparent";
|
|
418
|
+
var TRACESTATE_HEADER = "tracestate";
|
|
419
|
+
var BAGGAGE_HEADER = "baggage";
|
|
420
|
+
var BRAINTRUST_PARENT_KEY = "braintrust.parent";
|
|
421
|
+
var DEFAULT_TRACE_FLAGS = "01";
|
|
422
|
+
var TRACEPARENT_RE = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
|
|
423
|
+
var ZERO_TRACE_ID = "0".repeat(32);
|
|
424
|
+
var ZERO_SPAN_ID = "0".repeat(16);
|
|
425
|
+
var MAX_BAGGAGE_LENGTH = 8192;
|
|
426
|
+
var MAX_BAGGAGE_MEMBERS = 64;
|
|
427
|
+
var _utf8Encoder = new TextEncoder();
|
|
428
|
+
function utf8ByteLength(value) {
|
|
429
|
+
return _utf8Encoder.encode(value).length;
|
|
430
|
+
}
|
|
431
|
+
function capBaggageToMemberBoundary(value) {
|
|
432
|
+
const totalBytes = utf8ByteLength(value);
|
|
433
|
+
const withinBytes = totalBytes <= MAX_BAGGAGE_LENGTH;
|
|
434
|
+
let commaCount = 0;
|
|
435
|
+
for (let i = 0; i < value.length; i++) {
|
|
436
|
+
if (value.charCodeAt(i) === 44) {
|
|
437
|
+
commaCount++;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const withinMembers = commaCount < MAX_BAGGAGE_MEMBERS;
|
|
441
|
+
if (withinBytes && withinMembers) {
|
|
442
|
+
return value;
|
|
443
|
+
}
|
|
444
|
+
const kept = [];
|
|
445
|
+
let length = 0;
|
|
446
|
+
for (const rawMember of value.split(",")) {
|
|
447
|
+
if (kept.length >= MAX_BAGGAGE_MEMBERS) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
const cost = utf8ByteLength(rawMember) + (kept.length ? 1 : 0);
|
|
451
|
+
if (length + cost > MAX_BAGGAGE_LENGTH) {
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
kept.push(rawMember);
|
|
455
|
+
length += cost;
|
|
456
|
+
}
|
|
457
|
+
if (!kept.length) {
|
|
458
|
+
return "";
|
|
459
|
+
}
|
|
460
|
+
return kept.join(",");
|
|
461
|
+
}
|
|
462
|
+
function isTraceContextHeaderTupleArray(value) {
|
|
463
|
+
return Array.isArray(value) && value.every(
|
|
464
|
+
(item) => Array.isArray(item) && typeof item[0] === "string" && typeof item[1] === "string"
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
function isListHeader(name) {
|
|
468
|
+
const lowered = name.toLowerCase();
|
|
469
|
+
return lowered === BAGGAGE_HEADER || lowered === TRACESTATE_HEADER;
|
|
470
|
+
}
|
|
471
|
+
function headerValueToString(value, name) {
|
|
472
|
+
if (value === void 0 || value === null) {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
475
|
+
if (Array.isArray(value)) {
|
|
476
|
+
const stringValues = value.filter((item) => {
|
|
477
|
+
return typeof item === "string";
|
|
478
|
+
});
|
|
479
|
+
if (!stringValues.length) {
|
|
480
|
+
return void 0;
|
|
481
|
+
}
|
|
482
|
+
return isListHeader(name) ? stringValues.join(",") : stringValues[0];
|
|
483
|
+
}
|
|
484
|
+
return typeof value === "string" ? value : String(value);
|
|
485
|
+
}
|
|
486
|
+
function getHeader(headers, name) {
|
|
487
|
+
if (!headers) {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
if (isTraceContextHeaderTupleArray(headers)) {
|
|
491
|
+
const lowered2 = name.toLowerCase();
|
|
492
|
+
const matches = headers.filter(([key]) => key.toLowerCase() === lowered2).map(([, value]) => value);
|
|
493
|
+
if (!matches.length) {
|
|
494
|
+
return void 0;
|
|
495
|
+
}
|
|
496
|
+
return headerValueToString(matches, name);
|
|
497
|
+
}
|
|
498
|
+
const getter = headers.get;
|
|
499
|
+
if (typeof getter === "function") {
|
|
500
|
+
try {
|
|
501
|
+
const value = headerValueToString(getter.call(headers, name), name);
|
|
502
|
+
if (value !== void 0) {
|
|
503
|
+
return value;
|
|
504
|
+
}
|
|
505
|
+
} catch {
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const nodeGetter = headers.getHeader;
|
|
509
|
+
if (typeof nodeGetter === "function") {
|
|
510
|
+
try {
|
|
511
|
+
const value = headerValueToString(nodeGetter.call(headers, name), name);
|
|
512
|
+
if (value !== void 0) {
|
|
513
|
+
return value;
|
|
514
|
+
}
|
|
515
|
+
} catch {
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const headerBag = headers;
|
|
519
|
+
const exact = headerValueToString(headerBag[name], name);
|
|
520
|
+
if (exact !== void 0) {
|
|
521
|
+
return exact;
|
|
522
|
+
}
|
|
523
|
+
const lowered = name.toLowerCase();
|
|
524
|
+
for (const key of Object.keys(headers)) {
|
|
525
|
+
if (key !== name && key.toLowerCase() === lowered) {
|
|
526
|
+
const value = headerValueToString(headerBag[key], name);
|
|
527
|
+
if (value !== void 0) {
|
|
528
|
+
return value;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return void 0;
|
|
533
|
+
}
|
|
534
|
+
function isHex(value, length) {
|
|
535
|
+
if (typeof value !== "string" || value.length !== length) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
for (let i = 0; i < value.length; i++) {
|
|
539
|
+
const c = value[i];
|
|
540
|
+
const isDigit = c >= "0" && c <= "9";
|
|
541
|
+
const isLowerHex = c >= "a" && c <= "f";
|
|
542
|
+
if (!isDigit && !isLowerHex) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
function parseTraceparent(value) {
|
|
549
|
+
if (!value || typeof value !== "string") {
|
|
550
|
+
return void 0;
|
|
551
|
+
}
|
|
552
|
+
const match = TRACEPARENT_RE.exec(value.trim());
|
|
553
|
+
if (!match) {
|
|
554
|
+
return void 0;
|
|
555
|
+
}
|
|
556
|
+
const traceId = match[1];
|
|
557
|
+
const spanId = match[2];
|
|
558
|
+
const traceFlags = match[3];
|
|
559
|
+
if (traceId === ZERO_TRACE_ID || spanId === ZERO_SPAN_ID) {
|
|
560
|
+
return void 0;
|
|
561
|
+
}
|
|
562
|
+
return { traceId, spanId, traceFlags };
|
|
563
|
+
}
|
|
564
|
+
function formatTraceparent(traceId, spanId, traceFlags = DEFAULT_TRACE_FLAGS) {
|
|
565
|
+
if (!isHex(traceId, 32) || traceId === ZERO_TRACE_ID) {
|
|
566
|
+
return void 0;
|
|
567
|
+
}
|
|
568
|
+
if (!isHex(spanId, 16) || spanId === ZERO_SPAN_ID) {
|
|
569
|
+
return void 0;
|
|
570
|
+
}
|
|
571
|
+
const flags = isHex(traceFlags, 2) ? traceFlags : DEFAULT_TRACE_FLAGS;
|
|
572
|
+
return `00-${traceId}-${spanId}-${flags}`;
|
|
573
|
+
}
|
|
574
|
+
function percentEncode(value) {
|
|
575
|
+
return encodeURIComponent(value);
|
|
576
|
+
}
|
|
577
|
+
function percentDecode(value) {
|
|
578
|
+
if (!value.includes("%")) {
|
|
579
|
+
return value;
|
|
580
|
+
}
|
|
581
|
+
try {
|
|
582
|
+
return decodeURIComponent(value);
|
|
583
|
+
} catch {
|
|
584
|
+
return value;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function parseBaggage(value) {
|
|
588
|
+
const result = {};
|
|
589
|
+
if (!value || typeof value !== "string") {
|
|
590
|
+
return result;
|
|
591
|
+
}
|
|
592
|
+
const bounded = capBaggageToMemberBoundary(value);
|
|
593
|
+
for (let member of bounded.split(",")) {
|
|
594
|
+
member = member.trim();
|
|
595
|
+
if (!member || !member.includes("=")) {
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
member = member.split(";", 1)[0];
|
|
599
|
+
const eq = member.indexOf("=");
|
|
600
|
+
const key = percentDecode(member.slice(0, eq).trim());
|
|
601
|
+
const val = member.slice(eq + 1).trim();
|
|
602
|
+
if (!key) {
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
result[key] = percentDecode(val);
|
|
606
|
+
}
|
|
607
|
+
return result;
|
|
608
|
+
}
|
|
609
|
+
function mergeBaggage(existing, braintrustParent) {
|
|
610
|
+
let btMember = void 0;
|
|
611
|
+
if (braintrustParent) {
|
|
612
|
+
const encodedKey = percentEncode(BRAINTRUST_PARENT_KEY);
|
|
613
|
+
const encodedVal = percentEncode(String(braintrustParent));
|
|
614
|
+
btMember = `${encodedKey}=${encodedVal}`;
|
|
615
|
+
if (utf8ByteLength(btMember) > MAX_BAGGAGE_LENGTH) {
|
|
616
|
+
btMember = void 0;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
let byteBudget = MAX_BAGGAGE_LENGTH;
|
|
620
|
+
let memberBudget = MAX_BAGGAGE_MEMBERS;
|
|
621
|
+
if (btMember !== void 0) {
|
|
622
|
+
byteBudget -= utf8ByteLength(btMember) + 1;
|
|
623
|
+
memberBudget -= 1;
|
|
624
|
+
}
|
|
625
|
+
const relayed = [];
|
|
626
|
+
let length = 0;
|
|
627
|
+
if (existing && typeof existing === "string") {
|
|
628
|
+
for (const rawMember of existing.split(",")) {
|
|
629
|
+
const member = rawMember.trim();
|
|
630
|
+
if (!member || !member.includes("=")) {
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
const keyPart = member.split(";", 1)[0].split("=", 1)[0];
|
|
634
|
+
const key = percentDecode(keyPart.trim());
|
|
635
|
+
if (key === BRAINTRUST_PARENT_KEY) {
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
if (relayed.length >= memberBudget) {
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
const cost = utf8ByteLength(member) + (relayed.length ? 1 : 0);
|
|
642
|
+
if (length + cost > byteBudget) {
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
relayed.push(member);
|
|
646
|
+
length += cost;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
const members = btMember !== void 0 ? [...relayed, btMember] : relayed;
|
|
650
|
+
if (!members.length) {
|
|
651
|
+
return void 0;
|
|
652
|
+
}
|
|
653
|
+
return members.join(",");
|
|
370
654
|
}
|
|
371
655
|
|
|
372
656
|
// util/db_fields.ts
|
|
@@ -974,7 +1258,7 @@ var SpanComponentsV3 = class _SpanComponentsV3 {
|
|
|
974
1258
|
case 3 /* PLAYGROUND_LOGS */:
|
|
975
1259
|
return { prompt_session_id: this.data.object_id, log_id: "x" };
|
|
976
1260
|
default:
|
|
977
|
-
|
|
1261
|
+
this.data.object_type;
|
|
978
1262
|
throw new Error("Impossible");
|
|
979
1263
|
}
|
|
980
1264
|
}
|
|
@@ -1413,7 +1697,7 @@ var SpanComponentsV4 = class _SpanComponentsV4 {
|
|
|
1413
1697
|
case 3 /* PLAYGROUND_LOGS */:
|
|
1414
1698
|
return { prompt_session_id: this.data.object_id, log_id: "x" };
|
|
1415
1699
|
default:
|
|
1416
|
-
|
|
1700
|
+
this.data.object_type;
|
|
1417
1701
|
throw new Error(`Invalid object_type ${this.data.object_type}`);
|
|
1418
1702
|
}
|
|
1419
1703
|
}
|
|
@@ -1537,7 +1821,8 @@ var AclObjectType = z6.union([
|
|
|
1537
1821
|
"role",
|
|
1538
1822
|
"org_member",
|
|
1539
1823
|
"project_log",
|
|
1540
|
-
"org_project"
|
|
1824
|
+
"org_project",
|
|
1825
|
+
"org_audit_logs"
|
|
1541
1826
|
]),
|
|
1542
1827
|
z6.null()
|
|
1543
1828
|
]);
|
|
@@ -1563,6 +1848,17 @@ var Acl = z6.object({
|
|
|
1563
1848
|
_object_org_id: z6.string().uuid(),
|
|
1564
1849
|
created: z6.union([z6.string(), z6.null()]).optional()
|
|
1565
1850
|
});
|
|
1851
|
+
var Agent = z6.object({
|
|
1852
|
+
id: z6.string().uuid(),
|
|
1853
|
+
project_id: z6.string().uuid(),
|
|
1854
|
+
user_id: z6.string().uuid(),
|
|
1855
|
+
created: z6.union([z6.string(), z6.null()]).optional(),
|
|
1856
|
+
name: z6.string(),
|
|
1857
|
+
slug: z6.string(),
|
|
1858
|
+
kind: z6.string(),
|
|
1859
|
+
description: z6.union([z6.string(), z6.null()]).optional(),
|
|
1860
|
+
metadata: z6.union([z6.object({}).partial().passthrough(), z6.null()]).optional()
|
|
1861
|
+
});
|
|
1566
1862
|
var AISecret = z6.object({
|
|
1567
1863
|
id: z6.string().uuid(),
|
|
1568
1864
|
created: z6.union([z6.string(), z6.null()]).optional(),
|
|
@@ -1709,6 +2005,7 @@ var AttachmentStatus = z6.object({
|
|
|
1709
2005
|
upload_status: UploadStatus,
|
|
1710
2006
|
error_message: z6.string().optional()
|
|
1711
2007
|
});
|
|
2008
|
+
var AutomationStatus = z6.enum(["active", "paused"]);
|
|
1712
2009
|
var FunctionTypeEnum = z6.enum([
|
|
1713
2010
|
"llm",
|
|
1714
2011
|
"scorer",
|
|
@@ -1754,7 +2051,9 @@ var TopicMapData = z6.object({
|
|
|
1754
2051
|
topic_names: z6.record(z6.string()).optional(),
|
|
1755
2052
|
generation_settings: TopicMapGenerationSettings.optional(),
|
|
1756
2053
|
disable_reconciliation: z6.boolean().optional(),
|
|
1757
|
-
distance_threshold: z6.number().optional()
|
|
2054
|
+
distance_threshold: z6.number().optional(),
|
|
2055
|
+
btql_filter: z6.string().optional(),
|
|
2056
|
+
automation_btql_filter: z6.string().optional()
|
|
1758
2057
|
});
|
|
1759
2058
|
var BatchedFacetData = z6.object({
|
|
1760
2059
|
type: z6.literal("batched_facet"),
|
|
@@ -1828,19 +2127,30 @@ var CallEvent = z6.union([
|
|
|
1828
2127
|
var ChatCompletionContentPartTextWithTitle = z6.object({
|
|
1829
2128
|
text: z6.string().default(""),
|
|
1830
2129
|
type: z6.literal("text"),
|
|
1831
|
-
cache_control: z6.object({
|
|
2130
|
+
cache_control: z6.object({
|
|
2131
|
+
type: z6.literal("ephemeral"),
|
|
2132
|
+
ttl: z6.enum(["5m", "1h"]).optional()
|
|
2133
|
+
}).optional()
|
|
1832
2134
|
});
|
|
1833
2135
|
var ChatCompletionContentPartImageWithTitle = z6.object({
|
|
1834
2136
|
image_url: z6.object({
|
|
1835
2137
|
url: z6.string(),
|
|
1836
2138
|
detail: z6.union([z6.literal("auto"), z6.literal("low"), z6.literal("high")]).optional()
|
|
1837
2139
|
}),
|
|
1838
|
-
type: z6.literal("image_url")
|
|
2140
|
+
type: z6.literal("image_url"),
|
|
2141
|
+
cache_control: z6.object({
|
|
2142
|
+
type: z6.literal("ephemeral"),
|
|
2143
|
+
ttl: z6.enum(["5m", "1h"]).optional()
|
|
2144
|
+
}).optional()
|
|
1839
2145
|
});
|
|
1840
2146
|
var ChatCompletionContentPartFileFile = z6.object({ file_data: z6.string(), filename: z6.string(), file_id: z6.string() }).partial();
|
|
1841
2147
|
var ChatCompletionContentPartFileWithTitle = z6.object({
|
|
1842
2148
|
file: ChatCompletionContentPartFileFile,
|
|
1843
|
-
type: z6.literal("file")
|
|
2149
|
+
type: z6.literal("file"),
|
|
2150
|
+
cache_control: z6.object({
|
|
2151
|
+
type: z6.literal("ephemeral"),
|
|
2152
|
+
ttl: z6.enum(["5m", "1h"]).optional()
|
|
2153
|
+
}).optional()
|
|
1844
2154
|
});
|
|
1845
2155
|
var ChatCompletionContentPart = z6.union([
|
|
1846
2156
|
ChatCompletionContentPartTextWithTitle,
|
|
@@ -1850,7 +2160,10 @@ var ChatCompletionContentPart = z6.union([
|
|
|
1850
2160
|
var ChatCompletionContentPartText = z6.object({
|
|
1851
2161
|
text: z6.string().default(""),
|
|
1852
2162
|
type: z6.literal("text"),
|
|
1853
|
-
cache_control: z6.object({
|
|
2163
|
+
cache_control: z6.object({
|
|
2164
|
+
type: z6.literal("ephemeral"),
|
|
2165
|
+
ttl: z6.enum(["5m", "1h"]).optional()
|
|
2166
|
+
}).optional()
|
|
1854
2167
|
});
|
|
1855
2168
|
var ChatCompletionMessageToolCall = z6.object({
|
|
1856
2169
|
id: z6.string(),
|
|
@@ -2037,7 +2350,7 @@ var DatasetEvent = z6.object({
|
|
|
2037
2350
|
origin: ObjectReferenceNullish.optional(),
|
|
2038
2351
|
comments: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2039
2352
|
audit_data: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2040
|
-
facets: z6.union([z6.
|
|
2353
|
+
facets: z6.union([z6.record(z6.union([z6.string(), z6.null()])), z6.null()]).optional(),
|
|
2041
2354
|
classifications: z6.union([
|
|
2042
2355
|
z6.record(
|
|
2043
2356
|
z6.array(
|
|
@@ -2189,7 +2502,7 @@ var ExperimentEvent = z6.object({
|
|
|
2189
2502
|
origin: ObjectReferenceNullish.optional(),
|
|
2190
2503
|
comments: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2191
2504
|
audit_data: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2192
|
-
facets: z6.union([z6.
|
|
2505
|
+
facets: z6.union([z6.record(z6.union([z6.string(), z6.null()])), z6.null()]).optional(),
|
|
2193
2506
|
classifications: z6.union([
|
|
2194
2507
|
z6.record(
|
|
2195
2508
|
z6.array(
|
|
@@ -2327,7 +2640,8 @@ var PromptParserNullish = z6.union([
|
|
|
2327
2640
|
use_cot: z6.boolean(),
|
|
2328
2641
|
choice_scores: z6.record(z6.number().gte(0).lte(1)).optional(),
|
|
2329
2642
|
choice: z6.array(z6.string()).optional(),
|
|
2330
|
-
allow_no_match: z6.boolean().optional()
|
|
2643
|
+
allow_no_match: z6.boolean().optional(),
|
|
2644
|
+
allow_skip: z6.boolean().optional()
|
|
2331
2645
|
}),
|
|
2332
2646
|
z6.null()
|
|
2333
2647
|
]);
|
|
@@ -2657,6 +2971,9 @@ var Group = z6.object({
|
|
|
2657
2971
|
var GroupScope = z6.object({
|
|
2658
2972
|
type: z6.literal("group"),
|
|
2659
2973
|
group_by: z6.string(),
|
|
2974
|
+
interval_seconds: z6.number().gte(1).optional(),
|
|
2975
|
+
max_traces: z6.number().int().gte(1).lte(64).optional(),
|
|
2976
|
+
placement: z6.enum(["first", "each"]),
|
|
2660
2977
|
idle_seconds: z6.number().optional()
|
|
2661
2978
|
});
|
|
2662
2979
|
var IfExists = z6.enum(["error", "ignore", "replace"]);
|
|
@@ -2805,6 +3122,10 @@ var RetentionObjectType = z6.enum([
|
|
|
2805
3122
|
"experiment",
|
|
2806
3123
|
"dataset"
|
|
2807
3124
|
]);
|
|
3125
|
+
var TopicAutomationFacetModel = z6.union([
|
|
3126
|
+
z6.enum(["brain-facet-latest", "brain-facet-1", "brain-facet-2"]),
|
|
3127
|
+
z6.null()
|
|
3128
|
+
]);
|
|
2808
3129
|
var TopicMapFunctionAutomation = z6.object({
|
|
2809
3130
|
function: SavedFunctionId.and(z6.unknown()),
|
|
2810
3131
|
btql_filter: z6.union([z6.string(), z6.null()]).optional()
|
|
@@ -2817,7 +3138,9 @@ var TopicAutomationDataScope = z6.union([
|
|
|
2817
3138
|
]);
|
|
2818
3139
|
var TopicAutomationConfig = z6.object({
|
|
2819
3140
|
event_type: z6.literal("topic"),
|
|
3141
|
+
status: AutomationStatus.optional(),
|
|
2820
3142
|
sampling_rate: z6.number().gte(0).lte(1),
|
|
3143
|
+
facet_model: TopicAutomationFacetModel.optional(),
|
|
2821
3144
|
facet_functions: z6.array(SavedFunctionId),
|
|
2822
3145
|
topic_map_functions: z6.array(TopicMapFunctionAutomation),
|
|
2823
3146
|
scope: z6.union([SpanScope, TraceScope, GroupScope, z6.null()]).optional(),
|
|
@@ -2831,6 +3154,19 @@ var TopicAutomationConfig = z6.object({
|
|
|
2831
3154
|
z6.null()
|
|
2832
3155
|
]).optional()
|
|
2833
3156
|
});
|
|
3157
|
+
var TopicDigestAutomationConfig = z6.object({
|
|
3158
|
+
event_type: z6.literal("topic_digest"),
|
|
3159
|
+
status: AutomationStatus.optional(),
|
|
3160
|
+
window_seconds: z6.number().int().gte(3600).lte(2592e3).optional().default(86400),
|
|
3161
|
+
scheduled_time_minutes_utc: z6.number().int().gte(0).lte(1439),
|
|
3162
|
+
action: z6.object({
|
|
3163
|
+
type: z6.literal("slack"),
|
|
3164
|
+
workspace_id: z6.string(),
|
|
3165
|
+
channel: z6.string(),
|
|
3166
|
+
message_template: z6.string().optional()
|
|
3167
|
+
}),
|
|
3168
|
+
topic_map_function_ids: z6.array(z6.string()).max(10).optional()
|
|
3169
|
+
});
|
|
2834
3170
|
var ProjectAutomation = z6.object({
|
|
2835
3171
|
id: z6.string().uuid(),
|
|
2836
3172
|
project_id: z6.string().uuid(),
|
|
@@ -2855,6 +3191,7 @@ var ProjectAutomation = z6.object({
|
|
|
2855
3191
|
}),
|
|
2856
3192
|
z6.object({
|
|
2857
3193
|
event_type: z6.literal("btql_export"),
|
|
3194
|
+
status: AutomationStatus.optional(),
|
|
2858
3195
|
export_definition: z6.union([
|
|
2859
3196
|
z6.object({ type: z6.literal("log_traces") }),
|
|
2860
3197
|
z6.object({ type: z6.literal("log_spans") }),
|
|
@@ -2877,6 +3214,21 @@ var ProjectAutomation = z6.object({
|
|
|
2877
3214
|
]),
|
|
2878
3215
|
batch_size: z6.union([z6.number(), z6.null()]).optional()
|
|
2879
3216
|
}),
|
|
3217
|
+
z6.object({
|
|
3218
|
+
event_type: z6.literal("async_query"),
|
|
3219
|
+
status: AutomationStatus.optional(),
|
|
3220
|
+
created_by_user_id: z6.string().uuid(),
|
|
3221
|
+
object_type: z6.enum([
|
|
3222
|
+
"project_logs",
|
|
3223
|
+
"experiment",
|
|
3224
|
+
"dataset",
|
|
3225
|
+
"playground_logs"
|
|
3226
|
+
]),
|
|
3227
|
+
object_id: z6.string(),
|
|
3228
|
+
query: z6.string(),
|
|
3229
|
+
format: z6.literal("jsonl"),
|
|
3230
|
+
batch_size: z6.union([z6.number(), z6.null()]).optional()
|
|
3231
|
+
}),
|
|
2880
3232
|
z6.object({
|
|
2881
3233
|
event_type: z6.literal("retention"),
|
|
2882
3234
|
object_type: RetentionObjectType,
|
|
@@ -2895,7 +3247,8 @@ var ProjectAutomation = z6.object({
|
|
|
2895
3247
|
})
|
|
2896
3248
|
])
|
|
2897
3249
|
}),
|
|
2898
|
-
TopicAutomationConfig
|
|
3250
|
+
TopicAutomationConfig,
|
|
3251
|
+
TopicDigestAutomationConfig
|
|
2899
3252
|
])
|
|
2900
3253
|
});
|
|
2901
3254
|
var ProjectLogsEvent = z6.object({
|
|
@@ -2934,7 +3287,7 @@ var ProjectLogsEvent = z6.object({
|
|
|
2934
3287
|
comments: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2935
3288
|
audit_data: z6.union([z6.array(z6.unknown()), z6.null()]).optional(),
|
|
2936
3289
|
_async_scoring_state: z6.unknown().optional(),
|
|
2937
|
-
facets: z6.union([z6.
|
|
3290
|
+
facets: z6.union([z6.record(z6.union([z6.string(), z6.null()])), z6.null()]).optional(),
|
|
2938
3291
|
classifications: z6.union([
|
|
2939
3292
|
z6.record(
|
|
2940
3293
|
z6.array(
|
|
@@ -2983,11 +3336,34 @@ var ProjectScoreCategories = z6.union([
|
|
|
2983
3336
|
z6.array(z6.string()),
|
|
2984
3337
|
z6.null()
|
|
2985
3338
|
]);
|
|
3339
|
+
var ProjectScoreCondition = z6.union([
|
|
3340
|
+
z6.object({
|
|
3341
|
+
when: z6.object({
|
|
3342
|
+
clauses: z6.union([z6.array(z6.string()), z6.null()]),
|
|
3343
|
+
subspan_clauses: z6.union([z6.array(z6.string()), z6.null()]),
|
|
3344
|
+
trace_clauses: z6.union([z6.array(z6.string()), z6.null()])
|
|
3345
|
+
}).partial(),
|
|
3346
|
+
behavior: z6.literal("hidden").optional().default("hidden")
|
|
3347
|
+
}),
|
|
3348
|
+
z6.null()
|
|
3349
|
+
]);
|
|
2986
3350
|
var ProjectScoreConfig = z6.union([
|
|
2987
3351
|
z6.object({
|
|
2988
3352
|
multi_select: z6.union([z6.boolean(), z6.null()]),
|
|
2989
3353
|
destination: z6.union([z6.string(), z6.null()]),
|
|
2990
|
-
|
|
3354
|
+
visibility: z6.union([
|
|
3355
|
+
z6.object({
|
|
3356
|
+
users: z6.union([z6.array(z6.string()), z6.null()]),
|
|
3357
|
+
groups: z6.union([z6.array(z6.string()), z6.null()])
|
|
3358
|
+
}).partial(),
|
|
3359
|
+
z6.null()
|
|
3360
|
+
]),
|
|
3361
|
+
online: OnlineScoreConfig,
|
|
3362
|
+
condition: ProjectScoreCondition,
|
|
3363
|
+
object_types: z6.union([
|
|
3364
|
+
z6.array(z6.enum(["project_logs", "dataset", "experiment"])),
|
|
3365
|
+
z6.null()
|
|
3366
|
+
])
|
|
2991
3367
|
}).partial(),
|
|
2992
3368
|
z6.null()
|
|
2993
3369
|
]);
|
|
@@ -3172,8 +3548,7 @@ var User = z6.object({
|
|
|
3172
3548
|
family_name: z6.union([z6.string(), z6.null()]).optional(),
|
|
3173
3549
|
email: z6.union([z6.string(), z6.null()]).optional(),
|
|
3174
3550
|
avatar_url: z6.union([z6.string(), z6.null()]).optional(),
|
|
3175
|
-
created: z6.union([z6.string(), z6.null()]).optional()
|
|
3176
|
-
last_active_at: z6.union([z6.number(), z6.null()]).optional()
|
|
3551
|
+
created: z6.union([z6.string(), z6.null()]).optional()
|
|
3177
3552
|
});
|
|
3178
3553
|
var ViewDataSearch = z6.union([
|
|
3179
3554
|
z6.object({
|
|
@@ -3813,13 +4188,23 @@ var LRUCache = class {
|
|
|
3813
4188
|
* @returns The cached value if found, undefined otherwise.
|
|
3814
4189
|
*/
|
|
3815
4190
|
get(key) {
|
|
3816
|
-
const
|
|
3817
|
-
if (
|
|
4191
|
+
const entry = this.cache.get(key);
|
|
4192
|
+
if (entry === void 0) {
|
|
3818
4193
|
return void 0;
|
|
3819
4194
|
}
|
|
3820
4195
|
this.cache.delete(key);
|
|
3821
|
-
this.cache.set(key,
|
|
3822
|
-
return value;
|
|
4196
|
+
this.cache.set(key, entry);
|
|
4197
|
+
return entry.value;
|
|
4198
|
+
}
|
|
4199
|
+
/**
|
|
4200
|
+
* Checks whether a key exists and marks it as most recently used.
|
|
4201
|
+
*/
|
|
4202
|
+
has(key) {
|
|
4203
|
+
if (!this.cache.has(key)) {
|
|
4204
|
+
return false;
|
|
4205
|
+
}
|
|
4206
|
+
this.get(key);
|
|
4207
|
+
return true;
|
|
3823
4208
|
}
|
|
3824
4209
|
/**
|
|
3825
4210
|
* Stores a value in the cache.
|
|
@@ -3836,7 +4221,38 @@ var LRUCache = class {
|
|
|
3836
4221
|
const first = this.cache.keys().next().value;
|
|
3837
4222
|
this.cache.delete(first);
|
|
3838
4223
|
}
|
|
3839
|
-
this.cache.set(key, value);
|
|
4224
|
+
this.cache.set(key, { value });
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4227
|
+
* Removes an item from the cache.
|
|
4228
|
+
*/
|
|
4229
|
+
delete(key) {
|
|
4230
|
+
return this.cache.delete(key);
|
|
4231
|
+
}
|
|
4232
|
+
/**
|
|
4233
|
+
* Iterates over cache entries from least to most recently used.
|
|
4234
|
+
*/
|
|
4235
|
+
*entries() {
|
|
4236
|
+
for (const [key, entry] of this.cache) {
|
|
4237
|
+
yield [key, entry.value];
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
/**
|
|
4241
|
+
* Iterates over cache keys from least to most recently used.
|
|
4242
|
+
*/
|
|
4243
|
+
keys() {
|
|
4244
|
+
return this.cache.keys();
|
|
4245
|
+
}
|
|
4246
|
+
/**
|
|
4247
|
+
* Iterates over cache values from least to most recently used.
|
|
4248
|
+
*/
|
|
4249
|
+
*values() {
|
|
4250
|
+
for (const entry of this.cache.values()) {
|
|
4251
|
+
yield entry.value;
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
[Symbol.iterator]() {
|
|
4255
|
+
return this.entries();
|
|
3840
4256
|
}
|
|
3841
4257
|
/**
|
|
3842
4258
|
* Removes all items from the cache.
|
|
@@ -4394,6 +4810,9 @@ function applyMaskingToField(maskingFunction, data, fieldName) {
|
|
|
4394
4810
|
return `ERROR: Failed to mask field '${fieldName}' - ${errorType}`;
|
|
4395
4811
|
}
|
|
4396
4812
|
}
|
|
4813
|
+
var INITIAL_SPAN_WRITE_AS_MERGE = /* @__PURE__ */ Symbol(
|
|
4814
|
+
"braintrust.initial-span-write-as-merge"
|
|
4815
|
+
);
|
|
4397
4816
|
var BRAINTRUST_CURRENT_SPAN_STORE = /* @__PURE__ */ Symbol.for(
|
|
4398
4817
|
"braintrust.currentSpanStore"
|
|
4399
4818
|
);
|
|
@@ -4434,7 +4853,10 @@ var BraintrustContextManager = class extends ContextManager {
|
|
|
4434
4853
|
}
|
|
4435
4854
|
};
|
|
4436
4855
|
function getSpanComponentsClass() {
|
|
4437
|
-
|
|
4856
|
+
if (globalThis.BRAINTRUST_SPAN_COMPONENT) {
|
|
4857
|
+
return globalThis.BRAINTRUST_SPAN_COMPONENT;
|
|
4858
|
+
}
|
|
4859
|
+
return resolveUseLegacyUuidIds() ? SpanComponentsV3 : SpanComponentsV4;
|
|
4438
4860
|
}
|
|
4439
4861
|
function getContextManager() {
|
|
4440
4862
|
return globalThis.BRAINTRUST_CONTEXT_MANAGER ? new globalThis.BRAINTRUST_CONTEXT_MANAGER() : new BraintrustContextManager();
|
|
@@ -4470,6 +4892,9 @@ var NoopSpan = class {
|
|
|
4470
4892
|
async export() {
|
|
4471
4893
|
return "";
|
|
4472
4894
|
}
|
|
4895
|
+
inject(carrier) {
|
|
4896
|
+
return carrier ?? {};
|
|
4897
|
+
}
|
|
4473
4898
|
async permalink() {
|
|
4474
4899
|
return NOOP_SPAN_PERMALINK;
|
|
4475
4900
|
}
|
|
@@ -4520,6 +4945,10 @@ var loginSchema = z8.strictObject({
|
|
|
4520
4945
|
debugLogLevelDisabled: z8.boolean().optional()
|
|
4521
4946
|
});
|
|
4522
4947
|
var stateNonce = 0;
|
|
4948
|
+
var V1_PROXY_SUFFIX = "/v1/proxy";
|
|
4949
|
+
function normalizeProxyConnUrl(proxyUrl) {
|
|
4950
|
+
return proxyUrl.endsWith(V1_PROXY_SUFFIX) ? proxyUrl.slice(0, proxyUrl.length - V1_PROXY_SUFFIX.length) : proxyUrl;
|
|
4951
|
+
}
|
|
4523
4952
|
var BraintrustState = class _BraintrustState {
|
|
4524
4953
|
constructor(loginParams) {
|
|
4525
4954
|
this.loginParams = loginParams;
|
|
@@ -4790,7 +5219,10 @@ var BraintrustState = class _BraintrustState {
|
|
|
4790
5219
|
if (!this.proxyUrl) {
|
|
4791
5220
|
throw new Error("Must initialize proxyUrl before requesting proxyConn");
|
|
4792
5221
|
}
|
|
4793
|
-
this._proxyConn = new HTTPConnection(
|
|
5222
|
+
this._proxyConn = new HTTPConnection(
|
|
5223
|
+
normalizeProxyConnUrl(this.proxyUrl),
|
|
5224
|
+
this.fetch
|
|
5225
|
+
);
|
|
4794
5226
|
}
|
|
4795
5227
|
return this._proxyConn;
|
|
4796
5228
|
}
|
|
@@ -5476,7 +5908,7 @@ async function permalink(slug, opts) {
|
|
|
5476
5908
|
return state2.appUrl;
|
|
5477
5909
|
};
|
|
5478
5910
|
try {
|
|
5479
|
-
const components =
|
|
5911
|
+
const components = SpanComponentsV4.fromStr(slug);
|
|
5480
5912
|
const object_type = spanObjectTypeV3ToString(components.data.object_type);
|
|
5481
5913
|
const [orgName, appUrl, object_id] = await Promise.all([
|
|
5482
5914
|
getOrgName(),
|
|
@@ -5500,35 +5932,47 @@ function startSpanParentArgs(args) {
|
|
|
5500
5932
|
let argParentObjectId = void 0;
|
|
5501
5933
|
let argParentSpanIds = void 0;
|
|
5502
5934
|
let argPropagatedEvent = void 0;
|
|
5503
|
-
|
|
5935
|
+
let argPropagatedState = void 0;
|
|
5936
|
+
const { parentSlug, propagatedState: parentPropagatedState } = normalizeParent(args.parent, args.state);
|
|
5937
|
+
if (parentSlug) {
|
|
5504
5938
|
if (args.parentSpanIds) {
|
|
5505
5939
|
throw new Error("Cannot specify both parent and parentSpanIds");
|
|
5506
5940
|
}
|
|
5507
|
-
const parentComponents =
|
|
5941
|
+
const parentComponents = SpanComponentsV4.fromStr(parentSlug);
|
|
5508
5942
|
if (args.parentObjectType !== parentComponents.data.object_type) {
|
|
5509
5943
|
throw new Error(
|
|
5510
5944
|
`Mismatch between expected span parent object type ${args.parentObjectType} and provided type ${parentComponents.data.object_type}`
|
|
5511
5945
|
);
|
|
5512
5946
|
}
|
|
5513
5947
|
argParentObjectId = args.parentObjectId;
|
|
5514
|
-
if (parentComponents.data.row_id
|
|
5948
|
+
if (parentComponents.data.row_id && parentSpanIdsUsable(
|
|
5949
|
+
parentComponents.data.span_id,
|
|
5950
|
+
parentComponents.data.root_span_id
|
|
5951
|
+
)) {
|
|
5515
5952
|
argParentSpanIds = {
|
|
5516
5953
|
spanId: parentComponents.data.span_id,
|
|
5517
5954
|
rootSpanId: parentComponents.data.root_span_id
|
|
5518
5955
|
};
|
|
5519
5956
|
}
|
|
5520
5957
|
argPropagatedEvent = args.propagatedEvent ?? (parentComponents.data.propagated_event ?? void 0);
|
|
5958
|
+
const propagatedState = args.propagatedState ?? parentPropagatedState;
|
|
5959
|
+
if (propagatedState) {
|
|
5960
|
+
const { braintrustParent: _ignoredBraintrustParent, ...w3cState } = propagatedState;
|
|
5961
|
+
argPropagatedState = w3cState;
|
|
5962
|
+
}
|
|
5521
5963
|
} else {
|
|
5522
5964
|
argParentObjectId = args.parentObjectId;
|
|
5523
5965
|
argParentSpanIds = args.parentSpanIds;
|
|
5524
5966
|
argPropagatedEvent = args.propagatedEvent;
|
|
5967
|
+
argPropagatedState = args.propagatedState;
|
|
5525
5968
|
}
|
|
5526
5969
|
return {
|
|
5527
5970
|
parentObjectType: args.parentObjectType,
|
|
5528
5971
|
parentObjectId: argParentObjectId,
|
|
5529
5972
|
parentComputeObjectMetadataArgs: args.parentComputeObjectMetadataArgs,
|
|
5530
5973
|
parentSpanIds: argParentSpanIds,
|
|
5531
|
-
propagatedEvent: argPropagatedEvent
|
|
5974
|
+
propagatedEvent: argPropagatedEvent,
|
|
5975
|
+
propagatedState: argPropagatedState
|
|
5532
5976
|
};
|
|
5533
5977
|
}
|
|
5534
5978
|
var Logger = class {
|
|
@@ -5729,6 +6173,22 @@ var Logger = class {
|
|
|
5729
6173
|
_getLinkBaseUrl() {
|
|
5730
6174
|
return _getLinkBaseUrl(this.state, this._linkArgs);
|
|
5731
6175
|
}
|
|
6176
|
+
/**
|
|
6177
|
+
* Return this logger's Braintrust parent string (`project_id:<id>` or
|
|
6178
|
+
* `project_name:<name>`) for the `braintrust.parent` baggage entry, or
|
|
6179
|
+
* undefined when it cannot be determined synchronously.
|
|
6180
|
+
*/
|
|
6181
|
+
_getOtelParent() {
|
|
6182
|
+
const id = this.computeMetadataArgs?.project_id || this.lazyId.getSync().value;
|
|
6183
|
+
if (id) {
|
|
6184
|
+
return `project_id:${id}`;
|
|
6185
|
+
}
|
|
6186
|
+
const name = this.computeMetadataArgs?.project_name;
|
|
6187
|
+
if (name) {
|
|
6188
|
+
return `project_name:${name}`;
|
|
6189
|
+
}
|
|
6190
|
+
return void 0;
|
|
6191
|
+
}
|
|
5732
6192
|
};
|
|
5733
6193
|
function castLogger(logger, asyncFlush) {
|
|
5734
6194
|
if (logger === void 0) return void 0;
|
|
@@ -5823,12 +6283,12 @@ function stringifyWithOverflowMeta(item) {
|
|
|
5823
6283
|
object_ids: pickLogs3OverflowObjectIds(record),
|
|
5824
6284
|
is_delete: record[OBJECT_DELETE_FIELD] === true,
|
|
5825
6285
|
input_row: {
|
|
5826
|
-
byte_size:
|
|
6286
|
+
byte_size: utf8ByteLength2(str)
|
|
5827
6287
|
}
|
|
5828
6288
|
}
|
|
5829
6289
|
};
|
|
5830
6290
|
}
|
|
5831
|
-
function
|
|
6291
|
+
function utf8ByteLength2(value) {
|
|
5832
6292
|
if (typeof TextEncoder !== "undefined") {
|
|
5833
6293
|
return new TextEncoder().encode(value).length;
|
|
5834
6294
|
}
|
|
@@ -6159,7 +6619,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
6159
6619
|
}) {
|
|
6160
6620
|
const conn = await this.apiConn.get();
|
|
6161
6621
|
const dataStr = constructLogs3Data(items);
|
|
6162
|
-
const payloadBytes =
|
|
6622
|
+
const payloadBytes = utf8ByteLength2(dataStr);
|
|
6163
6623
|
const useOverflow = canUseOverflow && payloadBytes > maxRequestSize;
|
|
6164
6624
|
if (this.allPublishPayloadsDir) {
|
|
6165
6625
|
await _HTTPBackgroundLogger.writePayloadToDir({
|
|
@@ -6493,23 +6953,253 @@ function currentSpan(options) {
|
|
|
6493
6953
|
const state2 = options?.state ?? _globalState;
|
|
6494
6954
|
return state2.contextManager.getCurrentSpan() ?? NOOP_SPAN;
|
|
6495
6955
|
}
|
|
6496
|
-
function
|
|
6956
|
+
function getSpanParentObjectAndPropagatedState(options) {
|
|
6497
6957
|
const state2 = options?.state ?? _globalState;
|
|
6498
6958
|
const parentSpan = currentSpan({ state: state2 });
|
|
6499
6959
|
if (!Object.is(parentSpan, NOOP_SPAN)) {
|
|
6500
|
-
return parentSpan;
|
|
6960
|
+
return { parentObject: parentSpan, propagatedState: void 0 };
|
|
6961
|
+
}
|
|
6962
|
+
const parent = options?.parent ?? state2.currentParent.getStore();
|
|
6963
|
+
const { parentSlug, propagatedState } = normalizeParent(parent, state2);
|
|
6964
|
+
if (parentSlug) {
|
|
6965
|
+
return {
|
|
6966
|
+
parentObject: SpanComponentsV4.fromStr(parentSlug),
|
|
6967
|
+
propagatedState
|
|
6968
|
+
};
|
|
6501
6969
|
}
|
|
6502
|
-
const parentStr = options?.parent ?? state2.currentParent.getStore();
|
|
6503
|
-
if (parentStr) return getSpanComponentsClass().fromStr(parentStr);
|
|
6504
6970
|
const experiment = currentExperiment();
|
|
6505
6971
|
if (experiment) {
|
|
6506
|
-
return experiment;
|
|
6972
|
+
return { parentObject: experiment, propagatedState: void 0 };
|
|
6507
6973
|
}
|
|
6508
6974
|
const logger = currentLogger(options);
|
|
6509
6975
|
if (logger) {
|
|
6510
|
-
return logger;
|
|
6976
|
+
return { parentObject: logger, propagatedState: void 0 };
|
|
6977
|
+
}
|
|
6978
|
+
return { parentObject: NOOP_SPAN, propagatedState: void 0 };
|
|
6979
|
+
}
|
|
6980
|
+
function currentBraintrustParent(state2) {
|
|
6981
|
+
const resolvedState = state2 ?? _globalState;
|
|
6982
|
+
const experiment = currentExperiment({ state: resolvedState });
|
|
6983
|
+
if (experiment) {
|
|
6984
|
+
try {
|
|
6985
|
+
return experiment._getOtelParent() ?? void 0;
|
|
6986
|
+
} catch {
|
|
6987
|
+
return void 0;
|
|
6988
|
+
}
|
|
6989
|
+
}
|
|
6990
|
+
const logger = currentLogger({ state: resolvedState });
|
|
6991
|
+
if (logger) {
|
|
6992
|
+
try {
|
|
6993
|
+
return logger._getOtelParent() ?? void 0;
|
|
6994
|
+
} catch {
|
|
6995
|
+
return void 0;
|
|
6996
|
+
}
|
|
6997
|
+
}
|
|
6998
|
+
return void 0;
|
|
6999
|
+
}
|
|
7000
|
+
function braintrustParentToComponents(braintrustParent) {
|
|
7001
|
+
if (!braintrustParent) {
|
|
7002
|
+
return void 0;
|
|
7003
|
+
}
|
|
7004
|
+
if (braintrustParent.startsWith("project_id:")) {
|
|
7005
|
+
const objectId = braintrustParent.slice("project_id:".length);
|
|
7006
|
+
return objectId ? {
|
|
7007
|
+
objectType: 2 /* PROJECT_LOGS */,
|
|
7008
|
+
objectId,
|
|
7009
|
+
computeArgs: void 0
|
|
7010
|
+
} : void 0;
|
|
7011
|
+
}
|
|
7012
|
+
if (braintrustParent.startsWith("project_name:")) {
|
|
7013
|
+
const name = braintrustParent.slice("project_name:".length);
|
|
7014
|
+
return name ? {
|
|
7015
|
+
objectType: 2 /* PROJECT_LOGS */,
|
|
7016
|
+
objectId: void 0,
|
|
7017
|
+
computeArgs: { project_name: name }
|
|
7018
|
+
} : void 0;
|
|
7019
|
+
}
|
|
7020
|
+
if (braintrustParent.startsWith("experiment_id:")) {
|
|
7021
|
+
const objectId = braintrustParent.slice("experiment_id:".length);
|
|
7022
|
+
return objectId ? {
|
|
7023
|
+
objectType: 1 /* EXPERIMENT */,
|
|
7024
|
+
objectId,
|
|
7025
|
+
computeArgs: void 0
|
|
7026
|
+
} : void 0;
|
|
7027
|
+
}
|
|
7028
|
+
return void 0;
|
|
7029
|
+
}
|
|
7030
|
+
function isMutableHeaderTupleArray(carrier) {
|
|
7031
|
+
return Array.isArray(carrier) && carrier.every((item) => Array.isArray(item) && typeof item[0] === "string");
|
|
7032
|
+
}
|
|
7033
|
+
function setHeader(carrier, name, value) {
|
|
7034
|
+
if (isMutableHeaderTupleArray(carrier)) {
|
|
7035
|
+
const lowered2 = name.toLowerCase();
|
|
7036
|
+
for (let i = carrier.length - 1; i >= 0; i--) {
|
|
7037
|
+
if (carrier[i][0].toLowerCase() === lowered2) {
|
|
7038
|
+
carrier.splice(i, 1);
|
|
7039
|
+
}
|
|
7040
|
+
}
|
|
7041
|
+
carrier.push([name, value]);
|
|
7042
|
+
return;
|
|
7043
|
+
}
|
|
7044
|
+
const setter = carrier.set;
|
|
7045
|
+
if (typeof setter === "function") {
|
|
7046
|
+
const deleter = carrier.delete;
|
|
7047
|
+
if (typeof deleter === "function") {
|
|
7048
|
+
try {
|
|
7049
|
+
deleter.call(carrier, name);
|
|
7050
|
+
} catch {
|
|
7051
|
+
}
|
|
7052
|
+
}
|
|
7053
|
+
setter.call(carrier, name, value);
|
|
7054
|
+
return;
|
|
7055
|
+
}
|
|
7056
|
+
const nodeSetter = carrier.setHeader;
|
|
7057
|
+
if (typeof nodeSetter === "function") {
|
|
7058
|
+
const remover = carrier.removeHeader;
|
|
7059
|
+
if (typeof remover === "function") {
|
|
7060
|
+
try {
|
|
7061
|
+
remover.call(carrier, name);
|
|
7062
|
+
} catch {
|
|
7063
|
+
}
|
|
7064
|
+
}
|
|
7065
|
+
nodeSetter.call(carrier, name, value);
|
|
7066
|
+
return;
|
|
7067
|
+
}
|
|
7068
|
+
const headerSetter = carrier.header;
|
|
7069
|
+
if (typeof headerSetter === "function") {
|
|
7070
|
+
const deleter = carrier.delete;
|
|
7071
|
+
if (typeof deleter === "function") {
|
|
7072
|
+
try {
|
|
7073
|
+
deleter.call(carrier, name);
|
|
7074
|
+
} catch {
|
|
7075
|
+
}
|
|
7076
|
+
}
|
|
7077
|
+
const remover = carrier.removeHeader;
|
|
7078
|
+
if (typeof remover === "function") {
|
|
7079
|
+
try {
|
|
7080
|
+
remover.call(carrier, name);
|
|
7081
|
+
} catch {
|
|
7082
|
+
}
|
|
7083
|
+
}
|
|
7084
|
+
headerSetter.call(carrier, name, value);
|
|
7085
|
+
return;
|
|
7086
|
+
}
|
|
7087
|
+
const headerBag = carrier;
|
|
7088
|
+
const lowered = name.toLowerCase();
|
|
7089
|
+
for (const key of Object.keys(headerBag)) {
|
|
7090
|
+
if (key !== name && key.toLowerCase() === lowered) {
|
|
7091
|
+
delete headerBag[key];
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
headerBag[name] = value;
|
|
7095
|
+
}
|
|
7096
|
+
function deleteHeader(carrier, name) {
|
|
7097
|
+
const lowered = name.toLowerCase();
|
|
7098
|
+
if (isMutableHeaderTupleArray(carrier)) {
|
|
7099
|
+
for (let i = carrier.length - 1; i >= 0; i--) {
|
|
7100
|
+
if (carrier[i][0].toLowerCase() === lowered) {
|
|
7101
|
+
carrier.splice(i, 1);
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
return;
|
|
7105
|
+
}
|
|
7106
|
+
const deleter = carrier.delete;
|
|
7107
|
+
if (typeof deleter === "function") {
|
|
7108
|
+
try {
|
|
7109
|
+
deleter.call(carrier, name);
|
|
7110
|
+
return;
|
|
7111
|
+
} catch {
|
|
7112
|
+
}
|
|
7113
|
+
}
|
|
7114
|
+
const remover = carrier.removeHeader;
|
|
7115
|
+
if (typeof remover === "function") {
|
|
7116
|
+
try {
|
|
7117
|
+
remover.call(carrier, name);
|
|
7118
|
+
return;
|
|
7119
|
+
} catch {
|
|
7120
|
+
}
|
|
7121
|
+
}
|
|
7122
|
+
const headerBag = carrier;
|
|
7123
|
+
for (const key of Object.keys(headerBag)) {
|
|
7124
|
+
if (key.toLowerCase() === lowered) {
|
|
7125
|
+
delete headerBag[key];
|
|
7126
|
+
}
|
|
6511
7127
|
}
|
|
6512
|
-
|
|
7128
|
+
}
|
|
7129
|
+
function _injectIntoCarrier(carrier, args) {
|
|
7130
|
+
const traceFlags = args.propagatedState?.traceFlags;
|
|
7131
|
+
const traceparent = traceFlags ? formatTraceparent(args.traceId, args.spanId, traceFlags) : formatTraceparent(args.traceId, args.spanId);
|
|
7132
|
+
if (traceparent === void 0) {
|
|
7133
|
+
return;
|
|
7134
|
+
}
|
|
7135
|
+
setHeader(carrier, TRACEPARENT_HEADER, traceparent);
|
|
7136
|
+
const tracestate = args.propagatedState?.tracestate;
|
|
7137
|
+
if (tracestate) {
|
|
7138
|
+
setHeader(carrier, TRACESTATE_HEADER, tracestate);
|
|
7139
|
+
}
|
|
7140
|
+
const existing = getHeader(carrier, BAGGAGE_HEADER);
|
|
7141
|
+
const baggageValue = mergeBaggage(existing, args.braintrustParent);
|
|
7142
|
+
if (baggageValue !== void 0) {
|
|
7143
|
+
setHeader(carrier, BAGGAGE_HEADER, baggageValue);
|
|
7144
|
+
} else if (existing !== void 0) {
|
|
7145
|
+
deleteHeader(carrier, BAGGAGE_HEADER);
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
function resolveW3cParent(context, state2) {
|
|
7149
|
+
const traceparent = getHeader(context, TRACEPARENT_HEADER);
|
|
7150
|
+
const parsed = traceparent ? parseTraceparent(traceparent) : void 0;
|
|
7151
|
+
if (parsed === void 0) {
|
|
7152
|
+
return { parentSlug: void 0, propagatedState: void 0 };
|
|
7153
|
+
}
|
|
7154
|
+
const { traceId, spanId, traceFlags } = parsed;
|
|
7155
|
+
let braintrustParent = void 0;
|
|
7156
|
+
const baggageValue = getHeader(context, BAGGAGE_HEADER);
|
|
7157
|
+
if (baggageValue) {
|
|
7158
|
+
braintrustParent = parseBaggage(baggageValue)[BRAINTRUST_PARENT_KEY];
|
|
7159
|
+
}
|
|
7160
|
+
if (!braintrustParent) {
|
|
7161
|
+
braintrustParent = currentBraintrustParent(state2);
|
|
7162
|
+
}
|
|
7163
|
+
if (!braintrustParent) {
|
|
7164
|
+
debugLogger.warn(
|
|
7165
|
+
"Received traceparent without a braintrust.parent and no active logger/experiment; cannot route the trace. Starting a fresh local span instead."
|
|
7166
|
+
);
|
|
7167
|
+
return { parentSlug: void 0, propagatedState: void 0 };
|
|
7168
|
+
}
|
|
7169
|
+
const parsedParent = braintrustParentToComponents(braintrustParent);
|
|
7170
|
+
if (parsedParent === void 0) {
|
|
7171
|
+
debugLogger.warn(
|
|
7172
|
+
`Invalid braintrust.parent: ${JSON.stringify(braintrustParent)}`
|
|
7173
|
+
);
|
|
7174
|
+
return { parentSlug: void 0, propagatedState: void 0 };
|
|
7175
|
+
}
|
|
7176
|
+
const { objectType, objectId, computeArgs } = parsedParent;
|
|
7177
|
+
const tracestate = getHeader(context, TRACESTATE_HEADER);
|
|
7178
|
+
const slug = new SpanComponentsV4({
|
|
7179
|
+
object_type: objectType,
|
|
7180
|
+
...computeArgs ? { compute_object_metadata_args: computeArgs } : { object_id: objectId },
|
|
7181
|
+
row_id: "bt-propagation",
|
|
7182
|
+
// non-empty to enable span_id/root_span_id
|
|
7183
|
+
span_id: spanId,
|
|
7184
|
+
root_span_id: traceId
|
|
7185
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
7186
|
+
}).toStr();
|
|
7187
|
+
return {
|
|
7188
|
+
parentSlug: slug,
|
|
7189
|
+
propagatedState: { tracestate, traceFlags, braintrustParent }
|
|
7190
|
+
};
|
|
7191
|
+
}
|
|
7192
|
+
function normalizeParent(parent, state2) {
|
|
7193
|
+
if (parent && typeof parent === "object") {
|
|
7194
|
+
return resolveW3cParent(parent, state2);
|
|
7195
|
+
}
|
|
7196
|
+
return {
|
|
7197
|
+
parentSlug: parent ?? void 0,
|
|
7198
|
+
propagatedState: void 0
|
|
7199
|
+
};
|
|
7200
|
+
}
|
|
7201
|
+
function parentSpanIdsUsable(spanId, rootSpanId) {
|
|
7202
|
+
return Boolean(spanId) && Boolean(rootSpanId);
|
|
6513
7203
|
}
|
|
6514
7204
|
function logError(span, error) {
|
|
6515
7205
|
let errorMessage = "<error>";
|
|
@@ -6529,19 +7219,23 @@ function startSpan(args) {
|
|
|
6529
7219
|
}
|
|
6530
7220
|
function startSpanAndIsLogger(args) {
|
|
6531
7221
|
const state2 = args?.state ?? _globalState;
|
|
6532
|
-
const parentObject =
|
|
7222
|
+
const { parentObject, propagatedState } = getSpanParentObjectAndPropagatedState({
|
|
6533
7223
|
asyncFlush: args?.asyncFlush,
|
|
6534
7224
|
parent: args?.parent,
|
|
6535
7225
|
state: state2
|
|
6536
7226
|
});
|
|
6537
7227
|
if (parentObject instanceof SpanComponentsV3 || parentObject instanceof SpanComponentsV4) {
|
|
6538
|
-
const parentSpanIds = parentObject.data.row_id
|
|
7228
|
+
const parentSpanIds = parentObject.data.row_id && parentSpanIdsUsable(
|
|
7229
|
+
parentObject.data.span_id,
|
|
7230
|
+
parentObject.data.root_span_id
|
|
7231
|
+
) ? {
|
|
6539
7232
|
spanId: parentObject.data.span_id,
|
|
6540
7233
|
rootSpanId: parentObject.data.root_span_id
|
|
6541
7234
|
} : void 0;
|
|
7235
|
+
const { parent: _ignoredParent, ...spanArgs } = args ?? {};
|
|
6542
7236
|
const span = new SpanImpl({
|
|
6543
7237
|
state: state2,
|
|
6544
|
-
...
|
|
7238
|
+
...spanArgs,
|
|
6545
7239
|
parentObjectType: parentObject.data.object_type,
|
|
6546
7240
|
parentObjectId: new LazyValue(
|
|
6547
7241
|
spanComponentsToObjectIdLambda(state2, parentObject)
|
|
@@ -6549,7 +7243,8 @@ function startSpanAndIsLogger(args) {
|
|
|
6549
7243
|
parentComputeObjectMetadataArgs: parentObject.data.compute_object_metadata_args ?? void 0,
|
|
6550
7244
|
parentSpanIds,
|
|
6551
7245
|
propagatedEvent: args?.propagatedEvent ?? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
6552
|
-
(parentObject.data.propagated_event ?? void 0)
|
|
7246
|
+
(parentObject.data.propagated_event ?? void 0),
|
|
7247
|
+
propagatedState
|
|
6553
7248
|
});
|
|
6554
7249
|
return {
|
|
6555
7250
|
span,
|
|
@@ -6776,11 +7471,12 @@ function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
|
|
|
6776
7471
|
var DEFAULT_FETCH_BATCH_SIZE = 1e3;
|
|
6777
7472
|
var MAX_BTQL_ITERATIONS = 1e4;
|
|
6778
7473
|
var ObjectFetcher = class {
|
|
6779
|
-
constructor(objectType, pinnedVersion, mutateRecord, _internal_btql) {
|
|
7474
|
+
constructor(objectType, pinnedVersion, mutateRecord, _internal_btql, _internalBrainstoreRealtime = true) {
|
|
6780
7475
|
this.objectType = objectType;
|
|
6781
7476
|
this.pinnedVersion = pinnedVersion;
|
|
6782
7477
|
this.mutateRecord = mutateRecord;
|
|
6783
7478
|
this._internal_btql = _internal_btql;
|
|
7479
|
+
this._internalBrainstoreRealtime = _internalBrainstoreRealtime;
|
|
6784
7480
|
}
|
|
6785
7481
|
_fetchedData = void 0;
|
|
6786
7482
|
get id() {
|
|
@@ -6839,7 +7535,7 @@ var ObjectFetcher = class {
|
|
|
6839
7535
|
...internalBtqlWithoutReservedQueryKeys
|
|
6840
7536
|
},
|
|
6841
7537
|
use_columnstore: false,
|
|
6842
|
-
brainstore_realtime:
|
|
7538
|
+
brainstore_realtime: this._internalBrainstoreRealtime,
|
|
6843
7539
|
query_source: `js_sdk_object_fetcher_${this.objectType}`,
|
|
6844
7540
|
...this.pinnedVersion !== void 0 ? {
|
|
6845
7541
|
version: this.pinnedVersion
|
|
@@ -7188,6 +7884,15 @@ View complete results in Braintrust or run experiment.summarize() again.`
|
|
|
7188
7884
|
object_id: await this.id
|
|
7189
7885
|
}).toStr();
|
|
7190
7886
|
}
|
|
7887
|
+
/**
|
|
7888
|
+
* Return this experiment's Braintrust parent string (`experiment_id:<id>`) for
|
|
7889
|
+
* the `braintrust.parent` baggage entry, or undefined when it cannot be
|
|
7890
|
+
* determined synchronously.
|
|
7891
|
+
*/
|
|
7892
|
+
_getOtelParent() {
|
|
7893
|
+
const id = this.lazyId.getSync().value;
|
|
7894
|
+
return id ? `experiment_id:${id}` : void 0;
|
|
7895
|
+
}
|
|
7191
7896
|
/**
|
|
7192
7897
|
* Flush any pending rows to the server.
|
|
7193
7898
|
*/
|
|
@@ -7252,9 +7957,16 @@ var SpanImpl = class _SpanImpl {
|
|
|
7252
7957
|
_spanId;
|
|
7253
7958
|
_rootSpanId;
|
|
7254
7959
|
_spanParents;
|
|
7960
|
+
// Inbound W3C trace-context state (tracestate + raw traceparent flags) to
|
|
7961
|
+
// forward on outbound propagation. Captured at the span that received it (via
|
|
7962
|
+
// extractTraceContextFromHeaders) and inherited by all subspans, so that any
|
|
7963
|
+
// inject() within the trace re-emits the upstream state unchanged, per the W3C
|
|
7964
|
+
// Trace Context spec. Not interpreted.
|
|
7965
|
+
_propagatedState;
|
|
7255
7966
|
kind = "span";
|
|
7256
7967
|
constructor(args) {
|
|
7257
7968
|
this._state = args.state;
|
|
7969
|
+
this._propagatedState = args.propagatedState;
|
|
7258
7970
|
const spanAttributes = args.spanAttributes ?? {};
|
|
7259
7971
|
const rawEvent = args.event ?? {};
|
|
7260
7972
|
const type = args.type ?? (args.parentSpanIds ? void 0 : args.defaultRootType);
|
|
@@ -7305,7 +8017,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
7305
8017
|
this._spanId = resolvedIds.spanId;
|
|
7306
8018
|
this._rootSpanId = resolvedIds.rootSpanId;
|
|
7307
8019
|
this._spanParents = resolvedIds.spanParents;
|
|
7308
|
-
this.isMerge =
|
|
8020
|
+
this.isMerge = args[INITIAL_SPAN_WRITE_AS_MERGE] === true;
|
|
7309
8021
|
this.logInternal({ event, internalData });
|
|
7310
8022
|
this.isMerge = true;
|
|
7311
8023
|
}
|
|
@@ -7370,7 +8082,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
7370
8082
|
tags: partialRecord.tags,
|
|
7371
8083
|
span_id: this._spanId,
|
|
7372
8084
|
span_parents: this._spanParents,
|
|
7373
|
-
is_root: this.
|
|
8085
|
+
is_root: !this._spanParents || this._spanParents.length === 0,
|
|
7374
8086
|
span_attributes: partialRecord.span_attributes
|
|
7375
8087
|
};
|
|
7376
8088
|
this._state.spanCache.queueWrite(
|
|
@@ -7432,7 +8144,8 @@ var SpanImpl = class _SpanImpl {
|
|
|
7432
8144
|
parentObjectId: this.parentObjectId,
|
|
7433
8145
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
7434
8146
|
parentSpanIds,
|
|
7435
|
-
propagatedEvent: args?.propagatedEvent ?? this.propagatedEvent
|
|
8147
|
+
propagatedEvent: args?.propagatedEvent ?? this.propagatedEvent,
|
|
8148
|
+
propagatedState: this._propagatedState
|
|
7436
8149
|
})
|
|
7437
8150
|
});
|
|
7438
8151
|
}
|
|
@@ -7451,7 +8164,8 @@ var SpanImpl = class _SpanImpl {
|
|
|
7451
8164
|
parentObjectId: this.parentObjectId,
|
|
7452
8165
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
7453
8166
|
parentSpanIds,
|
|
7454
|
-
propagatedEvent: args?.propagatedEvent ?? this.propagatedEvent
|
|
8167
|
+
propagatedEvent: args?.propagatedEvent ?? this.propagatedEvent,
|
|
8168
|
+
propagatedState: this._propagatedState
|
|
7455
8169
|
}),
|
|
7456
8170
|
spanId
|
|
7457
8171
|
});
|
|
@@ -7479,6 +8193,42 @@ var SpanImpl = class _SpanImpl {
|
|
|
7479
8193
|
propagated_event: this.propagatedEvent
|
|
7480
8194
|
}).toStr();
|
|
7481
8195
|
}
|
|
8196
|
+
/**
|
|
8197
|
+
* Return this span's Braintrust parent string (`project_id:<id>`,
|
|
8198
|
+
* `project_name:<name>`, or `experiment_id:<id>`) for the `braintrust.parent`
|
|
8199
|
+
* baggage entry, or undefined when it cannot be determined synchronously.
|
|
8200
|
+
*/
|
|
8201
|
+
_getOtelParent() {
|
|
8202
|
+
if (this.parentObjectType === 2 /* PROJECT_LOGS */) {
|
|
8203
|
+
const id = this.parentComputeObjectMetadataArgs?.project_id || this.parentObjectId.getSync().value;
|
|
8204
|
+
const name = this.parentComputeObjectMetadataArgs?.project_name;
|
|
8205
|
+
if (id) {
|
|
8206
|
+
return `project_id:${id}`;
|
|
8207
|
+
} else if (name) {
|
|
8208
|
+
return `project_name:${name}`;
|
|
8209
|
+
}
|
|
8210
|
+
} else if (this.parentObjectType === 1 /* EXPERIMENT */) {
|
|
8211
|
+
const id = this.parentComputeObjectMetadataArgs?.experiment_id || this.parentObjectId.getSync().value;
|
|
8212
|
+
if (id) {
|
|
8213
|
+
return `experiment_id:${id}`;
|
|
8214
|
+
}
|
|
8215
|
+
}
|
|
8216
|
+
return void 0;
|
|
8217
|
+
}
|
|
8218
|
+
inject(carrier) {
|
|
8219
|
+
const resolvedCarrier = carrier ?? {};
|
|
8220
|
+
try {
|
|
8221
|
+
_injectIntoCarrier(resolvedCarrier, {
|
|
8222
|
+
traceId: this._rootSpanId,
|
|
8223
|
+
spanId: this._spanId,
|
|
8224
|
+
braintrustParent: this._getOtelParent() ?? this._propagatedState?.braintrustParent,
|
|
8225
|
+
propagatedState: this._propagatedState
|
|
8226
|
+
});
|
|
8227
|
+
} catch (e) {
|
|
8228
|
+
debugLogger.warn(`Error injecting trace context: ${e}`);
|
|
8229
|
+
}
|
|
8230
|
+
return resolvedCarrier;
|
|
8231
|
+
}
|
|
7482
8232
|
async permalink() {
|
|
7483
8233
|
return await permalink(await this.export(), {
|
|
7484
8234
|
state: this._state
|
|
@@ -7614,6 +8364,7 @@ var Dataset2 = class extends ObjectFetcher {
|
|
|
7614
8364
|
_internal_btql
|
|
7615
8365
|
);
|
|
7616
8366
|
this.state = state2;
|
|
8367
|
+
void this.__braintrust_dataset_marker;
|
|
7617
8368
|
this.lazyMetadata = lazyMetadata;
|
|
7618
8369
|
this.lazyPinnedVersion = pinState?.lazyPinnedVersion;
|
|
7619
8370
|
this.pinnedEnvironment = pinState?.pinnedEnvironment;
|
|
@@ -8093,7 +8844,13 @@ var BraintrustObservabilityExporter = class {
|
|
|
8093
8844
|
const args = {
|
|
8094
8845
|
name: exported.name,
|
|
8095
8846
|
spanAttributes: { type: spanTypeFor(exported.type) },
|
|
8096
|
-
startTime: epochSeconds(exported.startTime)
|
|
8847
|
+
startTime: epochSeconds(exported.startTime),
|
|
8848
|
+
// Use the Mastra span id as the Braintrust row id so that
|
|
8849
|
+
// `logFeedback({ id: <mastra span id> })` (and Mastra's score events)
|
|
8850
|
+
// attach to the right row. Without this, `SpanImpl` auto-generates a
|
|
8851
|
+
// row id (`this._id = eventId ?? idGenerator.getSpanId()`) that no
|
|
8852
|
+
// external caller could know.
|
|
8853
|
+
event: { id: exported.id }
|
|
8097
8854
|
};
|
|
8098
8855
|
const parentRecord = exported.parentSpanId ? this.spans.get(exported.parentSpanId) : void 0;
|
|
8099
8856
|
if (!this.capturedParent) {
|
|
@@ -8260,6 +9017,10 @@ var aiSDKChannels = defineChannels("ai", {
|
|
|
8260
9017
|
channelName: "ToolLoopAgent.stream",
|
|
8261
9018
|
kind: "async"
|
|
8262
9019
|
}),
|
|
9020
|
+
workflowAgentStream: channel({
|
|
9021
|
+
channelName: "WorkflowAgent.stream",
|
|
9022
|
+
kind: "async"
|
|
9023
|
+
}),
|
|
8263
9024
|
v7CreateTelemetryDispatcher: channel({
|
|
8264
9025
|
channelName: "createTelemetryDispatcher",
|
|
8265
9026
|
kind: "sync-stream"
|
|
@@ -8458,6 +9219,18 @@ var aiSDKConfigs = [
|
|
|
8458
9219
|
kind: "Sync"
|
|
8459
9220
|
}
|
|
8460
9221
|
},
|
|
9222
|
+
{
|
|
9223
|
+
channelName: aiSDKChannels.v7CreateTelemetryDispatcher.channelName,
|
|
9224
|
+
module: {
|
|
9225
|
+
name: "ai",
|
|
9226
|
+
versionRange: ">=7.0.0-0 <8.0.0",
|
|
9227
|
+
filePath: "dist/internal/index.js"
|
|
9228
|
+
},
|
|
9229
|
+
functionQuery: {
|
|
9230
|
+
functionName: "createTelemetryDispatcher",
|
|
9231
|
+
kind: "Sync"
|
|
9232
|
+
}
|
|
9233
|
+
},
|
|
8461
9234
|
// streamObject - async function (v3 only, before the sync refactor in v4)
|
|
8462
9235
|
{
|
|
8463
9236
|
channelName: aiSDKChannels.streamObject.channelName,
|
|
@@ -11203,9 +11976,6 @@ function getDefaultAutoInstrumentationConfigs() {
|
|
|
11203
11976
|
}
|
|
11204
11977
|
|
|
11205
11978
|
// src/auto-instrumentations/loader/cjs-patch.ts
|
|
11206
|
-
import {
|
|
11207
|
-
create
|
|
11208
|
-
} from "@apm-js-collab/code-transformer";
|
|
11209
11979
|
import * as NodeModule from "module";
|
|
11210
11980
|
import { sep } from "path";
|
|
11211
11981
|
import moduleDetailsFromPath from "module-details-from-path";
|
|
@@ -11262,8 +12032,6 @@ var ModulePatch = class {
|
|
|
11262
12032
|
args[0] = transformedCode?.code;
|
|
11263
12033
|
} catch (error) {
|
|
11264
12034
|
console.warn(`Error transforming module ${filename}:`, error);
|
|
11265
|
-
} finally {
|
|
11266
|
-
transformer.free();
|
|
11267
12035
|
}
|
|
11268
12036
|
}
|
|
11269
12037
|
}
|