braintrust 3.24.0 → 3.25.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/dev/dist/index.d.mts +5 -0
- package/dev/dist/index.d.ts +5 -0
- package/dev/dist/index.js +2614 -1567
- package/dev/dist/index.mjs +2037 -990
- package/dist/apply-auto-instrumentation.js +200 -199
- package/dist/apply-auto-instrumentation.mjs +8 -7
- package/dist/auto-instrumentations/bundler/esbuild.cjs +596 -462
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +596 -462
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +596 -462
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +596 -462
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +596 -462
- package/dist/auto-instrumentations/bundler/webpack.cjs +596 -462
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-BURMPO7L.mjs → chunk-7P6563SW.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-F43DNLPD.mjs → chunk-CZ24KNHT.mjs} +569 -442
- package/dist/auto-instrumentations/{chunk-GSZHTAQW.mjs → chunk-JPVCUKTY.mjs} +30 -21
- package/dist/auto-instrumentations/hook.mjs +648 -476
- package/dist/auto-instrumentations/index.cjs +568 -442
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/browser.d.mts +7 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +2022 -971
- package/dist/browser.mjs +2022 -971
- package/dist/{chunk-XE5FS7QY.mjs → chunk-2SANLSWX.mjs} +1375 -597
- package/dist/{chunk-7F6GCRHH.mjs → chunk-ABR2QWDP.mjs} +702 -456
- package/dist/{chunk-SU6EHKJV.js → chunk-GSIDVFE6.js} +2176 -1398
- package/dist/{chunk-7AUY2XWX.js → chunk-P25IOOU4.js} +704 -458
- package/dist/cli.js +2005 -958
- package/dist/edge-light.js +2022 -971
- package/dist/edge-light.mjs +2022 -971
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +447 -402
- package/dist/index.mjs +72 -27
- package/dist/instrumentation/index.d.mts +5 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.js +1990 -981
- package/dist/instrumentation/index.mjs +1990 -981
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.js +2022 -971
- package/dist/workerd.mjs +2022 -971
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1236,7 +1236,7 @@ var require_package = __commonJS({
|
|
|
1236
1236
|
"package.json"(exports2, module2) {
|
|
1237
1237
|
module2.exports = {
|
|
1238
1238
|
name: "braintrust",
|
|
1239
|
-
version: "3.
|
|
1239
|
+
version: "3.25.0",
|
|
1240
1240
|
description: "SDK for integrating Braintrust",
|
|
1241
1241
|
repository: {
|
|
1242
1242
|
type: "git",
|
|
@@ -1434,7 +1434,7 @@ var require_package = __commonJS({
|
|
|
1434
1434
|
"eslint-plugin-node-import": "^1.0.5",
|
|
1435
1435
|
openai: "6.25.0",
|
|
1436
1436
|
rollup: "^4.60.3",
|
|
1437
|
-
tar: "^7.5.
|
|
1437
|
+
tar: "^7.5.19",
|
|
1438
1438
|
tinybench: "^4.0.1",
|
|
1439
1439
|
"ts-declaration-location": "^1.0.7",
|
|
1440
1440
|
tsup: "^8.5.1",
|
|
@@ -6361,7 +6361,51 @@ var SpanCache = class {
|
|
|
6361
6361
|
};
|
|
6362
6362
|
|
|
6363
6363
|
// src/span-origin.ts
|
|
6364
|
-
var
|
|
6364
|
+
var INSTRUMENTATION_NAMES = {
|
|
6365
|
+
AI_SDK: "ai-sdk",
|
|
6366
|
+
ANTHROPIC: "anthropic",
|
|
6367
|
+
BEDROCK_RUNTIME: "bedrock-runtime",
|
|
6368
|
+
BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
|
|
6369
|
+
CLAUDE_AGENT_SDK: "claude-agent-sdk",
|
|
6370
|
+
COHERE: "cohere",
|
|
6371
|
+
CURSOR_SDK: "cursor-sdk",
|
|
6372
|
+
EVE: "eve",
|
|
6373
|
+
FLUE: "flue",
|
|
6374
|
+
GENKIT: "genkit",
|
|
6375
|
+
GITHUB_COPILOT: "github-copilot",
|
|
6376
|
+
GOOGLE_ADK: "google-adk",
|
|
6377
|
+
GOOGLE_GENAI: "google-genai",
|
|
6378
|
+
GROQ: "groq",
|
|
6379
|
+
HUGGINGFACE: "huggingface",
|
|
6380
|
+
LANGCHAIN: "langchain",
|
|
6381
|
+
LANGSMITH: "langsmith",
|
|
6382
|
+
MASTRA: "mastra",
|
|
6383
|
+
MISTRAL: "mistral",
|
|
6384
|
+
OPENAI: "openai",
|
|
6385
|
+
OPENAI_AGENTS: "openai-agents",
|
|
6386
|
+
OPENAI_CODEX: "openai-codex",
|
|
6387
|
+
OPENROUTER: "openrouter",
|
|
6388
|
+
OPENROUTER_AGENT: "openrouter-agent",
|
|
6389
|
+
PI_CODING_AGENT: "pi-coding-agent",
|
|
6390
|
+
STRANDS_AGENT_SDK: "strands-agent-sdk"
|
|
6391
|
+
};
|
|
6392
|
+
var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
|
|
6393
|
+
"braintrust.spanInstrumentationName"
|
|
6394
|
+
);
|
|
6395
|
+
var SDK_VERSION = true ? "3.25.0" : "0.0.0";
|
|
6396
|
+
function withSpanInstrumentationName(args, instrumentationName) {
|
|
6397
|
+
return {
|
|
6398
|
+
...args,
|
|
6399
|
+
[INTERNAL_SPAN_INSTRUMENTATION_NAME]: instrumentationName
|
|
6400
|
+
};
|
|
6401
|
+
}
|
|
6402
|
+
function getSpanInstrumentationName(args) {
|
|
6403
|
+
if (typeof args !== "object" || args === null) {
|
|
6404
|
+
return void 0;
|
|
6405
|
+
}
|
|
6406
|
+
const value = args[INTERNAL_SPAN_INSTRUMENTATION_NAME];
|
|
6407
|
+
return isSpanInstrumentationName(value) ? value : void 0;
|
|
6408
|
+
}
|
|
6365
6409
|
function detectSpanOriginEnvironment(explicit) {
|
|
6366
6410
|
if (explicit) return explicit;
|
|
6367
6411
|
const envType = isomorph_default.getEnv("BRAINTRUST_ENVIRONMENT_TYPE");
|
|
@@ -6433,6 +6477,9 @@ function mergeSpanOriginContext(context2, instrumentationName, environment) {
|
|
|
6433
6477
|
};
|
|
6434
6478
|
return next;
|
|
6435
6479
|
}
|
|
6480
|
+
function isSpanInstrumentationName(value) {
|
|
6481
|
+
return Object.values(INSTRUMENTATION_NAMES).some((name) => name === value);
|
|
6482
|
+
}
|
|
6436
6483
|
function firstPresent(entries) {
|
|
6437
6484
|
return entries.find(([key]) => Boolean(isomorph_default.getEnv(key)))?.[1];
|
|
6438
6485
|
}
|
|
@@ -6727,6 +6774,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
6727
6774
|
});
|
|
6728
6775
|
this.spanCache = new SpanCache({ disabled: loginParams.disableSpanCache });
|
|
6729
6776
|
this.spanOriginEnvironment = detectSpanOriginEnvironment();
|
|
6777
|
+
this._internalSetTraceContextSigningSecret(loginParams.apiKey);
|
|
6730
6778
|
}
|
|
6731
6779
|
loginParams;
|
|
6732
6780
|
id;
|
|
@@ -6764,6 +6812,18 @@ var BraintrustState = class _BraintrustState {
|
|
|
6764
6812
|
_contextManager = null;
|
|
6765
6813
|
_otelFlushCallback = null;
|
|
6766
6814
|
spanOriginEnvironment;
|
|
6815
|
+
traceContextSigningSecret;
|
|
6816
|
+
/** @internal */
|
|
6817
|
+
_internalSetTraceContextSigningSecret(secret) {
|
|
6818
|
+
const normalizedSecret = secret?.trim();
|
|
6819
|
+
if (normalizedSecret) {
|
|
6820
|
+
this.traceContextSigningSecret = normalizedSecret;
|
|
6821
|
+
}
|
|
6822
|
+
}
|
|
6823
|
+
/** @internal */
|
|
6824
|
+
_internalGetTraceContextSigningSecret() {
|
|
6825
|
+
return (this.traceContextSigningSecret ?? this.loginToken ?? isomorph_default.getEnv("BRAINTRUST_API_KEY"))?.trim();
|
|
6826
|
+
}
|
|
6767
6827
|
resetLoginInfo() {
|
|
6768
6828
|
this.appUrl = null;
|
|
6769
6829
|
this.appPublicUrl = null;
|
|
@@ -6824,6 +6884,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
6824
6884
|
this.gitMetadataSettings = other.gitMetadataSettings;
|
|
6825
6885
|
this.debugLogLevel = other.debugLogLevel;
|
|
6826
6886
|
this.debugLogLevelConfigured = other.debugLogLevelConfigured;
|
|
6887
|
+
this.traceContextSigningSecret = other.traceContextSigningSecret;
|
|
6827
6888
|
setGlobalDebugLogLevel(
|
|
6828
6889
|
this.debugLogLevelConfigured ? this.debugLogLevel ?? false : void 0
|
|
6829
6890
|
);
|
|
@@ -6911,6 +6972,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
6911
6972
|
return this.debugLogLevelConfigured;
|
|
6912
6973
|
}
|
|
6913
6974
|
async login(loginParams) {
|
|
6975
|
+
this._internalSetTraceContextSigningSecret(loginParams.apiKey);
|
|
6914
6976
|
this.setDebugLogLevel(loginParams.debugLogLevel);
|
|
6915
6977
|
if (this.apiUrl && !loginParams.forceLogin) {
|
|
6916
6978
|
return;
|
|
@@ -7575,6 +7637,28 @@ function updateSpanImpl({
|
|
|
7575
7637
|
}));
|
|
7576
7638
|
state.bgLogger().log([record]);
|
|
7577
7639
|
}
|
|
7640
|
+
function updateSpan({
|
|
7641
|
+
exported,
|
|
7642
|
+
state,
|
|
7643
|
+
...event
|
|
7644
|
+
}) {
|
|
7645
|
+
const resolvedState = state ?? _globalState;
|
|
7646
|
+
const components = SpanComponentsV4.fromStr(exported);
|
|
7647
|
+
if (!components.data.row_id) {
|
|
7648
|
+
throw new Error("Exported span must have a row id");
|
|
7649
|
+
}
|
|
7650
|
+
updateSpanImpl({
|
|
7651
|
+
state: resolvedState,
|
|
7652
|
+
parentObjectType: components.data.object_type,
|
|
7653
|
+
parentObjectId: new LazyValue(
|
|
7654
|
+
spanComponentsToObjectIdLambda(resolvedState, components)
|
|
7655
|
+
),
|
|
7656
|
+
id: components.data.row_id,
|
|
7657
|
+
root_span_id: components.data.root_span_id,
|
|
7658
|
+
span_id: components.data.span_id,
|
|
7659
|
+
event
|
|
7660
|
+
});
|
|
7661
|
+
}
|
|
7578
7662
|
function spanComponentsToObjectIdLambda(state, components) {
|
|
7579
7663
|
if (components.data.object_id) {
|
|
7580
7664
|
const ret = components.data.object_id;
|
|
@@ -8661,6 +8745,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
8661
8745
|
throw new Error("Cannot open and update an experiment at the same time");
|
|
8662
8746
|
}
|
|
8663
8747
|
const state = stateArg ?? _globalState;
|
|
8748
|
+
state._internalSetTraceContextSigningSecret(apiKey);
|
|
8664
8749
|
state.enforceQueueSizeLimit(false);
|
|
8665
8750
|
if (open2) {
|
|
8666
8751
|
if (isEmpty2(experiment)) {
|
|
@@ -9133,6 +9218,7 @@ function initLogger(options = {}) {
|
|
|
9133
9218
|
project_id: projectId
|
|
9134
9219
|
};
|
|
9135
9220
|
const state = stateArg ?? _globalState;
|
|
9221
|
+
state._internalSetTraceContextSigningSecret(apiKey);
|
|
9136
9222
|
state.setDebugLogLevel(debugLogLevel);
|
|
9137
9223
|
state.spanOriginEnvironment = detectSpanOriginEnvironment(environment);
|
|
9138
9224
|
state.enforceQueueSizeLimit(true);
|
|
@@ -9562,6 +9648,12 @@ function traced(callback, args) {
|
|
|
9562
9648
|
function startSpan(args) {
|
|
9563
9649
|
return startSpanAndIsLogger(args).span;
|
|
9564
9650
|
}
|
|
9651
|
+
function _internalStartSpanWithInitialMerge(args) {
|
|
9652
|
+
return startSpanAndIsLogger({
|
|
9653
|
+
...args,
|
|
9654
|
+
[INITIAL_SPAN_WRITE_AS_MERGE]: true
|
|
9655
|
+
}).span;
|
|
9656
|
+
}
|
|
9565
9657
|
async function flush(options) {
|
|
9566
9658
|
const state = options?.state ?? _globalState;
|
|
9567
9659
|
return await state.bgLogger().flush();
|
|
@@ -9713,7 +9805,9 @@ function deepCopyEvent(event) {
|
|
|
9713
9805
|
const ATTACHMENT_MARKER_KEY = "_bt_internal_saved_attachment_marker";
|
|
9714
9806
|
const attachmentMarker = ++deepCopyEventMarkerCounter;
|
|
9715
9807
|
const serialized = JSON.stringify(event, (_k, v) => {
|
|
9716
|
-
if (v instanceof
|
|
9808
|
+
if (v instanceof Error) {
|
|
9809
|
+
return v.message;
|
|
9810
|
+
} else if (v instanceof SpanImpl || v instanceof NoopSpan) {
|
|
9717
9811
|
return `<span>`;
|
|
9718
9812
|
} else if (v instanceof Experiment2) {
|
|
9719
9813
|
return `<experiment>`;
|
|
@@ -10381,6 +10475,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
10381
10475
|
constructor(args) {
|
|
10382
10476
|
this._state = args.state;
|
|
10383
10477
|
this._propagatedState = args.propagatedState;
|
|
10478
|
+
const instrumentationName = getSpanInstrumentationName(args) ?? INSTRUMENTATION_NAMES.BRAINTRUST_JS_LOGGER;
|
|
10384
10479
|
const spanAttributes = args.spanAttributes ?? {};
|
|
10385
10480
|
const rawEvent = args.event ?? {};
|
|
10386
10481
|
const type = args.type ?? (args.parentSpanIds ? void 0 : args.defaultRootType);
|
|
@@ -10412,7 +10507,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
10412
10507
|
},
|
|
10413
10508
|
context: mergeSpanOriginContext(
|
|
10414
10509
|
{ ...callerLocation },
|
|
10415
|
-
|
|
10510
|
+
instrumentationName,
|
|
10416
10511
|
this._state.spanOriginEnvironment
|
|
10417
10512
|
),
|
|
10418
10513
|
span_attributes: {
|
|
@@ -13949,26 +14044,30 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13949
14044
|
}
|
|
13950
14045
|
}
|
|
13951
14046
|
})();
|
|
14047
|
+
let timeoutId;
|
|
14048
|
+
let abortHandler;
|
|
14049
|
+
const cleanupCancellation = () => {
|
|
14050
|
+
if (timeoutId !== void 0) {
|
|
14051
|
+
clearTimeout(timeoutId);
|
|
14052
|
+
timeoutId = void 0;
|
|
14053
|
+
}
|
|
14054
|
+
if (abortHandler && evaluator.signal) {
|
|
14055
|
+
evaluator.signal.removeEventListener("abort", abortHandler);
|
|
14056
|
+
abortHandler = void 0;
|
|
14057
|
+
}
|
|
14058
|
+
};
|
|
13952
14059
|
const cancel = async () => {
|
|
13953
14060
|
await new Promise((_, reject2) => {
|
|
13954
14061
|
if (cancelled) {
|
|
13955
14062
|
reject2(new InternalAbortError("Evaluator already cancelled"));
|
|
13956
14063
|
return;
|
|
13957
14064
|
}
|
|
13958
|
-
let timeoutId;
|
|
13959
|
-
let abortHandler;
|
|
13960
14065
|
const rejectOnce = (error2) => {
|
|
13961
14066
|
if (cancelled) {
|
|
13962
14067
|
return;
|
|
13963
14068
|
}
|
|
13964
14069
|
cancelled = true;
|
|
13965
|
-
|
|
13966
|
-
clearTimeout(timeoutId);
|
|
13967
|
-
timeoutId = void 0;
|
|
13968
|
-
}
|
|
13969
|
-
if (abortHandler && evaluator.signal) {
|
|
13970
|
-
evaluator.signal.removeEventListener("abort", abortHandler);
|
|
13971
|
-
}
|
|
14070
|
+
cleanupCancellation();
|
|
13972
14071
|
reject2(error2);
|
|
13973
14072
|
};
|
|
13974
14073
|
if (evaluator.timeout) {
|
|
@@ -14008,6 +14107,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
14008
14107
|
}
|
|
14009
14108
|
throw e;
|
|
14010
14109
|
} finally {
|
|
14110
|
+
cleanupCancellation();
|
|
14011
14111
|
if (!collectResults) {
|
|
14012
14112
|
collectedResults.length = 0;
|
|
14013
14113
|
}
|
|
@@ -15392,15 +15492,25 @@ function hasChoices(value) {
|
|
|
15392
15492
|
function normalizeMetadata(metadata) {
|
|
15393
15493
|
return isObject(metadata) ? metadata : void 0;
|
|
15394
15494
|
}
|
|
15395
|
-
function startSpanForEvent(config3, event, channelName) {
|
|
15495
|
+
function startSpanForEvent(config3, event, channelName, instrumentationName) {
|
|
15396
15496
|
const { name, spanAttributes, spanInfoMetadata } = buildStartSpanArgs(
|
|
15397
15497
|
config3,
|
|
15398
15498
|
event
|
|
15399
15499
|
);
|
|
15400
|
-
const
|
|
15401
|
-
|
|
15402
|
-
|
|
15403
|
-
|
|
15500
|
+
const spanArgs = withSpanInstrumentationName(
|
|
15501
|
+
{
|
|
15502
|
+
name,
|
|
15503
|
+
spanAttributes
|
|
15504
|
+
},
|
|
15505
|
+
instrumentationName
|
|
15506
|
+
);
|
|
15507
|
+
let span;
|
|
15508
|
+
try {
|
|
15509
|
+
span = config3.startSpan?.(spanArgs) ?? startSpan(spanArgs);
|
|
15510
|
+
} catch (error2) {
|
|
15511
|
+
debugLogger.error(`Error starting span for ${channelName}:`, error2);
|
|
15512
|
+
span = startSpan(spanArgs);
|
|
15513
|
+
}
|
|
15404
15514
|
const startTime = getCurrentUnixTimestamp();
|
|
15405
15515
|
try {
|
|
15406
15516
|
const { input, metadata } = config3.extractInput(
|
|
@@ -15431,7 +15541,7 @@ function shouldTraceEvent(config3, event, channelName) {
|
|
|
15431
15541
|
return true;
|
|
15432
15542
|
}
|
|
15433
15543
|
}
|
|
15434
|
-
function ensureSpanStateForEvent(states, config3, event, channelName) {
|
|
15544
|
+
function ensureSpanStateForEvent(states, config3, event, channelName, instrumentationName) {
|
|
15435
15545
|
const key = event;
|
|
15436
15546
|
const existing = states.get(key);
|
|
15437
15547
|
if (existing) {
|
|
@@ -15440,11 +15550,16 @@ function ensureSpanStateForEvent(states, config3, event, channelName) {
|
|
|
15440
15550
|
if (!shouldTraceEvent(config3, event, channelName)) {
|
|
15441
15551
|
return void 0;
|
|
15442
15552
|
}
|
|
15443
|
-
const created = startSpanForEvent(
|
|
15553
|
+
const created = startSpanForEvent(
|
|
15554
|
+
config3,
|
|
15555
|
+
event,
|
|
15556
|
+
channelName,
|
|
15557
|
+
instrumentationName
|
|
15558
|
+
);
|
|
15444
15559
|
states.set(key, created);
|
|
15445
15560
|
return created;
|
|
15446
15561
|
}
|
|
15447
|
-
function bindCurrentSpanStoreToStart(tracingChannel2, states, config3, channelName) {
|
|
15562
|
+
function bindCurrentSpanStoreToStart(tracingChannel2, states, config3, channelName, instrumentationName) {
|
|
15448
15563
|
const state = _internalGetGlobalState();
|
|
15449
15564
|
const startChannel = tracingChannel2.start;
|
|
15450
15565
|
const contextManager = state?.contextManager;
|
|
@@ -15462,7 +15577,8 @@ function bindCurrentSpanStoreToStart(tracingChannel2, states, config3, channelNa
|
|
|
15462
15577
|
states,
|
|
15463
15578
|
config3,
|
|
15464
15579
|
event,
|
|
15465
|
-
channelName
|
|
15580
|
+
channelName,
|
|
15581
|
+
instrumentationName
|
|
15466
15582
|
);
|
|
15467
15583
|
return spanState ? contextManager.wrapSpanForStore(spanState.span) : currentSpanStore.getStore();
|
|
15468
15584
|
}
|
|
@@ -15471,15 +15587,21 @@ function bindCurrentSpanStoreToStart(tracingChannel2, states, config3, channelNa
|
|
|
15471
15587
|
startChannel.unbindStore(currentSpanStore);
|
|
15472
15588
|
};
|
|
15473
15589
|
}
|
|
15474
|
-
function logErrorAndEnd(states, event) {
|
|
15590
|
+
function logErrorAndEnd(states, event, channelName) {
|
|
15475
15591
|
const spanData = states.get(event);
|
|
15476
15592
|
if (!spanData) {
|
|
15477
15593
|
return;
|
|
15478
15594
|
}
|
|
15479
|
-
|
|
15480
|
-
error: event.error
|
|
15481
|
-
})
|
|
15482
|
-
|
|
15595
|
+
try {
|
|
15596
|
+
spanData.span.log({ error: event.error });
|
|
15597
|
+
} catch (error2) {
|
|
15598
|
+
debugLogger.error(`Error logging failure for ${channelName}:`, error2);
|
|
15599
|
+
}
|
|
15600
|
+
try {
|
|
15601
|
+
spanData.span.end();
|
|
15602
|
+
} catch (error2) {
|
|
15603
|
+
debugLogger.error(`Error ending span for ${channelName}:`, error2);
|
|
15604
|
+
}
|
|
15483
15605
|
states.delete(event);
|
|
15484
15606
|
}
|
|
15485
15607
|
function runStreamingCompletionHook(args) {
|
|
@@ -15529,7 +15651,8 @@ function traceAsyncChannel(channel2, config3) {
|
|
|
15529
15651
|
tracingChannel2,
|
|
15530
15652
|
states,
|
|
15531
15653
|
config3,
|
|
15532
|
-
channelName
|
|
15654
|
+
channelName,
|
|
15655
|
+
channel2.instrumentationName
|
|
15533
15656
|
);
|
|
15534
15657
|
const handlers = {
|
|
15535
15658
|
start: (event) => {
|
|
@@ -15540,7 +15663,8 @@ function traceAsyncChannel(channel2, config3) {
|
|
|
15540
15663
|
states,
|
|
15541
15664
|
config3,
|
|
15542
15665
|
event,
|
|
15543
|
-
channelName
|
|
15666
|
+
channelName,
|
|
15667
|
+
channel2.instrumentationName
|
|
15544
15668
|
);
|
|
15545
15669
|
},
|
|
15546
15670
|
asyncEnd: (event) => {
|
|
@@ -15577,7 +15701,7 @@ function traceAsyncChannel(channel2, config3) {
|
|
|
15577
15701
|
}
|
|
15578
15702
|
},
|
|
15579
15703
|
error: (event) => {
|
|
15580
|
-
logErrorAndEnd(states, event);
|
|
15704
|
+
logErrorAndEnd(states, event, channelName);
|
|
15581
15705
|
}
|
|
15582
15706
|
};
|
|
15583
15707
|
tracingChannel2.subscribe(handlers);
|
|
@@ -15594,7 +15718,8 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15594
15718
|
tracingChannel2,
|
|
15595
15719
|
states,
|
|
15596
15720
|
config3,
|
|
15597
|
-
channelName
|
|
15721
|
+
channelName,
|
|
15722
|
+
channel2.instrumentationName
|
|
15598
15723
|
);
|
|
15599
15724
|
const handlers = {
|
|
15600
15725
|
start: (event) => {
|
|
@@ -15605,7 +15730,8 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15605
15730
|
states,
|
|
15606
15731
|
config3,
|
|
15607
15732
|
event,
|
|
15608
|
-
channelName
|
|
15733
|
+
channelName,
|
|
15734
|
+
channel2.instrumentationName
|
|
15609
15735
|
);
|
|
15610
15736
|
},
|
|
15611
15737
|
asyncEnd: (event) => {
|
|
@@ -15624,6 +15750,7 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15624
15750
|
}
|
|
15625
15751
|
},
|
|
15626
15752
|
onComplete: (chunks) => {
|
|
15753
|
+
let completion2;
|
|
15627
15754
|
try {
|
|
15628
15755
|
let output;
|
|
15629
15756
|
let metrics;
|
|
@@ -15654,18 +15781,11 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15654
15781
|
} else if (metrics.time_to_first_token === void 0 && chunks.length > 0) {
|
|
15655
15782
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
15656
15783
|
}
|
|
15657
|
-
|
|
15658
|
-
channelName,
|
|
15659
|
-
chunks,
|
|
15660
|
-
config: config3,
|
|
15661
|
-
endEvent: asyncEndEvent,
|
|
15784
|
+
completion2 = {
|
|
15662
15785
|
...metadata !== void 0 ? { metadata } : {},
|
|
15663
15786
|
metrics,
|
|
15664
|
-
output
|
|
15665
|
-
|
|
15666
|
-
span,
|
|
15667
|
-
startTime
|
|
15668
|
-
});
|
|
15787
|
+
output
|
|
15788
|
+
};
|
|
15669
15789
|
span.log({
|
|
15670
15790
|
output,
|
|
15671
15791
|
...metadata !== void 0 ? { metadata } : {},
|
|
@@ -15677,11 +15797,49 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15677
15797
|
error2
|
|
15678
15798
|
);
|
|
15679
15799
|
} finally {
|
|
15680
|
-
|
|
15800
|
+
try {
|
|
15801
|
+
span.end();
|
|
15802
|
+
} catch (error2) {
|
|
15803
|
+
debugLogger.error(
|
|
15804
|
+
`Error ending span for ${channelName}:`,
|
|
15805
|
+
error2
|
|
15806
|
+
);
|
|
15807
|
+
}
|
|
15681
15808
|
states.delete(event);
|
|
15682
15809
|
}
|
|
15810
|
+
if (completion2) {
|
|
15811
|
+
runStreamingCompletionHook({
|
|
15812
|
+
channelName,
|
|
15813
|
+
chunks,
|
|
15814
|
+
config: config3,
|
|
15815
|
+
endEvent: asyncEndEvent,
|
|
15816
|
+
...completion2.metadata !== void 0 ? { metadata: completion2.metadata } : {},
|
|
15817
|
+
metrics: completion2.metrics,
|
|
15818
|
+
output: completion2.output,
|
|
15819
|
+
result: asyncEndEvent.result,
|
|
15820
|
+
span,
|
|
15821
|
+
startTime
|
|
15822
|
+
});
|
|
15823
|
+
}
|
|
15683
15824
|
},
|
|
15684
15825
|
onError: (error2) => {
|
|
15826
|
+
try {
|
|
15827
|
+
span.log({ error: error2 });
|
|
15828
|
+
} catch (loggingError) {
|
|
15829
|
+
debugLogger.error(
|
|
15830
|
+
`Error logging failure for ${channelName}:`,
|
|
15831
|
+
loggingError
|
|
15832
|
+
);
|
|
15833
|
+
}
|
|
15834
|
+
try {
|
|
15835
|
+
span.end();
|
|
15836
|
+
} catch (endingError) {
|
|
15837
|
+
debugLogger.error(
|
|
15838
|
+
`Error ending span for ${channelName}:`,
|
|
15839
|
+
endingError
|
|
15840
|
+
);
|
|
15841
|
+
}
|
|
15842
|
+
states.delete(event);
|
|
15685
15843
|
runStreamingErrorHook({
|
|
15686
15844
|
channelName,
|
|
15687
15845
|
config: config3,
|
|
@@ -15690,11 +15848,6 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15690
15848
|
span,
|
|
15691
15849
|
startTime
|
|
15692
15850
|
});
|
|
15693
|
-
span.log({
|
|
15694
|
-
error: error2.message
|
|
15695
|
-
});
|
|
15696
|
-
span.end();
|
|
15697
|
-
states.delete(event);
|
|
15698
15851
|
}
|
|
15699
15852
|
});
|
|
15700
15853
|
return;
|
|
@@ -15709,6 +15862,7 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15709
15862
|
states.delete(event);
|
|
15710
15863
|
return;
|
|
15711
15864
|
}
|
|
15865
|
+
let completion;
|
|
15712
15866
|
try {
|
|
15713
15867
|
const output = config3.extractOutput(
|
|
15714
15868
|
asyncEndEvent.result,
|
|
@@ -15723,17 +15877,11 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15723
15877
|
asyncEndEvent.result,
|
|
15724
15878
|
asyncEndEvent
|
|
15725
15879
|
);
|
|
15726
|
-
|
|
15727
|
-
channelName,
|
|
15728
|
-
config: config3,
|
|
15729
|
-
endEvent: asyncEndEvent,
|
|
15880
|
+
completion = {
|
|
15730
15881
|
...normalizeMetadata(metadata) !== void 0 ? { metadata: normalizeMetadata(metadata) } : {},
|
|
15731
15882
|
metrics,
|
|
15732
|
-
output
|
|
15733
|
-
|
|
15734
|
-
span,
|
|
15735
|
-
startTime
|
|
15736
|
-
});
|
|
15883
|
+
output
|
|
15884
|
+
};
|
|
15737
15885
|
span.log({
|
|
15738
15886
|
output,
|
|
15739
15887
|
...normalizeMetadata(metadata) !== void 0 ? { metadata: normalizeMetadata(metadata) } : {},
|
|
@@ -15742,12 +15890,30 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15742
15890
|
} catch (error2) {
|
|
15743
15891
|
debugLogger.error(`Error extracting output for ${channelName}:`, error2);
|
|
15744
15892
|
} finally {
|
|
15745
|
-
|
|
15893
|
+
try {
|
|
15894
|
+
span.end();
|
|
15895
|
+
} catch (error2) {
|
|
15896
|
+
debugLogger.error(`Error ending span for ${channelName}:`, error2);
|
|
15897
|
+
}
|
|
15746
15898
|
states.delete(event);
|
|
15747
15899
|
}
|
|
15900
|
+
if (completion) {
|
|
15901
|
+
runStreamingCompletionHook({
|
|
15902
|
+
channelName,
|
|
15903
|
+
config: config3,
|
|
15904
|
+
endEvent: asyncEndEvent,
|
|
15905
|
+
...completion.metadata !== void 0 ? { metadata: completion.metadata } : {},
|
|
15906
|
+
metrics: completion.metrics,
|
|
15907
|
+
output: completion.output,
|
|
15908
|
+
result: asyncEndEvent.result,
|
|
15909
|
+
span,
|
|
15910
|
+
startTime
|
|
15911
|
+
});
|
|
15912
|
+
}
|
|
15748
15913
|
},
|
|
15749
15914
|
error: (event) => {
|
|
15750
15915
|
const spanData = states.get(event);
|
|
15916
|
+
logErrorAndEnd(states, event, channelName);
|
|
15751
15917
|
if (spanData) {
|
|
15752
15918
|
runStreamingErrorHook({
|
|
15753
15919
|
channelName,
|
|
@@ -15758,7 +15924,6 @@ function traceStreamingChannel(channel2, config3) {
|
|
|
15758
15924
|
startTime: spanData.startTime
|
|
15759
15925
|
});
|
|
15760
15926
|
}
|
|
15761
|
-
logErrorAndEnd(states, event);
|
|
15762
15927
|
}
|
|
15763
15928
|
};
|
|
15764
15929
|
tracingChannel2.subscribe(handlers);
|
|
@@ -15775,7 +15940,8 @@ function traceSyncStreamChannel(channel2, config3) {
|
|
|
15775
15940
|
tracingChannel2,
|
|
15776
15941
|
states,
|
|
15777
15942
|
config3,
|
|
15778
|
-
channelName
|
|
15943
|
+
channelName,
|
|
15944
|
+
channel2.instrumentationName
|
|
15779
15945
|
);
|
|
15780
15946
|
const handlers = {
|
|
15781
15947
|
start: (event) => {
|
|
@@ -15786,7 +15952,8 @@ function traceSyncStreamChannel(channel2, config3) {
|
|
|
15786
15952
|
states,
|
|
15787
15953
|
config3,
|
|
15788
15954
|
event,
|
|
15789
|
-
channelName
|
|
15955
|
+
channelName,
|
|
15956
|
+
channel2.instrumentationName
|
|
15790
15957
|
);
|
|
15791
15958
|
},
|
|
15792
15959
|
end: (event) => {
|
|
@@ -15880,7 +16047,7 @@ function traceSyncStreamChannel(channel2, config3) {
|
|
|
15880
16047
|
handleResolvedResult(endEvent.result);
|
|
15881
16048
|
},
|
|
15882
16049
|
error: (event) => {
|
|
15883
|
-
logErrorAndEnd(states, event);
|
|
16050
|
+
logErrorAndEnd(states, event, channelName);
|
|
15884
16051
|
}
|
|
15885
16052
|
};
|
|
15886
16053
|
tracingChannel2.subscribe(handlers);
|
|
@@ -16059,7 +16226,8 @@ function processInputAttachments(input) {
|
|
|
16059
16226
|
function channel(spec) {
|
|
16060
16227
|
return spec;
|
|
16061
16228
|
}
|
|
16062
|
-
function defineChannels(pkg, channels) {
|
|
16229
|
+
function defineChannels(pkg, channels, options) {
|
|
16230
|
+
const { instrumentationName } = options;
|
|
16063
16231
|
return Object.fromEntries(
|
|
16064
16232
|
Object.entries(channels).map(([key, spec]) => {
|
|
16065
16233
|
const fullChannelName = `orchestrion:${pkg}:${spec.channelName}`;
|
|
@@ -16072,6 +16240,7 @@ function defineChannels(pkg, channels) {
|
|
|
16072
16240
|
key,
|
|
16073
16241
|
{
|
|
16074
16242
|
...asyncSpec,
|
|
16243
|
+
instrumentationName,
|
|
16075
16244
|
tracingChannel: tracingChannel3,
|
|
16076
16245
|
tracePromise: (fn, context2) => tracingChannel3().tracePromise(
|
|
16077
16246
|
fn,
|
|
@@ -16089,6 +16258,7 @@ function defineChannels(pkg, channels) {
|
|
|
16089
16258
|
key,
|
|
16090
16259
|
{
|
|
16091
16260
|
...syncSpec,
|
|
16261
|
+
instrumentationName,
|
|
16092
16262
|
tracingChannel: tracingChannel2,
|
|
16093
16263
|
traceSync: (fn, context2) => tracingChannel2().traceSync(
|
|
16094
16264
|
fn,
|
|
@@ -16102,44 +16272,48 @@ function defineChannels(pkg, channels) {
|
|
|
16102
16272
|
}
|
|
16103
16273
|
|
|
16104
16274
|
// src/instrumentation/plugins/openai-channels.ts
|
|
16105
|
-
var openAIChannels = defineChannels(
|
|
16106
|
-
|
|
16107
|
-
|
|
16108
|
-
|
|
16109
|
-
|
|
16110
|
-
|
|
16111
|
-
|
|
16112
|
-
|
|
16113
|
-
|
|
16114
|
-
|
|
16115
|
-
|
|
16116
|
-
|
|
16117
|
-
|
|
16118
|
-
|
|
16119
|
-
|
|
16120
|
-
|
|
16121
|
-
|
|
16122
|
-
|
|
16123
|
-
|
|
16124
|
-
|
|
16125
|
-
|
|
16126
|
-
|
|
16127
|
-
|
|
16128
|
-
|
|
16129
|
-
|
|
16130
|
-
|
|
16131
|
-
|
|
16132
|
-
|
|
16133
|
-
|
|
16134
|
-
|
|
16135
|
-
|
|
16136
|
-
|
|
16137
|
-
|
|
16138
|
-
|
|
16139
|
-
|
|
16140
|
-
|
|
16141
|
-
|
|
16142
|
-
|
|
16275
|
+
var openAIChannels = defineChannels(
|
|
16276
|
+
"openai",
|
|
16277
|
+
{
|
|
16278
|
+
chatCompletionsCreate: channel({
|
|
16279
|
+
channelName: "chat.completions.create",
|
|
16280
|
+
kind: "async"
|
|
16281
|
+
}),
|
|
16282
|
+
embeddingsCreate: channel({
|
|
16283
|
+
channelName: "embeddings.create",
|
|
16284
|
+
kind: "async"
|
|
16285
|
+
}),
|
|
16286
|
+
betaChatCompletionsParse: channel({
|
|
16287
|
+
channelName: "beta.chat.completions.parse",
|
|
16288
|
+
kind: "async"
|
|
16289
|
+
}),
|
|
16290
|
+
betaChatCompletionsStream: channel({
|
|
16291
|
+
channelName: "beta.chat.completions.stream",
|
|
16292
|
+
kind: "sync-stream"
|
|
16293
|
+
}),
|
|
16294
|
+
moderationsCreate: channel({
|
|
16295
|
+
channelName: "moderations.create",
|
|
16296
|
+
kind: "async"
|
|
16297
|
+
}),
|
|
16298
|
+
responsesCreate: channel({
|
|
16299
|
+
channelName: "responses.create",
|
|
16300
|
+
kind: "async"
|
|
16301
|
+
}),
|
|
16302
|
+
responsesStream: channel({
|
|
16303
|
+
channelName: "responses.stream",
|
|
16304
|
+
kind: "sync-stream"
|
|
16305
|
+
}),
|
|
16306
|
+
responsesParse: channel({
|
|
16307
|
+
channelName: "responses.parse",
|
|
16308
|
+
kind: "async"
|
|
16309
|
+
}),
|
|
16310
|
+
responsesCompact: channel({
|
|
16311
|
+
channelName: "responses.compact",
|
|
16312
|
+
kind: "async"
|
|
16313
|
+
})
|
|
16314
|
+
},
|
|
16315
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OPENAI }
|
|
16316
|
+
);
|
|
16143
16317
|
|
|
16144
16318
|
// src/openai-utils.ts
|
|
16145
16319
|
var BRAINTRUST_CACHED_STREAM_METRIC = "__braintrust_cached_metric";
|
|
@@ -16654,16 +16828,20 @@ function aggregateResponseStreamEvents(chunks, _streamResult, endEvent) {
|
|
|
16654
16828
|
}
|
|
16655
16829
|
|
|
16656
16830
|
// src/instrumentation/plugins/openai-codex-channels.ts
|
|
16657
|
-
var openAICodexChannels = defineChannels(
|
|
16658
|
-
|
|
16659
|
-
|
|
16660
|
-
|
|
16661
|
-
|
|
16662
|
-
|
|
16663
|
-
|
|
16664
|
-
|
|
16665
|
-
|
|
16666
|
-
|
|
16831
|
+
var openAICodexChannels = defineChannels(
|
|
16832
|
+
"@openai/codex-sdk",
|
|
16833
|
+
{
|
|
16834
|
+
run: channel({
|
|
16835
|
+
channelName: "Thread.run",
|
|
16836
|
+
kind: "async"
|
|
16837
|
+
}),
|
|
16838
|
+
runStreamed: channel({
|
|
16839
|
+
channelName: "Thread.runStreamed",
|
|
16840
|
+
kind: "async"
|
|
16841
|
+
})
|
|
16842
|
+
},
|
|
16843
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OPENAI_CODEX }
|
|
16844
|
+
);
|
|
16667
16845
|
|
|
16668
16846
|
// src/instrumentation/plugins/openai-codex-plugin.ts
|
|
16669
16847
|
var PATCHED_STREAMED_TURN = /* @__PURE__ */ Symbol.for(
|
|
@@ -16751,10 +16929,15 @@ function startCodexRun(event, operation) {
|
|
|
16751
16929
|
provider: "openai",
|
|
16752
16930
|
...event.moduleVersion ? { "openai_codex.version": event.moduleVersion } : {}
|
|
16753
16931
|
};
|
|
16754
|
-
const span = startSpan(
|
|
16755
|
-
|
|
16756
|
-
|
|
16757
|
-
|
|
16932
|
+
const span = startSpan(
|
|
16933
|
+
withSpanInstrumentationName(
|
|
16934
|
+
{
|
|
16935
|
+
name: "OpenAI Codex",
|
|
16936
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
16937
|
+
},
|
|
16938
|
+
INSTRUMENTATION_NAMES.OPENAI_CODEX
|
|
16939
|
+
)
|
|
16940
|
+
);
|
|
16758
16941
|
const startTime = getCurrentUnixTimestamp();
|
|
16759
16942
|
safeLog(span, {
|
|
16760
16943
|
input: sanitizedInput,
|
|
@@ -16903,7 +17086,12 @@ async function createCompletedItemSpan(state, item) {
|
|
|
16903
17086
|
if (!spanArgs) {
|
|
16904
17087
|
return;
|
|
16905
17088
|
}
|
|
16906
|
-
const span = startSpan(
|
|
17089
|
+
const span = startSpan(
|
|
17090
|
+
withSpanInstrumentationName(
|
|
17091
|
+
spanArgs.start,
|
|
17092
|
+
INSTRUMENTATION_NAMES.OPENAI_CODEX
|
|
17093
|
+
)
|
|
17094
|
+
);
|
|
16907
17095
|
safeLog(span, spanArgs.end);
|
|
16908
17096
|
span.end();
|
|
16909
17097
|
}
|
|
@@ -16945,15 +17133,20 @@ async function ensureActiveLlmSpan(state) {
|
|
|
16945
17133
|
...state.metadata["openai_codex.thread_id"] ? { "openai_codex.thread_id": state.metadata["openai_codex.thread_id"] } : {},
|
|
16946
17134
|
"openai_codex.llm_sequence": sequence
|
|
16947
17135
|
};
|
|
16948
|
-
const span = startSpan(
|
|
16949
|
-
|
|
16950
|
-
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16954
|
-
|
|
16955
|
-
|
|
16956
|
-
|
|
17136
|
+
const span = startSpan(
|
|
17137
|
+
withSpanInstrumentationName(
|
|
17138
|
+
{
|
|
17139
|
+
event: {
|
|
17140
|
+
...sequence === 1 ? { input: state.input } : {},
|
|
17141
|
+
metadata
|
|
17142
|
+
},
|
|
17143
|
+
name: "OpenAI Codex LLM",
|
|
17144
|
+
parent: await state.span.export(),
|
|
17145
|
+
spanAttributes: { type: "llm" /* LLM */ }
|
|
17146
|
+
},
|
|
17147
|
+
INSTRUMENTATION_NAMES.OPENAI_CODEX
|
|
17148
|
+
)
|
|
17149
|
+
);
|
|
16957
17150
|
state.activeLlmSpan = {
|
|
16958
17151
|
anonymousMessages: [],
|
|
16959
17152
|
anonymousReasoning: [],
|
|
@@ -16999,7 +17192,15 @@ async function startCodexItemSpan(state, item) {
|
|
|
16999
17192
|
if (!spanArgs) {
|
|
17000
17193
|
return;
|
|
17001
17194
|
}
|
|
17002
|
-
state.activeItemSpans.set(
|
|
17195
|
+
state.activeItemSpans.set(
|
|
17196
|
+
itemId,
|
|
17197
|
+
startSpan(
|
|
17198
|
+
withSpanInstrumentationName(
|
|
17199
|
+
spanArgs.start,
|
|
17200
|
+
INSTRUMENTATION_NAMES.OPENAI_CODEX
|
|
17201
|
+
)
|
|
17202
|
+
)
|
|
17203
|
+
);
|
|
17003
17204
|
}
|
|
17004
17205
|
function updateCodexItem(state, item) {
|
|
17005
17206
|
if (item.type === "agent_message" && typeof item.text === "string") {
|
|
@@ -17309,20 +17510,24 @@ function extractAnthropicCacheTokens(cacheReadTokens = 0, cacheCreationTokens =
|
|
|
17309
17510
|
}
|
|
17310
17511
|
|
|
17311
17512
|
// src/instrumentation/plugins/anthropic-channels.ts
|
|
17312
|
-
var anthropicChannels = defineChannels(
|
|
17313
|
-
|
|
17314
|
-
|
|
17315
|
-
|
|
17316
|
-
|
|
17317
|
-
|
|
17318
|
-
|
|
17319
|
-
|
|
17320
|
-
|
|
17321
|
-
|
|
17322
|
-
|
|
17323
|
-
|
|
17324
|
-
|
|
17325
|
-
|
|
17513
|
+
var anthropicChannels = defineChannels(
|
|
17514
|
+
"@anthropic-ai/sdk",
|
|
17515
|
+
{
|
|
17516
|
+
messagesCreate: channel({
|
|
17517
|
+
channelName: "messages.create",
|
|
17518
|
+
kind: "async"
|
|
17519
|
+
}),
|
|
17520
|
+
betaMessagesCreate: channel({
|
|
17521
|
+
channelName: "beta.messages.create",
|
|
17522
|
+
kind: "async"
|
|
17523
|
+
}),
|
|
17524
|
+
betaMessagesToolRunner: channel({
|
|
17525
|
+
channelName: "beta.messages.toolRunner",
|
|
17526
|
+
kind: "sync-stream"
|
|
17527
|
+
})
|
|
17528
|
+
},
|
|
17529
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
|
|
17530
|
+
);
|
|
17326
17531
|
|
|
17327
17532
|
// src/instrumentation/plugins/anthropic-plugin.ts
|
|
17328
17533
|
var ANTHROPIC_TOOL_RUNNER_TOOL_WRAPPED = /* @__PURE__ */ Symbol.for(
|
|
@@ -17395,12 +17600,17 @@ var AnthropicPlugin = class extends BasePlugin {
|
|
|
17395
17600
|
return;
|
|
17396
17601
|
}
|
|
17397
17602
|
const params = event.arguments[0] ?? {};
|
|
17398
|
-
const span = startSpan(
|
|
17399
|
-
|
|
17400
|
-
|
|
17401
|
-
|
|
17402
|
-
|
|
17403
|
-
|
|
17603
|
+
const span = startSpan(
|
|
17604
|
+
withSpanInstrumentationName(
|
|
17605
|
+
{
|
|
17606
|
+
name: "anthropic.beta.messages.toolRunner",
|
|
17607
|
+
spanAttributes: {
|
|
17608
|
+
type: "task" /* TASK */
|
|
17609
|
+
}
|
|
17610
|
+
},
|
|
17611
|
+
INSTRUMENTATION_NAMES.ANTHROPIC
|
|
17612
|
+
)
|
|
17613
|
+
);
|
|
17404
17614
|
span.log({
|
|
17405
17615
|
input: processAttachmentsInInput(
|
|
17406
17616
|
coalesceInput(params.messages ?? [], params.system)
|
|
@@ -17541,19 +17751,22 @@ function wrapAnthropicToolRunnerTool(tool, index, state) {
|
|
|
17541
17751
|
return finalizeError(error2);
|
|
17542
17752
|
}
|
|
17543
17753
|
},
|
|
17544
|
-
|
|
17545
|
-
|
|
17546
|
-
|
|
17547
|
-
|
|
17548
|
-
|
|
17549
|
-
|
|
17754
|
+
withSpanInstrumentationName(
|
|
17755
|
+
{
|
|
17756
|
+
event: {
|
|
17757
|
+
input: getAnthropicToolRunnerInput(args),
|
|
17758
|
+
metadata: {
|
|
17759
|
+
"gen_ai.tool.name": toolName,
|
|
17760
|
+
provider: "anthropic"
|
|
17761
|
+
}
|
|
17762
|
+
},
|
|
17763
|
+
name: `tool: ${toolName}`,
|
|
17764
|
+
spanAttributes: {
|
|
17765
|
+
type: "tool" /* TOOL */
|
|
17550
17766
|
}
|
|
17551
17767
|
},
|
|
17552
|
-
|
|
17553
|
-
|
|
17554
|
-
type: "tool" /* TOOL */
|
|
17555
|
-
}
|
|
17556
|
-
}
|
|
17768
|
+
INSTRUMENTATION_NAMES.ANTHROPIC
|
|
17769
|
+
)
|
|
17557
17770
|
);
|
|
17558
17771
|
},
|
|
17559
17772
|
writable: runDescriptor?.writable ?? true
|
|
@@ -18148,6 +18361,267 @@ function currentWorkflowAgentWrapperSpan() {
|
|
|
18148
18361
|
return void 0;
|
|
18149
18362
|
}
|
|
18150
18363
|
|
|
18364
|
+
// src/wrappers/ai-sdk/harness-agent-context.ts
|
|
18365
|
+
var BRAINTRUST_TURN_CONTEXT_KEY = "__braintrust_trace_context";
|
|
18366
|
+
var sessionTurnParents = /* @__PURE__ */ new WeakMap();
|
|
18367
|
+
var wrapperTurnParents = /* @__PURE__ */ new WeakMap();
|
|
18368
|
+
var patchedLifecycleMethods = /* @__PURE__ */ new WeakMap();
|
|
18369
|
+
var harnessTurnParentStore;
|
|
18370
|
+
function serializedTurnContext(value) {
|
|
18371
|
+
if (!isObject(value)) {
|
|
18372
|
+
return void 0;
|
|
18373
|
+
}
|
|
18374
|
+
const context2 = value[BRAINTRUST_TURN_CONTEXT_KEY];
|
|
18375
|
+
if (!isObject(context2) || typeof context2.parent !== "string" || typeof context2.sessionId !== "string" || typeof context2.signature !== "string") {
|
|
18376
|
+
return void 0;
|
|
18377
|
+
}
|
|
18378
|
+
const expectedSignature = signTurnContext({
|
|
18379
|
+
parent: context2.parent,
|
|
18380
|
+
sessionId: context2.sessionId
|
|
18381
|
+
});
|
|
18382
|
+
if (!expectedSignature || !isomorph_default.timingSafeEqual?.(context2.signature, expectedSignature)) {
|
|
18383
|
+
return void 0;
|
|
18384
|
+
}
|
|
18385
|
+
const parent = SpanComponentsV4.fromStr(context2.parent);
|
|
18386
|
+
if (!parent.data.row_id || !parent.data.root_span_id || !parent.data.span_id) {
|
|
18387
|
+
return void 0;
|
|
18388
|
+
}
|
|
18389
|
+
return {
|
|
18390
|
+
parent: context2.parent,
|
|
18391
|
+
sessionId: context2.sessionId
|
|
18392
|
+
};
|
|
18393
|
+
}
|
|
18394
|
+
function signTurnContext(context2) {
|
|
18395
|
+
const secret = _internalGetGlobalState()._internalGetTraceContextSigningSecret();
|
|
18396
|
+
return secret ? isomorph_default.hmacSha256?.(
|
|
18397
|
+
secret,
|
|
18398
|
+
JSON.stringify([BRAINTRUST_TURN_CONTEXT_KEY, context2])
|
|
18399
|
+
) : void 0;
|
|
18400
|
+
}
|
|
18401
|
+
function continuationParentFromCreateSessionParams(params) {
|
|
18402
|
+
if (!isObject(params)) {
|
|
18403
|
+
return void 0;
|
|
18404
|
+
}
|
|
18405
|
+
const continuation = params.continueFrom ?? (isObject(params.resumeFrom) ? params.resumeFrom.continueFrom : void 0);
|
|
18406
|
+
const context2 = serializedTurnContext(continuation);
|
|
18407
|
+
if (!context2) {
|
|
18408
|
+
return void 0;
|
|
18409
|
+
}
|
|
18410
|
+
if (params.sessionId !== context2.sessionId) {
|
|
18411
|
+
return void 0;
|
|
18412
|
+
}
|
|
18413
|
+
return context2.parent;
|
|
18414
|
+
}
|
|
18415
|
+
function exportSpanSynchronously(span) {
|
|
18416
|
+
const parentInfo = span.getParentInfo();
|
|
18417
|
+
if (!parentInfo) {
|
|
18418
|
+
return void 0;
|
|
18419
|
+
}
|
|
18420
|
+
const objectId = parentInfo.objectId.getSync().value;
|
|
18421
|
+
if (!objectId && !parentInfo.computeObjectMetadataArgs) {
|
|
18422
|
+
return void 0;
|
|
18423
|
+
}
|
|
18424
|
+
return new SpanComponentsV4({
|
|
18425
|
+
object_type: parentInfo.objectType,
|
|
18426
|
+
...objectId ? { object_id: objectId } : {
|
|
18427
|
+
compute_object_metadata_args: parentInfo.computeObjectMetadataArgs ?? {}
|
|
18428
|
+
},
|
|
18429
|
+
row_id: span.id,
|
|
18430
|
+
root_span_id: span.rootSpanId,
|
|
18431
|
+
span_id: span.spanId
|
|
18432
|
+
}).toStr();
|
|
18433
|
+
}
|
|
18434
|
+
function exportedParent(parent) {
|
|
18435
|
+
return typeof parent === "string" ? parent : exportSpanSynchronously(parent);
|
|
18436
|
+
}
|
|
18437
|
+
function addSerializedContext(args) {
|
|
18438
|
+
if (!isObject(args.continuation) || args.sessionId === void 0) {
|
|
18439
|
+
return;
|
|
18440
|
+
}
|
|
18441
|
+
const parent = exportedParent(args.parent);
|
|
18442
|
+
if (!parent) {
|
|
18443
|
+
return;
|
|
18444
|
+
}
|
|
18445
|
+
const context2 = {
|
|
18446
|
+
parent,
|
|
18447
|
+
sessionId: args.sessionId
|
|
18448
|
+
};
|
|
18449
|
+
const signature = signTurnContext(context2);
|
|
18450
|
+
if (!signature) {
|
|
18451
|
+
return;
|
|
18452
|
+
}
|
|
18453
|
+
Object.defineProperty(args.continuation, BRAINTRUST_TURN_CONTEXT_KEY, {
|
|
18454
|
+
configurable: true,
|
|
18455
|
+
enumerable: true,
|
|
18456
|
+
value: {
|
|
18457
|
+
...context2,
|
|
18458
|
+
signature
|
|
18459
|
+
},
|
|
18460
|
+
writable: true
|
|
18461
|
+
});
|
|
18462
|
+
}
|
|
18463
|
+
function lifecycleMethodDescriptor(session, method) {
|
|
18464
|
+
let owner = session;
|
|
18465
|
+
while (owner) {
|
|
18466
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, method);
|
|
18467
|
+
if (descriptor) {
|
|
18468
|
+
return { descriptor, owner };
|
|
18469
|
+
}
|
|
18470
|
+
owner = Object.getPrototypeOf(owner);
|
|
18471
|
+
}
|
|
18472
|
+
return void 0;
|
|
18473
|
+
}
|
|
18474
|
+
function patchLifecycleMethod(session, method) {
|
|
18475
|
+
let resolvedDescriptor;
|
|
18476
|
+
try {
|
|
18477
|
+
resolvedDescriptor = lifecycleMethodDescriptor(session, method);
|
|
18478
|
+
} catch {
|
|
18479
|
+
return;
|
|
18480
|
+
}
|
|
18481
|
+
if (!resolvedDescriptor || !("value" in resolvedDescriptor.descriptor) || typeof resolvedDescriptor.descriptor.value !== "function") {
|
|
18482
|
+
return;
|
|
18483
|
+
}
|
|
18484
|
+
const { descriptor, owner } = resolvedDescriptor;
|
|
18485
|
+
const patched = patchedLifecycleMethods.get(owner);
|
|
18486
|
+
if (patched?.has(method)) {
|
|
18487
|
+
return;
|
|
18488
|
+
}
|
|
18489
|
+
const original = descriptor.value;
|
|
18490
|
+
const replacement = function(...args) {
|
|
18491
|
+
const result = Reflect.apply(original, this, args);
|
|
18492
|
+
const addContext = (state) => {
|
|
18493
|
+
try {
|
|
18494
|
+
const parent = sessionTurnParents.get(this);
|
|
18495
|
+
if (!parent) {
|
|
18496
|
+
return;
|
|
18497
|
+
}
|
|
18498
|
+
const continuation = method === "suspendTurn" ? state : isObject(state) ? state.continueFrom : void 0;
|
|
18499
|
+
addSerializedContext({
|
|
18500
|
+
continuation,
|
|
18501
|
+
parent,
|
|
18502
|
+
sessionId: typeof this.sessionId === "string" ? this.sessionId : void 0
|
|
18503
|
+
});
|
|
18504
|
+
} catch {
|
|
18505
|
+
}
|
|
18506
|
+
};
|
|
18507
|
+
try {
|
|
18508
|
+
if (isObject(result) && typeof result.then === "function") {
|
|
18509
|
+
void Promise.resolve(result).then(addContext, () => {
|
|
18510
|
+
});
|
|
18511
|
+
} else {
|
|
18512
|
+
addContext(result);
|
|
18513
|
+
}
|
|
18514
|
+
} catch {
|
|
18515
|
+
}
|
|
18516
|
+
return result;
|
|
18517
|
+
};
|
|
18518
|
+
try {
|
|
18519
|
+
Object.defineProperty(owner, method, {
|
|
18520
|
+
...descriptor,
|
|
18521
|
+
value: replacement
|
|
18522
|
+
});
|
|
18523
|
+
const ownerMethods = patched ?? /* @__PURE__ */ new Set();
|
|
18524
|
+
ownerMethods.add(method);
|
|
18525
|
+
if (!patched) {
|
|
18526
|
+
patchedLifecycleMethods.set(owner, ownerMethods);
|
|
18527
|
+
}
|
|
18528
|
+
} catch {
|
|
18529
|
+
}
|
|
18530
|
+
}
|
|
18531
|
+
function patchLifecycleMethods(session) {
|
|
18532
|
+
patchLifecycleMethod(session, "suspendTurn");
|
|
18533
|
+
patchLifecycleMethod(session, "detach");
|
|
18534
|
+
patchLifecycleMethod(session, "stop");
|
|
18535
|
+
}
|
|
18536
|
+
function registerHarnessTurnSpan(args) {
|
|
18537
|
+
if (!isObject(args.session)) {
|
|
18538
|
+
return;
|
|
18539
|
+
}
|
|
18540
|
+
const session = args.session;
|
|
18541
|
+
sessionTurnParents.set(session, args.span);
|
|
18542
|
+
wrapperTurnParents.set(args.span, args.span);
|
|
18543
|
+
patchLifecycleMethods(session);
|
|
18544
|
+
}
|
|
18545
|
+
function harnessContinuationParent(session) {
|
|
18546
|
+
return isObject(session) ? sessionTurnParents.get(session) : void 0;
|
|
18547
|
+
}
|
|
18548
|
+
function captureHarnessCreateSessionParent(params) {
|
|
18549
|
+
try {
|
|
18550
|
+
return continuationParentFromCreateSessionParams(params);
|
|
18551
|
+
} catch {
|
|
18552
|
+
return void 0;
|
|
18553
|
+
}
|
|
18554
|
+
}
|
|
18555
|
+
function registerHarnessSessionParent(session, parent) {
|
|
18556
|
+
if (!parent || !isObject(session)) {
|
|
18557
|
+
return;
|
|
18558
|
+
}
|
|
18559
|
+
const harnessSession = session;
|
|
18560
|
+
sessionTurnParents.set(harnessSession, parent);
|
|
18561
|
+
patchLifecycleMethods(harnessSession);
|
|
18562
|
+
}
|
|
18563
|
+
function currentHarnessTurnParent() {
|
|
18564
|
+
return harnessTurnParentStore?.getStore() ?? wrapperTurnParents.get(currentSpan());
|
|
18565
|
+
}
|
|
18566
|
+
function bindHarnessTurnParentToStart(tracingChannel2, parentFromEvent) {
|
|
18567
|
+
const startChannel = tracingChannel2.start;
|
|
18568
|
+
if (!startChannel) {
|
|
18569
|
+
return () => {
|
|
18570
|
+
};
|
|
18571
|
+
}
|
|
18572
|
+
harnessTurnParentStore ??= isomorph_default.newAsyncLocalStorage();
|
|
18573
|
+
const store = harnessTurnParentStore;
|
|
18574
|
+
startChannel.bindStore(
|
|
18575
|
+
store,
|
|
18576
|
+
(event) => parentFromEvent(event) ?? store.getStore()
|
|
18577
|
+
);
|
|
18578
|
+
return () => {
|
|
18579
|
+
startChannel.unbindStore(store);
|
|
18580
|
+
};
|
|
18581
|
+
}
|
|
18582
|
+
function startHarnessTurnChildSpan(parent, args) {
|
|
18583
|
+
const spanArgs = withSpanInstrumentationName(
|
|
18584
|
+
args,
|
|
18585
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
18586
|
+
);
|
|
18587
|
+
return typeof parent === "string" ? startSpan({ ...spanArgs, parent }) : parent.startSpan(spanArgs);
|
|
18588
|
+
}
|
|
18589
|
+
function updateHarnessTurn(parent, update = {}) {
|
|
18590
|
+
if (!parent) {
|
|
18591
|
+
return;
|
|
18592
|
+
}
|
|
18593
|
+
const log2 = (event) => {
|
|
18594
|
+
if (typeof parent === "string") {
|
|
18595
|
+
updateSpan({ exported: parent, ...event });
|
|
18596
|
+
} else {
|
|
18597
|
+
parent.log(event);
|
|
18598
|
+
}
|
|
18599
|
+
};
|
|
18600
|
+
try {
|
|
18601
|
+
if (Object.prototype.hasOwnProperty.call(update, "output")) {
|
|
18602
|
+
log2({ output: null });
|
|
18603
|
+
}
|
|
18604
|
+
log2(update);
|
|
18605
|
+
} catch {
|
|
18606
|
+
}
|
|
18607
|
+
}
|
|
18608
|
+
function endHarnessTurn(parent) {
|
|
18609
|
+
const endTime = getCurrentUnixTimestamp();
|
|
18610
|
+
if (!parent) {
|
|
18611
|
+
return endTime;
|
|
18612
|
+
}
|
|
18613
|
+
try {
|
|
18614
|
+
const event = { metrics: { end: endTime } };
|
|
18615
|
+
if (typeof parent === "string") {
|
|
18616
|
+
updateSpan({ exported: parent, ...event });
|
|
18617
|
+
} else {
|
|
18618
|
+
parent.log(event);
|
|
18619
|
+
}
|
|
18620
|
+
} catch {
|
|
18621
|
+
}
|
|
18622
|
+
return endTime;
|
|
18623
|
+
}
|
|
18624
|
+
|
|
18151
18625
|
// src/wrappers/ai-sdk/telemetry.ts
|
|
18152
18626
|
function braintrustAISDKTelemetry() {
|
|
18153
18627
|
const operations = /* @__PURE__ */ new Map();
|
|
@@ -18166,14 +18640,17 @@ function braintrustAISDKTelemetry() {
|
|
|
18166
18640
|
console.error(`Error in Braintrust AI SDK telemetry ${name}:`, error2);
|
|
18167
18641
|
}
|
|
18168
18642
|
};
|
|
18169
|
-
const startChildSpan = (operationKey, name, type, event) => {
|
|
18643
|
+
const startChildSpan = (operationKey, name, type, event, parentOverride) => {
|
|
18170
18644
|
const parent = operations.get(operationKey)?.span;
|
|
18171
|
-
const spanArgs =
|
|
18172
|
-
|
|
18173
|
-
|
|
18174
|
-
|
|
18175
|
-
|
|
18176
|
-
|
|
18645
|
+
const spanArgs = withSpanInstrumentationName(
|
|
18646
|
+
{
|
|
18647
|
+
name,
|
|
18648
|
+
spanAttributes: { type },
|
|
18649
|
+
...event ? { event } : {}
|
|
18650
|
+
},
|
|
18651
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
18652
|
+
);
|
|
18653
|
+
const span = parentOverride ? startHarnessTurnChildSpan(parentOverride, spanArgs) : parent ? parent.startSpan(spanArgs) : startSpan(spanArgs);
|
|
18177
18654
|
const state = operations.get(operationKey);
|
|
18178
18655
|
if (state && type === "llm" /* LLM */) {
|
|
18179
18656
|
state.hadModelChild = true;
|
|
@@ -18453,14 +18930,30 @@ function braintrustAISDKTelemetry() {
|
|
|
18453
18930
|
const workflowAgent = operationName === "WorkflowAgent.stream";
|
|
18454
18931
|
const wrapperSpan = workflowAgent ? currentWorkflowAgentWrapperSpan() : void 0;
|
|
18455
18932
|
const ownsSpan = !wrapperSpan;
|
|
18456
|
-
const
|
|
18457
|
-
|
|
18458
|
-
|
|
18459
|
-
|
|
18933
|
+
const harnessTurnParent = currentHarnessTurnParent();
|
|
18934
|
+
const span = ownsSpan ? harnessTurnParent ? startHarnessTurnChildSpan(
|
|
18935
|
+
harnessTurnParent,
|
|
18936
|
+
withSpanInstrumentationName(
|
|
18937
|
+
{
|
|
18938
|
+
name: operationName,
|
|
18939
|
+
spanAttributes: { type: "function" /* FUNCTION */ }
|
|
18940
|
+
},
|
|
18941
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
18942
|
+
)
|
|
18943
|
+
) : startSpan(
|
|
18944
|
+
withSpanInstrumentationName(
|
|
18945
|
+
{
|
|
18946
|
+
name: operationName,
|
|
18947
|
+
spanAttributes: { type: "function" /* FUNCTION */ }
|
|
18948
|
+
},
|
|
18949
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
18950
|
+
)
|
|
18951
|
+
) : wrapperSpan;
|
|
18460
18952
|
const operationKey = createOperationKey(event, operationName);
|
|
18461
18953
|
registerOperation({
|
|
18462
18954
|
callId: event.callId,
|
|
18463
18955
|
hadModelChild: false,
|
|
18956
|
+
harnessTurnParent,
|
|
18464
18957
|
loggedInput: false,
|
|
18465
18958
|
operationName,
|
|
18466
18959
|
operationKey,
|
|
@@ -18701,7 +19194,8 @@ function braintrustAISDKTelemetry() {
|
|
|
18701
19194
|
toolCallId,
|
|
18702
19195
|
...typeof event.toolCall.toolName === "string" ? { toolName: event.toolCall.toolName } : {}
|
|
18703
19196
|
}
|
|
18704
|
-
}
|
|
19197
|
+
},
|
|
19198
|
+
state?.harnessTurnParent
|
|
18705
19199
|
);
|
|
18706
19200
|
toolSpans.set(toolCallId, { operationKey, span });
|
|
18707
19201
|
});
|
|
@@ -18937,92 +19431,102 @@ function finishOutput(result, operationName) {
|
|
|
18937
19431
|
}
|
|
18938
19432
|
|
|
18939
19433
|
// src/instrumentation/plugins/ai-sdk-channels.ts
|
|
18940
|
-
var aiSDKChannels = defineChannels(
|
|
18941
|
-
|
|
18942
|
-
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
18966
|
-
|
|
19434
|
+
var aiSDKChannels = defineChannels(
|
|
19435
|
+
"ai",
|
|
19436
|
+
{
|
|
19437
|
+
generateText: channel({
|
|
19438
|
+
channelName: "generateText",
|
|
19439
|
+
kind: "async"
|
|
19440
|
+
}),
|
|
19441
|
+
streamText: channel({
|
|
19442
|
+
channelName: "streamText",
|
|
19443
|
+
kind: "async"
|
|
19444
|
+
}),
|
|
19445
|
+
streamTextSync: channel({
|
|
19446
|
+
channelName: "streamText.sync",
|
|
19447
|
+
kind: "sync-stream"
|
|
19448
|
+
}),
|
|
19449
|
+
generateObject: channel({
|
|
19450
|
+
channelName: "generateObject",
|
|
19451
|
+
kind: "async"
|
|
19452
|
+
}),
|
|
19453
|
+
streamObject: channel({
|
|
19454
|
+
channelName: "streamObject",
|
|
19455
|
+
kind: "async"
|
|
19456
|
+
}),
|
|
19457
|
+
streamObjectSync: channel({
|
|
19458
|
+
channelName: "streamObject.sync",
|
|
19459
|
+
kind: "sync-stream"
|
|
19460
|
+
}),
|
|
19461
|
+
embed: channel({
|
|
18967
19462
|
channelName: "embed",
|
|
18968
19463
|
kind: "async"
|
|
18969
|
-
}
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
|
|
18974
|
-
|
|
18975
|
-
|
|
18976
|
-
|
|
18977
|
-
|
|
18978
|
-
|
|
18979
|
-
|
|
18980
|
-
|
|
18981
|
-
|
|
18982
|
-
|
|
18983
|
-
|
|
18984
|
-
|
|
18985
|
-
|
|
18986
|
-
|
|
18987
|
-
|
|
18988
|
-
|
|
18989
|
-
|
|
18990
|
-
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
|
|
18995
|
-
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
|
|
19002
|
-
|
|
19003
|
-
|
|
19004
|
-
|
|
19005
|
-
|
|
19006
|
-
}
|
|
19007
|
-
}
|
|
19008
|
-
|
|
19009
|
-
|
|
19010
|
-
|
|
19011
|
-
|
|
19012
|
-
|
|
19013
|
-
|
|
19014
|
-
|
|
19015
|
-
|
|
19016
|
-
|
|
19017
|
-
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19024
|
-
|
|
19025
|
-
|
|
19464
|
+
}),
|
|
19465
|
+
embedMany: channel({
|
|
19466
|
+
channelName: "embedMany",
|
|
19467
|
+
kind: "async"
|
|
19468
|
+
}),
|
|
19469
|
+
rerank: channel({
|
|
19470
|
+
channelName: "rerank",
|
|
19471
|
+
kind: "async"
|
|
19472
|
+
}),
|
|
19473
|
+
agentGenerate: channel({
|
|
19474
|
+
channelName: "Agent.generate",
|
|
19475
|
+
kind: "async"
|
|
19476
|
+
}),
|
|
19477
|
+
agentStream: channel({
|
|
19478
|
+
channelName: "Agent.stream",
|
|
19479
|
+
kind: "async"
|
|
19480
|
+
}),
|
|
19481
|
+
agentStreamSync: channel({
|
|
19482
|
+
channelName: "Agent.stream.sync",
|
|
19483
|
+
kind: "sync-stream"
|
|
19484
|
+
}),
|
|
19485
|
+
toolLoopAgentGenerate: channel({
|
|
19486
|
+
channelName: "ToolLoopAgent.generate",
|
|
19487
|
+
kind: "async"
|
|
19488
|
+
}),
|
|
19489
|
+
toolLoopAgentStream: channel({
|
|
19490
|
+
channelName: "ToolLoopAgent.stream",
|
|
19491
|
+
kind: "async"
|
|
19492
|
+
}),
|
|
19493
|
+
workflowAgentStream: channel({
|
|
19494
|
+
channelName: "WorkflowAgent.stream",
|
|
19495
|
+
kind: "async"
|
|
19496
|
+
}),
|
|
19497
|
+
v7CreateTelemetryDispatcher: channel({
|
|
19498
|
+
channelName: "createTelemetryDispatcher",
|
|
19499
|
+
kind: "sync-stream"
|
|
19500
|
+
})
|
|
19501
|
+
},
|
|
19502
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.AI_SDK }
|
|
19503
|
+
);
|
|
19504
|
+
var harnessAgentChannels = defineChannels(
|
|
19505
|
+
"@ai-sdk/harness",
|
|
19506
|
+
{
|
|
19507
|
+
createSession: channel({
|
|
19508
|
+
channelName: "HarnessAgent.createSession",
|
|
19509
|
+
kind: "async"
|
|
19510
|
+
}),
|
|
19511
|
+
generate: channel({
|
|
19512
|
+
channelName: "HarnessAgent.generate",
|
|
19513
|
+
kind: "async"
|
|
19514
|
+
}),
|
|
19515
|
+
stream: channel({
|
|
19516
|
+
channelName: "HarnessAgent.stream",
|
|
19517
|
+
kind: "async"
|
|
19518
|
+
}),
|
|
19519
|
+
continueGenerate: channel({
|
|
19520
|
+
channelName: "HarnessAgent.continueGenerate",
|
|
19521
|
+
kind: "async"
|
|
19522
|
+
}),
|
|
19523
|
+
continueStream: channel({
|
|
19524
|
+
channelName: "HarnessAgent.continueStream",
|
|
19525
|
+
kind: "async"
|
|
19526
|
+
})
|
|
19527
|
+
},
|
|
19528
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.AI_SDK }
|
|
19529
|
+
);
|
|
19026
19530
|
|
|
19027
19531
|
// src/instrumentation/plugins/ai-sdk-plugin.ts
|
|
19028
19532
|
var DEFAULT_DENY_OUTPUT_PATHS = [
|
|
@@ -19099,6 +19603,17 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19099
19603
|
subscribeToAISDK() {
|
|
19100
19604
|
const denyOutputPaths = this.config.denyOutputPaths || DEFAULT_DENY_OUTPUT_PATHS;
|
|
19101
19605
|
this.unsubscribers.push(subscribeToAISDKV7TelemetryDispatcher());
|
|
19606
|
+
this.unsubscribers.push(subscribeToHarnessAgentCreateSession());
|
|
19607
|
+
this.unsubscribers.push(
|
|
19608
|
+
subscribeToHarnessContinuation(
|
|
19609
|
+
harnessAgentChannels.continueGenerate,
|
|
19610
|
+
denyOutputPaths
|
|
19611
|
+
),
|
|
19612
|
+
subscribeToHarnessContinuation(
|
|
19613
|
+
harnessAgentChannels.continueStream,
|
|
19614
|
+
denyOutputPaths
|
|
19615
|
+
)
|
|
19616
|
+
);
|
|
19102
19617
|
this.unsubscribers.push(
|
|
19103
19618
|
traceStreamingChannel(aiSDKChannels.generateText, {
|
|
19104
19619
|
name: "generateText",
|
|
@@ -19294,8 +19809,9 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19294
19809
|
this.unsubscribers.push(
|
|
19295
19810
|
traceStreamingChannel(harnessAgentChannels.generate, {
|
|
19296
19811
|
name: "HarnessAgent.generate",
|
|
19812
|
+
startSpan: _internalStartSpanWithInitialMerge,
|
|
19297
19813
|
type: "task" /* TASK */,
|
|
19298
|
-
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
19814
|
+
extractInput: ([params], event, span) => prepareAISDKHarnessAgentInput(params, event.self, span),
|
|
19299
19815
|
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
19300
19816
|
result,
|
|
19301
19817
|
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
@@ -19307,8 +19823,9 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19307
19823
|
this.unsubscribers.push(
|
|
19308
19824
|
traceStreamingChannel(harnessAgentChannels.stream, {
|
|
19309
19825
|
name: "HarnessAgent.stream",
|
|
19826
|
+
startSpan: _internalStartSpanWithInitialMerge,
|
|
19310
19827
|
type: "task" /* TASK */,
|
|
19311
|
-
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
19828
|
+
extractInput: ([params], event, span) => prepareAISDKHarnessAgentInput(params, event.self, span),
|
|
19312
19829
|
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
19313
19830
|
result,
|
|
19314
19831
|
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
@@ -19333,8 +19850,10 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19333
19850
|
this.unsubscribers.push(
|
|
19334
19851
|
traceStreamingChannel(harnessAgentChannels.continueGenerate, {
|
|
19335
19852
|
name: "HarnessAgent.continueGenerate",
|
|
19853
|
+
shouldTrace: (args) => !harnessContinuationParent(harnessSessionFromArguments(args)),
|
|
19854
|
+
startSpan: _internalStartSpanWithInitialMerge,
|
|
19336
19855
|
type: "task" /* TASK */,
|
|
19337
|
-
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
19856
|
+
extractInput: ([params], event, span) => prepareAISDKHarnessAgentInput(params, event.self, span),
|
|
19338
19857
|
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
19339
19858
|
result,
|
|
19340
19859
|
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
@@ -19346,8 +19865,10 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19346
19865
|
this.unsubscribers.push(
|
|
19347
19866
|
traceStreamingChannel(harnessAgentChannels.continueStream, {
|
|
19348
19867
|
name: "HarnessAgent.continueStream",
|
|
19868
|
+
shouldTrace: (args) => !harnessContinuationParent(harnessSessionFromArguments(args)),
|
|
19869
|
+
startSpan: _internalStartSpanWithInitialMerge,
|
|
19349
19870
|
type: "task" /* TASK */,
|
|
19350
|
-
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
19871
|
+
extractInput: ([params], event, span) => prepareAISDKHarnessAgentInput(params, event.self, span),
|
|
19351
19872
|
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
19352
19873
|
result,
|
|
19353
19874
|
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
@@ -19439,6 +19960,8 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19439
19960
|
defaultDenyOutputPaths: denyOutputPaths,
|
|
19440
19961
|
endEvent,
|
|
19441
19962
|
onComplete: () => unregisterWorkflowAgentWrapperSpan(span),
|
|
19963
|
+
onCancel: () => unregisterWorkflowAgentWrapperSpan(span),
|
|
19964
|
+
onError: () => unregisterWorkflowAgentWrapperSpan(span),
|
|
19442
19965
|
result,
|
|
19443
19966
|
span,
|
|
19444
19967
|
startTime
|
|
@@ -19447,6 +19970,153 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
19447
19970
|
);
|
|
19448
19971
|
}
|
|
19449
19972
|
};
|
|
19973
|
+
function subscribeToHarnessAgentCreateSession() {
|
|
19974
|
+
const channel2 = harnessAgentChannels.createSession.tracingChannel();
|
|
19975
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
19976
|
+
const handlers = {
|
|
19977
|
+
start: (event) => {
|
|
19978
|
+
const parent = captureHarnessCreateSessionParent(event.arguments?.[0]);
|
|
19979
|
+
if (parent) {
|
|
19980
|
+
parents.set(event, parent);
|
|
19981
|
+
}
|
|
19982
|
+
},
|
|
19983
|
+
asyncEnd: (event) => {
|
|
19984
|
+
registerHarnessSessionParent(event.result, parents.get(event));
|
|
19985
|
+
parents.delete(event);
|
|
19986
|
+
},
|
|
19987
|
+
error: (event) => {
|
|
19988
|
+
parents.delete(event);
|
|
19989
|
+
}
|
|
19990
|
+
};
|
|
19991
|
+
channel2.subscribe(handlers);
|
|
19992
|
+
return () => channel2.unsubscribe(handlers);
|
|
19993
|
+
}
|
|
19994
|
+
function harnessContinuationParentFromEvent(event) {
|
|
19995
|
+
try {
|
|
19996
|
+
return harnessContinuationParent(event.arguments?.[0]?.session);
|
|
19997
|
+
} catch {
|
|
19998
|
+
return void 0;
|
|
19999
|
+
}
|
|
20000
|
+
}
|
|
20001
|
+
function subscribeToHarnessContinuation(continuationChannel, defaultDenyOutputPaths) {
|
|
20002
|
+
const channel2 = continuationChannel.tracingChannel();
|
|
20003
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
20004
|
+
const startTimes = /* @__PURE__ */ new WeakMap();
|
|
20005
|
+
const unbindParentStore = bindHarnessTurnParentToStart(
|
|
20006
|
+
channel2,
|
|
20007
|
+
harnessContinuationParentFromEvent
|
|
20008
|
+
);
|
|
20009
|
+
const handlers = {
|
|
20010
|
+
start: (event) => {
|
|
20011
|
+
const parent = harnessContinuationParentFromEvent(event);
|
|
20012
|
+
if (!parent) {
|
|
20013
|
+
return;
|
|
20014
|
+
}
|
|
20015
|
+
parents.set(event, parent);
|
|
20016
|
+
startTimes.set(event, getCurrentUnixTimestamp());
|
|
20017
|
+
try {
|
|
20018
|
+
const params = event.arguments?.[0];
|
|
20019
|
+
if (params) {
|
|
20020
|
+
prepareAISDKHarnessAgentInput(params, event.self);
|
|
20021
|
+
}
|
|
20022
|
+
} catch (error2) {
|
|
20023
|
+
debugLogger.error(
|
|
20024
|
+
"Error preparing Harness continuation telemetry:",
|
|
20025
|
+
error2
|
|
20026
|
+
);
|
|
20027
|
+
}
|
|
20028
|
+
},
|
|
20029
|
+
asyncEnd: (event) => {
|
|
20030
|
+
const parent = parents.get(event);
|
|
20031
|
+
const startTime = startTimes.get(event) ?? getCurrentUnixTimestamp();
|
|
20032
|
+
parents.delete(event);
|
|
20033
|
+
startTimes.delete(event);
|
|
20034
|
+
if (!parent) {
|
|
20035
|
+
return;
|
|
20036
|
+
}
|
|
20037
|
+
const endEvent = event;
|
|
20038
|
+
const span = {
|
|
20039
|
+
end: () => endHarnessTurn(parent),
|
|
20040
|
+
log: (update) => updateHarnessTurn(
|
|
20041
|
+
parent,
|
|
20042
|
+
Object.prototype.hasOwnProperty.call(update, "error") && !Object.prototype.hasOwnProperty.call(update, "output") ? { ...update, output: null } : update
|
|
20043
|
+
)
|
|
20044
|
+
};
|
|
20045
|
+
try {
|
|
20046
|
+
if (isAsyncIterable3(endEvent.result)) {
|
|
20047
|
+
patchStreamIfNeeded(endEvent.result, {
|
|
20048
|
+
onComplete: (chunks) => {
|
|
20049
|
+
try {
|
|
20050
|
+
const { metadata, metrics, output } = aggregateAISDKChunks(
|
|
20051
|
+
chunks,
|
|
20052
|
+
endEvent.result,
|
|
20053
|
+
endEvent
|
|
20054
|
+
);
|
|
20055
|
+
span.log({
|
|
20056
|
+
...metadata ? { metadata } : {},
|
|
20057
|
+
metrics,
|
|
20058
|
+
output
|
|
20059
|
+
});
|
|
20060
|
+
} catch (error2) {
|
|
20061
|
+
debugLogger.error(
|
|
20062
|
+
"Error aggregating Harness continuation stream:",
|
|
20063
|
+
error2
|
|
20064
|
+
);
|
|
20065
|
+
} finally {
|
|
20066
|
+
span.end();
|
|
20067
|
+
}
|
|
20068
|
+
},
|
|
20069
|
+
onError: (error2) => {
|
|
20070
|
+
span.log({ error: toLoggedError(error2), output: null });
|
|
20071
|
+
span.end();
|
|
20072
|
+
}
|
|
20073
|
+
});
|
|
20074
|
+
return;
|
|
20075
|
+
}
|
|
20076
|
+
if (patchAISDKStreamingResult({
|
|
20077
|
+
defaultDenyOutputPaths,
|
|
20078
|
+
endEvent,
|
|
20079
|
+
result: endEvent.result,
|
|
20080
|
+
resolvePromiseUsage: true,
|
|
20081
|
+
span,
|
|
20082
|
+
startTime
|
|
20083
|
+
})) {
|
|
20084
|
+
return;
|
|
20085
|
+
}
|
|
20086
|
+
finalizeAISDKChildTracing(endEvent);
|
|
20087
|
+
span.log({
|
|
20088
|
+
metrics: extractTokenMetrics(endEvent.result),
|
|
20089
|
+
output: processAISDKOutput(
|
|
20090
|
+
endEvent.result,
|
|
20091
|
+
resolveDenyOutputPaths(endEvent, defaultDenyOutputPaths)
|
|
20092
|
+
)
|
|
20093
|
+
});
|
|
20094
|
+
span.end();
|
|
20095
|
+
} catch (error2) {
|
|
20096
|
+
debugLogger.error("Error tracing Harness continuation:", error2);
|
|
20097
|
+
span.end();
|
|
20098
|
+
}
|
|
20099
|
+
},
|
|
20100
|
+
error: (event) => {
|
|
20101
|
+
const parent = parents.get(event);
|
|
20102
|
+
parents.delete(event);
|
|
20103
|
+
startTimes.delete(event);
|
|
20104
|
+
if (!parent) {
|
|
20105
|
+
return;
|
|
20106
|
+
}
|
|
20107
|
+
updateHarnessTurn(parent, {
|
|
20108
|
+
error: toLoggedError(event.error),
|
|
20109
|
+
output: null
|
|
20110
|
+
});
|
|
20111
|
+
endHarnessTurn(parent);
|
|
20112
|
+
}
|
|
20113
|
+
};
|
|
20114
|
+
channel2.subscribe(handlers);
|
|
20115
|
+
return () => {
|
|
20116
|
+
unbindParentStore();
|
|
20117
|
+
channel2.unsubscribe(handlers);
|
|
20118
|
+
};
|
|
20119
|
+
}
|
|
19450
20120
|
function subscribeToAISDKV7TelemetryDispatcher() {
|
|
19451
20121
|
const channel2 = aiSDKChannels.v7CreateTelemetryDispatcher.tracingChannel();
|
|
19452
20122
|
const telemetry = braintrustAISDKTelemetry();
|
|
@@ -19899,7 +20569,13 @@ function prepareAISDKCallInput(params, event, span, defaultDenyOutputPaths, chil
|
|
|
19899
20569
|
metadata
|
|
19900
20570
|
};
|
|
19901
20571
|
}
|
|
19902
|
-
function prepareAISDKHarnessAgentInput(params, self) {
|
|
20572
|
+
function prepareAISDKHarnessAgentInput(params, self, span) {
|
|
20573
|
+
if (span) {
|
|
20574
|
+
registerHarnessTurnSpan({
|
|
20575
|
+
session: params.session,
|
|
20576
|
+
span
|
|
20577
|
+
});
|
|
20578
|
+
}
|
|
19903
20579
|
if (isObject(self)) {
|
|
19904
20580
|
try {
|
|
19905
20581
|
if (isObject(self.settings)) {
|
|
@@ -19938,6 +20614,10 @@ function prepareAISDKHarnessAgentInput(params, self) {
|
|
|
19938
20614
|
metadata
|
|
19939
20615
|
};
|
|
19940
20616
|
}
|
|
20617
|
+
function harnessSessionFromArguments(args) {
|
|
20618
|
+
const params = args[0];
|
|
20619
|
+
return isObject(params) ? params.session : void 0;
|
|
20620
|
+
}
|
|
19941
20621
|
function prepareAISDKWorkflowAgentStreamInput(params, event, span, defaultDenyOutputPaths) {
|
|
19942
20622
|
registerWorkflowAgentWrapperSpan(span);
|
|
19943
20623
|
const { input } = processAISDKWorkflowAgentCallInput(params);
|
|
@@ -20385,19 +21065,22 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
20385
21065
|
activeEntry.openSpans.delete(span);
|
|
20386
21066
|
}
|
|
20387
21067
|
},
|
|
20388
|
-
|
|
20389
|
-
|
|
20390
|
-
|
|
20391
|
-
|
|
21068
|
+
withSpanInstrumentationName(
|
|
21069
|
+
{
|
|
21070
|
+
name: "doGenerate",
|
|
21071
|
+
spanAttributes: {
|
|
21072
|
+
type: "llm" /* LLM */
|
|
21073
|
+
},
|
|
21074
|
+
event: buildAISDKModelStartEvent(
|
|
21075
|
+
callOptions,
|
|
21076
|
+
activeEntry.baseMetadata,
|
|
21077
|
+
{
|
|
21078
|
+
workflowAgent: activeEntry.childTracingOptions.workflowAgent
|
|
21079
|
+
}
|
|
21080
|
+
)
|
|
20392
21081
|
},
|
|
20393
|
-
|
|
20394
|
-
|
|
20395
|
-
activeEntry.baseMetadata,
|
|
20396
|
-
{
|
|
20397
|
-
workflowAgent: activeEntry.childTracingOptions.workflowAgent
|
|
20398
|
-
}
|
|
20399
|
-
)
|
|
20400
|
-
}
|
|
21082
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
21083
|
+
)
|
|
20401
21084
|
);
|
|
20402
21085
|
};
|
|
20403
21086
|
if (originalDoStream) {
|
|
@@ -20407,19 +21090,24 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
20407
21090
|
return Reflect.apply(originalDoStream, resolvedModel, [callOptions]);
|
|
20408
21091
|
}
|
|
20409
21092
|
closeOpenAISDKModelPatchSpans(activeEntry);
|
|
20410
|
-
const span = activeEntry.parentSpan.startSpan(
|
|
20411
|
-
|
|
20412
|
-
spanAttributes: {
|
|
20413
|
-
type: "llm" /* LLM */
|
|
20414
|
-
},
|
|
20415
|
-
event: buildAISDKModelStartEvent(
|
|
20416
|
-
callOptions,
|
|
20417
|
-
activeEntry.baseMetadata,
|
|
21093
|
+
const span = activeEntry.parentSpan.startSpan(
|
|
21094
|
+
withSpanInstrumentationName(
|
|
20418
21095
|
{
|
|
20419
|
-
|
|
20420
|
-
|
|
21096
|
+
name: "doStream",
|
|
21097
|
+
spanAttributes: {
|
|
21098
|
+
type: "llm" /* LLM */
|
|
21099
|
+
},
|
|
21100
|
+
event: buildAISDKModelStartEvent(
|
|
21101
|
+
callOptions,
|
|
21102
|
+
activeEntry.baseMetadata,
|
|
21103
|
+
{
|
|
21104
|
+
workflowAgent: activeEntry.childTracingOptions.workflowAgent
|
|
21105
|
+
}
|
|
21106
|
+
)
|
|
21107
|
+
},
|
|
21108
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
20421
21109
|
)
|
|
20422
|
-
|
|
21110
|
+
);
|
|
20423
21111
|
activeEntry.openSpans.add(span);
|
|
20424
21112
|
const streamStartTime = getCurrentUnixTimestamp();
|
|
20425
21113
|
const result = await withCurrent(
|
|
@@ -20591,12 +21279,17 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
20591
21279
|
}
|
|
20592
21280
|
if (isAsyncGenerator2(result)) {
|
|
20593
21281
|
return (async function* () {
|
|
20594
|
-
const span = activeEntry.parentSpan.startSpan(
|
|
20595
|
-
|
|
20596
|
-
|
|
20597
|
-
|
|
20598
|
-
|
|
20599
|
-
|
|
21282
|
+
const span = activeEntry.parentSpan.startSpan(
|
|
21283
|
+
withSpanInstrumentationName(
|
|
21284
|
+
{
|
|
21285
|
+
name: activeEntry.name,
|
|
21286
|
+
spanAttributes: {
|
|
21287
|
+
type: "tool" /* TOOL */
|
|
21288
|
+
}
|
|
21289
|
+
},
|
|
21290
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
21291
|
+
)
|
|
21292
|
+
);
|
|
20600
21293
|
span.log({ input: serializeToolExecutionInput(args) });
|
|
20601
21294
|
try {
|
|
20602
21295
|
let lastValue;
|
|
@@ -20620,12 +21313,15 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
20620
21313
|
span.log({ output: awaitedResult });
|
|
20621
21314
|
return awaitedResult;
|
|
20622
21315
|
},
|
|
20623
|
-
|
|
20624
|
-
|
|
20625
|
-
|
|
20626
|
-
|
|
20627
|
-
|
|
20628
|
-
|
|
21316
|
+
withSpanInstrumentationName(
|
|
21317
|
+
{
|
|
21318
|
+
name: activeEntry.name,
|
|
21319
|
+
spanAttributes: {
|
|
21320
|
+
type: "tool" /* TOOL */
|
|
21321
|
+
}
|
|
21322
|
+
},
|
|
21323
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
21324
|
+
)
|
|
20629
21325
|
);
|
|
20630
21326
|
};
|
|
20631
21327
|
cleanup.push(() => {
|
|
@@ -20784,6 +21480,8 @@ function patchAISDKStreamingResult(args) {
|
|
|
20784
21480
|
defaultDenyOutputPaths,
|
|
20785
21481
|
endEvent,
|
|
20786
21482
|
onComplete,
|
|
21483
|
+
onCancel,
|
|
21484
|
+
onError,
|
|
20787
21485
|
result,
|
|
20788
21486
|
resolvePromiseUsage,
|
|
20789
21487
|
span,
|
|
@@ -20795,14 +21493,43 @@ function patchAISDKStreamingResult(args) {
|
|
|
20795
21493
|
const resultRecord = result;
|
|
20796
21494
|
attachKnownResultPromiseHandlers(resultRecord);
|
|
20797
21495
|
let finalized = false;
|
|
20798
|
-
const finalize = () => {
|
|
21496
|
+
const finalize = (outcome) => {
|
|
20799
21497
|
if (finalized) {
|
|
20800
21498
|
return;
|
|
20801
21499
|
}
|
|
20802
21500
|
finalized = true;
|
|
20803
|
-
|
|
20804
|
-
|
|
20805
|
-
|
|
21501
|
+
try {
|
|
21502
|
+
finalizeAISDKChildTracing(endEvent);
|
|
21503
|
+
} catch (error2) {
|
|
21504
|
+
debugLogger.error("Error finalizing AI SDK child tracing:", error2);
|
|
21505
|
+
}
|
|
21506
|
+
try {
|
|
21507
|
+
span.end();
|
|
21508
|
+
} catch (error2) {
|
|
21509
|
+
debugLogger.error("Error ending AI SDK streaming span:", error2);
|
|
21510
|
+
}
|
|
21511
|
+
if (outcome && "error" in outcome) {
|
|
21512
|
+
try {
|
|
21513
|
+
onError?.(outcome.error);
|
|
21514
|
+
} catch (error2) {
|
|
21515
|
+
debugLogger.error("Error in AI SDK streaming error hook:", error2);
|
|
21516
|
+
}
|
|
21517
|
+
} else if (outcome) {
|
|
21518
|
+
try {
|
|
21519
|
+
onComplete?.(outcome);
|
|
21520
|
+
} catch (error2) {
|
|
21521
|
+
debugLogger.error("Error in AI SDK streaming completion hook:", error2);
|
|
21522
|
+
}
|
|
21523
|
+
} else {
|
|
21524
|
+
try {
|
|
21525
|
+
onCancel?.();
|
|
21526
|
+
} catch (error2) {
|
|
21527
|
+
debugLogger.error(
|
|
21528
|
+
"Error in AI SDK streaming cancellation hook:",
|
|
21529
|
+
error2
|
|
21530
|
+
);
|
|
21531
|
+
}
|
|
21532
|
+
}
|
|
20806
21533
|
};
|
|
20807
21534
|
let outputLogged = false;
|
|
20808
21535
|
const logStreamingOutput = async (firstChunkTime) => {
|
|
@@ -20836,15 +21563,29 @@ function patchAISDKStreamingResult(args) {
|
|
|
20836
21563
|
resolveDenyOutputPaths(endEvent, defaultDenyOutputPaths)
|
|
20837
21564
|
);
|
|
20838
21565
|
const metadata = buildResolvedMetadataPayload(result).metadata;
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
20843
|
-
|
|
21566
|
+
try {
|
|
21567
|
+
span.log({
|
|
21568
|
+
output,
|
|
21569
|
+
...metadata ? { metadata } : {},
|
|
21570
|
+
metrics
|
|
21571
|
+
});
|
|
21572
|
+
} catch (error2) {
|
|
21573
|
+
debugLogger.error("Error logging AI SDK streaming output:", error2);
|
|
21574
|
+
}
|
|
21575
|
+
finalize({ metrics, output });
|
|
20844
21576
|
} catch (error2) {
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
21577
|
+
const loggedError = toLoggedError(error2);
|
|
21578
|
+
try {
|
|
21579
|
+
span.log({ error: loggedError });
|
|
21580
|
+
} catch (loggingError) {
|
|
21581
|
+
debugLogger.error(
|
|
21582
|
+
"Error logging AI SDK streaming failure:",
|
|
21583
|
+
loggingError
|
|
21584
|
+
);
|
|
21585
|
+
}
|
|
21586
|
+
finalize({
|
|
21587
|
+
error: error2 instanceof Error ? error2 : new Error(String(loggedError))
|
|
21588
|
+
});
|
|
20848
21589
|
}
|
|
20849
21590
|
};
|
|
20850
21591
|
const createAsyncIterableHooks = () => {
|
|
@@ -20861,11 +21602,16 @@ function patchAISDKStreamingResult(args) {
|
|
|
20861
21602
|
onError: (error2) => {
|
|
20862
21603
|
if (!outputLogged) {
|
|
20863
21604
|
outputLogged = true;
|
|
20864
|
-
|
|
20865
|
-
error: error2
|
|
20866
|
-
})
|
|
21605
|
+
try {
|
|
21606
|
+
span.log({ error: error2 });
|
|
21607
|
+
} catch (loggingError) {
|
|
21608
|
+
debugLogger.error(
|
|
21609
|
+
"Error logging AI SDK stream failure:",
|
|
21610
|
+
loggingError
|
|
21611
|
+
);
|
|
21612
|
+
}
|
|
20867
21613
|
}
|
|
20868
|
-
finalize();
|
|
21614
|
+
finalize({ error: error2 });
|
|
20869
21615
|
},
|
|
20870
21616
|
onCancel: finalize
|
|
20871
21617
|
};
|
|
@@ -20951,8 +21697,18 @@ function patchAISDKStreamingResult(args) {
|
|
|
20951
21697
|
}
|
|
20952
21698
|
controller.enqueue(value);
|
|
20953
21699
|
} catch (error2) {
|
|
20954
|
-
|
|
20955
|
-
|
|
21700
|
+
const loggedError = toLoggedError(error2);
|
|
21701
|
+
try {
|
|
21702
|
+
span.log({ error: loggedError });
|
|
21703
|
+
} catch (loggingError) {
|
|
21704
|
+
debugLogger.error(
|
|
21705
|
+
"Error logging AI SDK base stream failure:",
|
|
21706
|
+
loggingError
|
|
21707
|
+
);
|
|
21708
|
+
}
|
|
21709
|
+
finalize({
|
|
21710
|
+
error: error2 instanceof Error ? error2 : new Error(String(loggedError))
|
|
21711
|
+
});
|
|
20956
21712
|
controller.error(error2);
|
|
20957
21713
|
}
|
|
20958
21714
|
},
|
|
@@ -21741,7 +22497,8 @@ var claudeAgentSDKChannels = defineChannels(
|
|
|
21741
22497
|
channelName: "query",
|
|
21742
22498
|
kind: "sync-stream"
|
|
21743
22499
|
})
|
|
21744
|
-
}
|
|
22500
|
+
},
|
|
22501
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK }
|
|
21745
22502
|
);
|
|
21746
22503
|
|
|
21747
22504
|
// src/instrumentation/plugins/claude-agent-sdk-instrumentation-constants.ts
|
|
@@ -21889,22 +22646,27 @@ function wrapLocalClaudeToolHandler(handler, getMetadata) {
|
|
|
21889
22646
|
const spanName = metadata.serverName ? `tool: ${metadata.serverName}/${metadata.toolName}` : `tool: ${metadata.toolName}`;
|
|
21890
22647
|
const runWithResolvedParent = async () => {
|
|
21891
22648
|
const parent = toolUseId && localToolParentResolver ? await localToolParentResolver(toolUseId).catch(() => void 0) : void 0;
|
|
21892
|
-
const span = startSpan(
|
|
21893
|
-
|
|
21894
|
-
|
|
21895
|
-
|
|
21896
|
-
|
|
21897
|
-
|
|
21898
|
-
|
|
21899
|
-
|
|
21900
|
-
|
|
21901
|
-
|
|
21902
|
-
|
|
21903
|
-
|
|
21904
|
-
|
|
21905
|
-
|
|
21906
|
-
|
|
21907
|
-
|
|
22649
|
+
const span = startSpan(
|
|
22650
|
+
withSpanInstrumentationName(
|
|
22651
|
+
{
|
|
22652
|
+
event: {
|
|
22653
|
+
input: handlerArgs[0],
|
|
22654
|
+
metadata: {
|
|
22655
|
+
"claude_agent_sdk.raw_tool_name": rawToolName,
|
|
22656
|
+
"gen_ai.tool.name": metadata.toolName,
|
|
22657
|
+
...toolUseId && { "gen_ai.tool.call.id": toolUseId },
|
|
22658
|
+
...metadata.serverName && {
|
|
22659
|
+
"mcp.server": metadata.serverName
|
|
22660
|
+
}
|
|
22661
|
+
}
|
|
22662
|
+
},
|
|
22663
|
+
name: spanName,
|
|
22664
|
+
...parent && { parent },
|
|
22665
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
22666
|
+
},
|
|
22667
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
22668
|
+
)
|
|
22669
|
+
);
|
|
21908
22670
|
const runHandler = () => Reflect.apply(handler, this, handlerArgs);
|
|
21909
22671
|
const finalizeSuccess = (result) => {
|
|
21910
22672
|
span.log({ output: result });
|
|
@@ -22229,14 +22991,19 @@ async function createLLMSpanForMessages(messages, promptMessages, conversationHi
|
|
|
22229
22991
|
).filter(
|
|
22230
22992
|
(c) => c !== void 0
|
|
22231
22993
|
);
|
|
22232
|
-
const span = existingSpan ?? startSpan(
|
|
22233
|
-
|
|
22234
|
-
|
|
22235
|
-
|
|
22236
|
-
|
|
22237
|
-
|
|
22238
|
-
|
|
22239
|
-
|
|
22994
|
+
const span = existingSpan ?? startSpan(
|
|
22995
|
+
withSpanInstrumentationName(
|
|
22996
|
+
{
|
|
22997
|
+
name: "anthropic.messages.create",
|
|
22998
|
+
parent: parentSpan,
|
|
22999
|
+
spanAttributes: {
|
|
23000
|
+
type: "llm" /* LLM */
|
|
23001
|
+
},
|
|
23002
|
+
startTime
|
|
23003
|
+
},
|
|
23004
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
23005
|
+
)
|
|
23006
|
+
);
|
|
22240
23007
|
span.log({
|
|
22241
23008
|
input,
|
|
22242
23009
|
metadata: model ? { model } : void 0,
|
|
@@ -22339,25 +23106,30 @@ function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers,
|
|
|
22339
23106
|
return {};
|
|
22340
23107
|
}
|
|
22341
23108
|
const parsed = parseToolName(input.tool_name);
|
|
22342
|
-
const toolSpan = startSpan(
|
|
22343
|
-
|
|
22344
|
-
|
|
22345
|
-
|
|
22346
|
-
|
|
22347
|
-
|
|
22348
|
-
|
|
22349
|
-
|
|
22350
|
-
|
|
22351
|
-
|
|
22352
|
-
|
|
22353
|
-
|
|
22354
|
-
|
|
22355
|
-
|
|
22356
|
-
|
|
22357
|
-
|
|
22358
|
-
|
|
22359
|
-
|
|
22360
|
-
|
|
23109
|
+
const toolSpan = startSpan(
|
|
23110
|
+
withSpanInstrumentationName(
|
|
23111
|
+
{
|
|
23112
|
+
event: {
|
|
23113
|
+
input: input.tool_input,
|
|
23114
|
+
metadata: {
|
|
23115
|
+
"claude_agent_sdk.cwd": input.cwd,
|
|
23116
|
+
"claude_agent_sdk.raw_tool_name": parsed.rawToolName,
|
|
23117
|
+
"claude_agent_sdk.session_id": input.session_id,
|
|
23118
|
+
"gen_ai.tool.call.id": toolUseID,
|
|
23119
|
+
"gen_ai.tool.name": parsed.toolName,
|
|
23120
|
+
...parsed.mcpServer && { "mcp.server": parsed.mcpServer },
|
|
23121
|
+
...getMcpServerMetadata(parsed.mcpServer, mcpServers)
|
|
23122
|
+
}
|
|
23123
|
+
},
|
|
23124
|
+
name: parsed.displayName,
|
|
23125
|
+
parent: await resolveParentSpan(toolUseID, {
|
|
23126
|
+
agentId: input.agent_id
|
|
23127
|
+
}),
|
|
23128
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
23129
|
+
},
|
|
23130
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
23131
|
+
)
|
|
23132
|
+
);
|
|
22361
23133
|
activeToolSpans.set(toolUseID, toolSpan);
|
|
22362
23134
|
return {};
|
|
22363
23135
|
};
|
|
@@ -22723,14 +23495,19 @@ async function ensureSubAgentSpan(subAgentDetailsByToolUseId, rootSpan, activeTo
|
|
|
22723
23495
|
const spanName = formatSubAgentSpanName(details);
|
|
22724
23496
|
const parentToolSpan = activeToolSpans.get(parentToolUseId);
|
|
22725
23497
|
const parentSpan = parentToolSpan ? await parentToolSpan.export() : await rootSpan.export();
|
|
22726
|
-
const subAgentSpan = startSpan(
|
|
22727
|
-
|
|
22728
|
-
|
|
22729
|
-
|
|
22730
|
-
|
|
22731
|
-
|
|
22732
|
-
|
|
22733
|
-
|
|
23498
|
+
const subAgentSpan = startSpan(
|
|
23499
|
+
withSpanInstrumentationName(
|
|
23500
|
+
{
|
|
23501
|
+
event: {
|
|
23502
|
+
metadata: subAgentDetailsToMetadata(details)
|
|
23503
|
+
},
|
|
23504
|
+
name: spanName,
|
|
23505
|
+
parent: parentSpan,
|
|
23506
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
23507
|
+
},
|
|
23508
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
23509
|
+
)
|
|
23510
|
+
);
|
|
22734
23511
|
subAgentSpans.set(parentToolUseId, subAgentSpan);
|
|
22735
23512
|
return subAgentSpan;
|
|
22736
23513
|
}
|
|
@@ -22751,14 +23528,19 @@ async function ensureActiveLlmSpanForParentToolUse(rootSpan, activeLlmSpansByPar
|
|
|
22751
23528
|
);
|
|
22752
23529
|
llmParentSpan = await subAgentSpan.export();
|
|
22753
23530
|
}
|
|
22754
|
-
const llmSpan = startSpan(
|
|
22755
|
-
|
|
22756
|
-
|
|
22757
|
-
|
|
22758
|
-
|
|
22759
|
-
|
|
22760
|
-
|
|
22761
|
-
|
|
23531
|
+
const llmSpan = startSpan(
|
|
23532
|
+
withSpanInstrumentationName(
|
|
23533
|
+
{
|
|
23534
|
+
name: "anthropic.messages.create",
|
|
23535
|
+
parent: llmParentSpan,
|
|
23536
|
+
spanAttributes: {
|
|
23537
|
+
type: "llm" /* LLM */
|
|
23538
|
+
},
|
|
23539
|
+
startTime
|
|
23540
|
+
},
|
|
23541
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
23542
|
+
)
|
|
23543
|
+
);
|
|
22762
23544
|
activeLlmSpansByParentToolUse.set(parentKey, llmSpan);
|
|
22763
23545
|
return llmSpan;
|
|
22764
23546
|
}
|
|
@@ -23027,12 +23809,17 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
23027
23809
|
}
|
|
23028
23810
|
})();
|
|
23029
23811
|
}
|
|
23030
|
-
const span = startSpan(
|
|
23031
|
-
|
|
23032
|
-
|
|
23033
|
-
|
|
23034
|
-
|
|
23035
|
-
|
|
23812
|
+
const span = startSpan(
|
|
23813
|
+
withSpanInstrumentationName(
|
|
23814
|
+
{
|
|
23815
|
+
name: "Claude Agent",
|
|
23816
|
+
spanAttributes: {
|
|
23817
|
+
type: "task" /* TASK */
|
|
23818
|
+
}
|
|
23819
|
+
},
|
|
23820
|
+
INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK
|
|
23821
|
+
)
|
|
23822
|
+
);
|
|
23036
23823
|
const startTime = getCurrentUnixTimestamp();
|
|
23037
23824
|
try {
|
|
23038
23825
|
span.log({
|
|
@@ -23197,24 +23984,28 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
23197
23984
|
};
|
|
23198
23985
|
|
|
23199
23986
|
// src/instrumentation/plugins/cursor-sdk-channels.ts
|
|
23200
|
-
var cursorSDKChannels = defineChannels(
|
|
23201
|
-
|
|
23202
|
-
|
|
23203
|
-
|
|
23204
|
-
|
|
23205
|
-
|
|
23206
|
-
|
|
23207
|
-
|
|
23208
|
-
|
|
23209
|
-
|
|
23210
|
-
|
|
23211
|
-
|
|
23212
|
-
|
|
23213
|
-
|
|
23214
|
-
|
|
23215
|
-
|
|
23216
|
-
|
|
23217
|
-
|
|
23987
|
+
var cursorSDKChannels = defineChannels(
|
|
23988
|
+
"@cursor/sdk",
|
|
23989
|
+
{
|
|
23990
|
+
create: channel({
|
|
23991
|
+
channelName: "Agent.create",
|
|
23992
|
+
kind: "async"
|
|
23993
|
+
}),
|
|
23994
|
+
resume: channel({
|
|
23995
|
+
channelName: "Agent.resume",
|
|
23996
|
+
kind: "async"
|
|
23997
|
+
}),
|
|
23998
|
+
prompt: channel({
|
|
23999
|
+
channelName: "Agent.prompt",
|
|
24000
|
+
kind: "async"
|
|
24001
|
+
}),
|
|
24002
|
+
send: channel({
|
|
24003
|
+
channelName: "agent.send",
|
|
24004
|
+
kind: "async"
|
|
24005
|
+
})
|
|
24006
|
+
},
|
|
24007
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CURSOR_SDK }
|
|
24008
|
+
);
|
|
23218
24009
|
|
|
23219
24010
|
// src/instrumentation/plugins/cursor-sdk-plugin.ts
|
|
23220
24011
|
var PATCHED_AGENT = /* @__PURE__ */ Symbol.for("braintrust.cursor-sdk.auto-patched-agent");
|
|
@@ -23266,10 +24057,15 @@ var CursorSDKPlugin = class extends BasePlugin {
|
|
|
23266
24057
|
provider: "cursor",
|
|
23267
24058
|
...event.moduleVersion ? { "cursor_sdk.version": event.moduleVersion } : {}
|
|
23268
24059
|
};
|
|
23269
|
-
const span = startSpan(
|
|
23270
|
-
|
|
23271
|
-
|
|
23272
|
-
|
|
24060
|
+
const span = startSpan(
|
|
24061
|
+
withSpanInstrumentationName(
|
|
24062
|
+
{
|
|
24063
|
+
name: "Cursor Agent",
|
|
24064
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
24065
|
+
},
|
|
24066
|
+
INSTRUMENTATION_NAMES.CURSOR_SDK
|
|
24067
|
+
)
|
|
24068
|
+
);
|
|
23273
24069
|
const startTime = getCurrentUnixTimestamp();
|
|
23274
24070
|
safeLog2(span, {
|
|
23275
24071
|
input: sanitizeUserMessage(message),
|
|
@@ -23331,10 +24127,15 @@ var CursorSDKPlugin = class extends BasePlugin {
|
|
|
23331
24127
|
provider: "cursor",
|
|
23332
24128
|
...event.moduleVersion ? { "cursor_sdk.version": event.moduleVersion } : {}
|
|
23333
24129
|
};
|
|
23334
|
-
const span = startSpan(
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
24130
|
+
const span = startSpan(
|
|
24131
|
+
withSpanInstrumentationName(
|
|
24132
|
+
{
|
|
24133
|
+
name: "Cursor Agent",
|
|
24134
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
24135
|
+
},
|
|
24136
|
+
INSTRUMENTATION_NAMES.CURSOR_SDK
|
|
24137
|
+
)
|
|
24138
|
+
);
|
|
23338
24139
|
const startTime = getCurrentUnixTimestamp();
|
|
23339
24140
|
safeLog2(span, {
|
|
23340
24141
|
input: sanitizeUserMessage(message),
|
|
@@ -23781,29 +24582,39 @@ async function startToolSpan(state, args) {
|
|
|
23781
24582
|
if (args.truncated?.result !== void 0) {
|
|
23782
24583
|
metadata["cursor_sdk.tool.result_truncated"] = args.truncated.result;
|
|
23783
24584
|
}
|
|
23784
|
-
const span = startSpan(
|
|
23785
|
-
|
|
23786
|
-
|
|
23787
|
-
|
|
23788
|
-
|
|
23789
|
-
|
|
23790
|
-
|
|
23791
|
-
|
|
23792
|
-
|
|
24585
|
+
const span = startSpan(
|
|
24586
|
+
withSpanInstrumentationName(
|
|
24587
|
+
{
|
|
24588
|
+
event: {
|
|
24589
|
+
input: args.args,
|
|
24590
|
+
metadata
|
|
24591
|
+
},
|
|
24592
|
+
name: `tool: ${name}`,
|
|
24593
|
+
parent: await state.span.export(),
|
|
24594
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
24595
|
+
},
|
|
24596
|
+
INSTRUMENTATION_NAMES.CURSOR_SDK
|
|
24597
|
+
)
|
|
24598
|
+
);
|
|
23793
24599
|
let subAgentSpan;
|
|
23794
24600
|
if (isSubAgentToolName(name)) {
|
|
23795
|
-
subAgentSpan = startSpan(
|
|
23796
|
-
|
|
23797
|
-
|
|
23798
|
-
|
|
23799
|
-
|
|
23800
|
-
|
|
23801
|
-
|
|
23802
|
-
|
|
23803
|
-
|
|
23804
|
-
|
|
23805
|
-
|
|
23806
|
-
|
|
24601
|
+
subAgentSpan = startSpan(
|
|
24602
|
+
withSpanInstrumentationName(
|
|
24603
|
+
{
|
|
24604
|
+
event: {
|
|
24605
|
+
input: args.args,
|
|
24606
|
+
metadata: {
|
|
24607
|
+
"cursor_sdk.subagent.tool_call_id": args.callId,
|
|
24608
|
+
"gen_ai.tool.name": name
|
|
24609
|
+
}
|
|
24610
|
+
},
|
|
24611
|
+
name: formatSubAgentSpanName2(args.toolCall, args.args),
|
|
24612
|
+
parent: await span.export(),
|
|
24613
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
24614
|
+
},
|
|
24615
|
+
INSTRUMENTATION_NAMES.CURSOR_SDK
|
|
24616
|
+
)
|
|
24617
|
+
);
|
|
23807
24618
|
}
|
|
23808
24619
|
return { span, subAgentSpan };
|
|
23809
24620
|
}
|
|
@@ -24062,24 +24873,28 @@ function cleanMetrics2(metrics) {
|
|
|
24062
24873
|
}
|
|
24063
24874
|
|
|
24064
24875
|
// src/instrumentation/plugins/openai-agents-channels.ts
|
|
24065
|
-
var openAIAgentsCoreChannels = defineChannels(
|
|
24066
|
-
|
|
24067
|
-
|
|
24068
|
-
|
|
24069
|
-
|
|
24070
|
-
|
|
24071
|
-
|
|
24072
|
-
|
|
24073
|
-
|
|
24074
|
-
|
|
24075
|
-
|
|
24076
|
-
|
|
24077
|
-
|
|
24078
|
-
|
|
24079
|
-
|
|
24080
|
-
|
|
24081
|
-
|
|
24082
|
-
|
|
24876
|
+
var openAIAgentsCoreChannels = defineChannels(
|
|
24877
|
+
"@openai/agents-core",
|
|
24878
|
+
{
|
|
24879
|
+
onTraceStart: channel({
|
|
24880
|
+
channelName: "tracing.processor.onTraceStart",
|
|
24881
|
+
kind: "async"
|
|
24882
|
+
}),
|
|
24883
|
+
onTraceEnd: channel({
|
|
24884
|
+
channelName: "tracing.processor.onTraceEnd",
|
|
24885
|
+
kind: "async"
|
|
24886
|
+
}),
|
|
24887
|
+
onSpanStart: channel({
|
|
24888
|
+
channelName: "tracing.processor.onSpanStart",
|
|
24889
|
+
kind: "async"
|
|
24890
|
+
}),
|
|
24891
|
+
onSpanEnd: channel({
|
|
24892
|
+
channelName: "tracing.processor.onSpanEnd",
|
|
24893
|
+
kind: "async"
|
|
24894
|
+
})
|
|
24895
|
+
},
|
|
24896
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OPENAI_AGENTS }
|
|
24897
|
+
);
|
|
24083
24898
|
|
|
24084
24899
|
// src/instrumentation/plugins/openai-agents-trace-processor.ts
|
|
24085
24900
|
function isSpanData(spanData, type) {
|
|
@@ -24195,16 +25010,19 @@ var OpenAIAgentsTraceProcessor = class _OpenAIAgentsTraceProcessor {
|
|
|
24195
25010
|
this.evictOldestTrace();
|
|
24196
25011
|
}
|
|
24197
25012
|
const current = currentSpan();
|
|
24198
|
-
const
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
|
|
24203
|
-
|
|
24204
|
-
|
|
24205
|
-
|
|
24206
|
-
|
|
24207
|
-
|
|
25013
|
+
const spanArgs = withSpanInstrumentationName(
|
|
25014
|
+
{
|
|
25015
|
+
name: trace.name,
|
|
25016
|
+
type: "task" /* TASK */
|
|
25017
|
+
},
|
|
25018
|
+
INSTRUMENTATION_NAMES.OPENAI_AGENTS
|
|
25019
|
+
);
|
|
25020
|
+
const span = current && current !== NOOP_SPAN ? current.startSpan(spanArgs) : this.logger ? this.logger.startSpan(spanArgs) : startSpan(
|
|
25021
|
+
withSpanInstrumentationName(
|
|
25022
|
+
spanArgs,
|
|
25023
|
+
INSTRUMENTATION_NAMES.OPENAI_AGENTS
|
|
25024
|
+
)
|
|
25025
|
+
);
|
|
24208
25026
|
span.log({
|
|
24209
25027
|
input: "Agent workflow started",
|
|
24210
25028
|
metadata: {
|
|
@@ -24255,10 +25073,15 @@ var OpenAIAgentsTraceProcessor = class _OpenAIAgentsTraceProcessor {
|
|
|
24255
25073
|
if (!parentSpan) {
|
|
24256
25074
|
return Promise.resolve();
|
|
24257
25075
|
}
|
|
24258
|
-
const childSpan = parentSpan.startSpan(
|
|
24259
|
-
|
|
24260
|
-
|
|
24261
|
-
|
|
25076
|
+
const childSpan = parentSpan.startSpan(
|
|
25077
|
+
withSpanInstrumentationName(
|
|
25078
|
+
{
|
|
25079
|
+
name: spanNameFromAgents(span),
|
|
25080
|
+
type: spanTypeFromAgents(span)
|
|
25081
|
+
},
|
|
25082
|
+
INSTRUMENTATION_NAMES.OPENAI_AGENTS
|
|
25083
|
+
)
|
|
25084
|
+
);
|
|
24262
25085
|
traceData.childSpans.set(span.spanId, childSpan);
|
|
24263
25086
|
return Promise.resolve();
|
|
24264
25087
|
}
|
|
@@ -24523,24 +25346,28 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
|
|
|
24523
25346
|
};
|
|
24524
25347
|
|
|
24525
25348
|
// src/instrumentation/plugins/google-genai-channels.ts
|
|
24526
|
-
var googleGenAIChannels = defineChannels(
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
|
|
24533
|
-
|
|
24534
|
-
|
|
24535
|
-
|
|
24536
|
-
|
|
24537
|
-
|
|
24538
|
-
|
|
24539
|
-
|
|
24540
|
-
|
|
24541
|
-
|
|
24542
|
-
|
|
24543
|
-
|
|
25349
|
+
var googleGenAIChannels = defineChannels(
|
|
25350
|
+
"@google/genai",
|
|
25351
|
+
{
|
|
25352
|
+
generateContent: channel({
|
|
25353
|
+
channelName: "models.generateContent",
|
|
25354
|
+
kind: "async"
|
|
25355
|
+
}),
|
|
25356
|
+
generateContentStream: channel({
|
|
25357
|
+
channelName: "models.generateContentStream",
|
|
25358
|
+
kind: "async"
|
|
25359
|
+
}),
|
|
25360
|
+
embedContent: channel({
|
|
25361
|
+
channelName: "models.embedContent",
|
|
25362
|
+
kind: "async"
|
|
25363
|
+
}),
|
|
25364
|
+
interactionsCreate: channel({
|
|
25365
|
+
channelName: "interactions.create",
|
|
25366
|
+
kind: "async"
|
|
25367
|
+
})
|
|
25368
|
+
},
|
|
25369
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_GENAI }
|
|
25370
|
+
);
|
|
24544
25371
|
|
|
24545
25372
|
// src/instrumentation/plugins/google-genai-plugin.ts
|
|
24546
25373
|
var GOOGLE_GENAI_INTERNAL_CONTEXT = {
|
|
@@ -24578,13 +25405,18 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
24578
25405
|
const params = event.arguments[0];
|
|
24579
25406
|
const input = serializeGenerateContentInput(params);
|
|
24580
25407
|
const metadata = extractGenerateContentMetadata(params);
|
|
24581
|
-
const span = startSpan(
|
|
24582
|
-
|
|
24583
|
-
|
|
24584
|
-
|
|
24585
|
-
|
|
24586
|
-
|
|
24587
|
-
|
|
25408
|
+
const span = startSpan(
|
|
25409
|
+
withSpanInstrumentationName(
|
|
25410
|
+
{
|
|
25411
|
+
name: "generate_content",
|
|
25412
|
+
spanAttributes: {
|
|
25413
|
+
type: "llm" /* LLM */
|
|
25414
|
+
},
|
|
25415
|
+
event: createWrapperParityEvent({ input, metadata })
|
|
25416
|
+
},
|
|
25417
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENAI
|
|
25418
|
+
)
|
|
25419
|
+
);
|
|
24588
25420
|
return {
|
|
24589
25421
|
span,
|
|
24590
25422
|
startTime: getCurrentUnixTimestamp()
|
|
@@ -24597,13 +25429,18 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
24597
25429
|
const params = event.arguments[0];
|
|
24598
25430
|
const input = serializeGenerateContentInput(params);
|
|
24599
25431
|
const metadata = extractGenerateContentMetadata(params);
|
|
24600
|
-
const span = startSpan(
|
|
24601
|
-
|
|
24602
|
-
|
|
24603
|
-
|
|
24604
|
-
|
|
24605
|
-
|
|
24606
|
-
|
|
25432
|
+
const span = startSpan(
|
|
25433
|
+
withSpanInstrumentationName(
|
|
25434
|
+
{
|
|
25435
|
+
name: "generate_content",
|
|
25436
|
+
spanAttributes: {
|
|
25437
|
+
type: "llm" /* LLM */
|
|
25438
|
+
},
|
|
25439
|
+
event: createWrapperParityEvent({ input, metadata })
|
|
25440
|
+
},
|
|
25441
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENAI
|
|
25442
|
+
)
|
|
25443
|
+
);
|
|
24607
25444
|
return {
|
|
24608
25445
|
span,
|
|
24609
25446
|
startTime: getCurrentUnixTimestamp()
|
|
@@ -24679,13 +25516,18 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
24679
25516
|
const params = event.arguments[0];
|
|
24680
25517
|
const input = serializeEmbedContentInput(params);
|
|
24681
25518
|
const metadata = extractEmbedContentMetadata(params);
|
|
24682
|
-
const span = startSpan(
|
|
24683
|
-
|
|
24684
|
-
|
|
24685
|
-
|
|
24686
|
-
|
|
24687
|
-
|
|
24688
|
-
|
|
25519
|
+
const span = startSpan(
|
|
25520
|
+
withSpanInstrumentationName(
|
|
25521
|
+
{
|
|
25522
|
+
name: "embed_content",
|
|
25523
|
+
spanAttributes: {
|
|
25524
|
+
type: "llm" /* LLM */
|
|
25525
|
+
},
|
|
25526
|
+
event: createWrapperParityEvent({ input, metadata })
|
|
25527
|
+
},
|
|
25528
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENAI
|
|
25529
|
+
)
|
|
25530
|
+
);
|
|
24689
25531
|
return {
|
|
24690
25532
|
span,
|
|
24691
25533
|
startTime: getCurrentUnixTimestamp()
|
|
@@ -24698,13 +25540,18 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
24698
25540
|
const params = event.arguments[0];
|
|
24699
25541
|
const input = serializeEmbedContentInput(params);
|
|
24700
25542
|
const metadata = extractEmbedContentMetadata(params);
|
|
24701
|
-
const span = startSpan(
|
|
24702
|
-
|
|
24703
|
-
|
|
24704
|
-
|
|
24705
|
-
|
|
24706
|
-
|
|
24707
|
-
|
|
25543
|
+
const span = startSpan(
|
|
25544
|
+
withSpanInstrumentationName(
|
|
25545
|
+
{
|
|
25546
|
+
name: "embed_content",
|
|
25547
|
+
spanAttributes: {
|
|
25548
|
+
type: "llm" /* LLM */
|
|
25549
|
+
},
|
|
25550
|
+
event: createWrapperParityEvent({ input, metadata })
|
|
25551
|
+
},
|
|
25552
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENAI
|
|
25553
|
+
)
|
|
25554
|
+
);
|
|
24708
25555
|
return {
|
|
24709
25556
|
span,
|
|
24710
25557
|
startTime: getCurrentUnixTimestamp()
|
|
@@ -24815,16 +25662,21 @@ function patchGoogleGenAIStreamingResult(args) {
|
|
|
24815
25662
|
const requestStartTime = startTime ?? getCurrentUnixTimestamp();
|
|
24816
25663
|
const ensureSpan = () => {
|
|
24817
25664
|
if (!span) {
|
|
24818
|
-
span = startSpan(
|
|
24819
|
-
|
|
24820
|
-
|
|
24821
|
-
|
|
24822
|
-
|
|
24823
|
-
|
|
24824
|
-
|
|
24825
|
-
|
|
24826
|
-
|
|
24827
|
-
|
|
25665
|
+
span = startSpan(
|
|
25666
|
+
withSpanInstrumentationName(
|
|
25667
|
+
{
|
|
25668
|
+
name: "generate_content_stream",
|
|
25669
|
+
spanAttributes: {
|
|
25670
|
+
type: "llm" /* LLM */
|
|
25671
|
+
},
|
|
25672
|
+
event: {
|
|
25673
|
+
input,
|
|
25674
|
+
metadata
|
|
25675
|
+
}
|
|
25676
|
+
},
|
|
25677
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENAI
|
|
25678
|
+
)
|
|
25679
|
+
);
|
|
24828
25680
|
}
|
|
24829
25681
|
return span;
|
|
24830
25682
|
};
|
|
@@ -25592,28 +26444,32 @@ function tryToDict(obj) {
|
|
|
25592
26444
|
}
|
|
25593
26445
|
|
|
25594
26446
|
// src/instrumentation/plugins/huggingface-channels.ts
|
|
25595
|
-
var huggingFaceChannels = defineChannels(
|
|
25596
|
-
|
|
25597
|
-
|
|
25598
|
-
|
|
25599
|
-
|
|
25600
|
-
|
|
25601
|
-
|
|
25602
|
-
|
|
25603
|
-
|
|
25604
|
-
|
|
25605
|
-
|
|
25606
|
-
|
|
25607
|
-
|
|
25608
|
-
|
|
25609
|
-
|
|
25610
|
-
|
|
25611
|
-
|
|
25612
|
-
|
|
25613
|
-
|
|
25614
|
-
|
|
25615
|
-
|
|
25616
|
-
|
|
26447
|
+
var huggingFaceChannels = defineChannels(
|
|
26448
|
+
"@huggingface/inference",
|
|
26449
|
+
{
|
|
26450
|
+
chatCompletion: channel({
|
|
26451
|
+
channelName: "chatCompletion",
|
|
26452
|
+
kind: "async"
|
|
26453
|
+
}),
|
|
26454
|
+
chatCompletionStream: channel({
|
|
26455
|
+
channelName: "chatCompletionStream",
|
|
26456
|
+
kind: "sync-stream"
|
|
26457
|
+
}),
|
|
26458
|
+
textGeneration: channel({
|
|
26459
|
+
channelName: "textGeneration",
|
|
26460
|
+
kind: "async"
|
|
26461
|
+
}),
|
|
26462
|
+
textGenerationStream: channel({
|
|
26463
|
+
channelName: "textGenerationStream",
|
|
26464
|
+
kind: "sync-stream"
|
|
26465
|
+
}),
|
|
26466
|
+
featureExtraction: channel({
|
|
26467
|
+
channelName: "featureExtraction",
|
|
26468
|
+
kind: "async"
|
|
26469
|
+
})
|
|
26470
|
+
},
|
|
26471
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.HUGGINGFACE }
|
|
26472
|
+
);
|
|
25617
26473
|
|
|
25618
26474
|
// src/instrumentation/plugins/huggingface-plugin.ts
|
|
25619
26475
|
var REQUEST_METADATA_ALLOWLIST = /* @__PURE__ */ new Set([
|
|
@@ -26040,20 +26896,24 @@ function extractTextGenerationStreamMetadata(chunks) {
|
|
|
26040
26896
|
}
|
|
26041
26897
|
|
|
26042
26898
|
// src/instrumentation/plugins/openrouter-agent-channels.ts
|
|
26043
|
-
var openRouterAgentChannels = defineChannels(
|
|
26044
|
-
|
|
26045
|
-
|
|
26046
|
-
|
|
26047
|
-
|
|
26048
|
-
|
|
26049
|
-
|
|
26050
|
-
|
|
26051
|
-
|
|
26052
|
-
|
|
26053
|
-
|
|
26054
|
-
|
|
26055
|
-
|
|
26056
|
-
|
|
26899
|
+
var openRouterAgentChannels = defineChannels(
|
|
26900
|
+
"@openrouter/agent",
|
|
26901
|
+
{
|
|
26902
|
+
callModel: channel({
|
|
26903
|
+
channelName: "callModel",
|
|
26904
|
+
kind: "sync-stream"
|
|
26905
|
+
}),
|
|
26906
|
+
callModelTurn: channel({
|
|
26907
|
+
channelName: "callModel.turn",
|
|
26908
|
+
kind: "async"
|
|
26909
|
+
}),
|
|
26910
|
+
toolExecute: channel({
|
|
26911
|
+
channelName: "tool.execute",
|
|
26912
|
+
kind: "async"
|
|
26913
|
+
})
|
|
26914
|
+
},
|
|
26915
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OPENROUTER_AGENT }
|
|
26916
|
+
);
|
|
26057
26917
|
|
|
26058
26918
|
// src/instrumentation/plugins/openrouter-agent-plugin.ts
|
|
26059
26919
|
var OpenRouterAgentPlugin = class extends BasePlugin {
|
|
@@ -26823,38 +27683,40 @@ function normalizeError(error2) {
|
|
|
26823
27683
|
}
|
|
26824
27684
|
|
|
26825
27685
|
// src/instrumentation/plugins/openrouter-channels.ts
|
|
26826
|
-
var openRouterChannels = defineChannels(
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
26831
|
-
|
|
26832
|
-
|
|
26833
|
-
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
|
|
27686
|
+
var openRouterChannels = defineChannels(
|
|
27687
|
+
"@openrouter/sdk",
|
|
27688
|
+
{
|
|
27689
|
+
chatSend: channel({
|
|
27690
|
+
channelName: "chat.send",
|
|
27691
|
+
kind: "async"
|
|
27692
|
+
}),
|
|
27693
|
+
embeddingsGenerate: channel({
|
|
27694
|
+
channelName: "embeddings.generate",
|
|
27695
|
+
kind: "async"
|
|
27696
|
+
}),
|
|
27697
|
+
rerankRerank: channel({
|
|
26837
27698
|
channelName: "rerank.rerank",
|
|
26838
27699
|
kind: "async"
|
|
26839
|
-
}
|
|
26840
|
-
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
26845
|
-
|
|
26846
|
-
|
|
26847
|
-
|
|
26848
|
-
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26855
|
-
|
|
26856
|
-
}
|
|
26857
|
-
}
|
|
27700
|
+
}),
|
|
27701
|
+
betaResponsesSend: channel({
|
|
27702
|
+
channelName: "beta.responses.send",
|
|
27703
|
+
kind: "async"
|
|
27704
|
+
}),
|
|
27705
|
+
callModel: channel({
|
|
27706
|
+
channelName: "callModel",
|
|
27707
|
+
kind: "sync-stream"
|
|
27708
|
+
}),
|
|
27709
|
+
callModelTurn: channel({
|
|
27710
|
+
channelName: "callModel.turn",
|
|
27711
|
+
kind: "async"
|
|
27712
|
+
}),
|
|
27713
|
+
toolExecute: channel({
|
|
27714
|
+
channelName: "tool.execute",
|
|
27715
|
+
kind: "async"
|
|
27716
|
+
})
|
|
27717
|
+
},
|
|
27718
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OPENROUTER }
|
|
27719
|
+
);
|
|
26858
27720
|
|
|
26859
27721
|
// src/instrumentation/plugins/openrouter-plugin.ts
|
|
26860
27722
|
var OpenRouterPlugin = class extends BasePlugin {
|
|
@@ -27894,52 +28756,56 @@ function normalizeError2(error2) {
|
|
|
27894
28756
|
}
|
|
27895
28757
|
|
|
27896
28758
|
// src/instrumentation/plugins/mistral-channels.ts
|
|
27897
|
-
var mistralChannels = defineChannels(
|
|
27898
|
-
|
|
27899
|
-
|
|
27900
|
-
|
|
27901
|
-
|
|
27902
|
-
|
|
27903
|
-
|
|
27904
|
-
|
|
27905
|
-
|
|
27906
|
-
|
|
27907
|
-
|
|
27908
|
-
|
|
27909
|
-
|
|
27910
|
-
|
|
27911
|
-
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
|
|
27915
|
-
|
|
27916
|
-
|
|
27917
|
-
|
|
27918
|
-
|
|
27919
|
-
|
|
27920
|
-
|
|
27921
|
-
|
|
27922
|
-
|
|
27923
|
-
|
|
27924
|
-
|
|
27925
|
-
|
|
27926
|
-
|
|
27927
|
-
|
|
27928
|
-
|
|
27929
|
-
|
|
27930
|
-
|
|
27931
|
-
|
|
27932
|
-
|
|
27933
|
-
|
|
27934
|
-
|
|
27935
|
-
|
|
27936
|
-
|
|
27937
|
-
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
28759
|
+
var mistralChannels = defineChannels(
|
|
28760
|
+
"@mistralai/mistralai",
|
|
28761
|
+
{
|
|
28762
|
+
chatComplete: channel({
|
|
28763
|
+
channelName: "chat.complete",
|
|
28764
|
+
kind: "async"
|
|
28765
|
+
}),
|
|
28766
|
+
chatStream: channel({
|
|
28767
|
+
channelName: "chat.stream",
|
|
28768
|
+
kind: "async"
|
|
28769
|
+
}),
|
|
28770
|
+
embeddingsCreate: channel({
|
|
28771
|
+
channelName: "embeddings.create",
|
|
28772
|
+
kind: "async"
|
|
28773
|
+
}),
|
|
28774
|
+
classifiersModerate: channel({
|
|
28775
|
+
channelName: "classifiers.moderate",
|
|
28776
|
+
kind: "async"
|
|
28777
|
+
}),
|
|
28778
|
+
classifiersModerateChat: channel({
|
|
28779
|
+
channelName: "classifiers.moderateChat",
|
|
28780
|
+
kind: "async"
|
|
28781
|
+
}),
|
|
28782
|
+
classifiersClassify: channel({
|
|
28783
|
+
channelName: "classifiers.classify",
|
|
28784
|
+
kind: "async"
|
|
28785
|
+
}),
|
|
28786
|
+
classifiersClassifyChat: channel({
|
|
28787
|
+
channelName: "classifiers.classifyChat",
|
|
28788
|
+
kind: "async"
|
|
28789
|
+
}),
|
|
28790
|
+
fimComplete: channel({
|
|
28791
|
+
channelName: "fim.complete",
|
|
28792
|
+
kind: "async"
|
|
28793
|
+
}),
|
|
28794
|
+
fimStream: channel({
|
|
28795
|
+
channelName: "fim.stream",
|
|
28796
|
+
kind: "async"
|
|
28797
|
+
}),
|
|
28798
|
+
agentsComplete: channel({
|
|
28799
|
+
channelName: "agents.complete",
|
|
28800
|
+
kind: "async"
|
|
28801
|
+
}),
|
|
28802
|
+
agentsStream: channel({
|
|
28803
|
+
channelName: "agents.stream",
|
|
28804
|
+
kind: "async"
|
|
28805
|
+
})
|
|
28806
|
+
},
|
|
28807
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.MISTRAL }
|
|
28808
|
+
);
|
|
27943
28809
|
|
|
27944
28810
|
// src/instrumentation/plugins/mistral-plugin.ts
|
|
27945
28811
|
var MistralPlugin = class extends BasePlugin {
|
|
@@ -28559,20 +29425,24 @@ function aggregateMistralStreamChunks(chunks) {
|
|
|
28559
29425
|
}
|
|
28560
29426
|
|
|
28561
29427
|
// src/instrumentation/plugins/google-adk-channels.ts
|
|
28562
|
-
var googleADKChannels = defineChannels(
|
|
28563
|
-
|
|
28564
|
-
|
|
28565
|
-
|
|
28566
|
-
|
|
28567
|
-
|
|
28568
|
-
|
|
28569
|
-
|
|
28570
|
-
|
|
28571
|
-
|
|
28572
|
-
|
|
28573
|
-
|
|
28574
|
-
|
|
28575
|
-
|
|
29428
|
+
var googleADKChannels = defineChannels(
|
|
29429
|
+
"@google/adk",
|
|
29430
|
+
{
|
|
29431
|
+
runnerRunAsync: channel({
|
|
29432
|
+
channelName: "runner.runAsync",
|
|
29433
|
+
kind: "sync-stream"
|
|
29434
|
+
}),
|
|
29435
|
+
agentRunAsync: channel({
|
|
29436
|
+
channelName: "agent.runAsync",
|
|
29437
|
+
kind: "sync-stream"
|
|
29438
|
+
}),
|
|
29439
|
+
toolRunAsync: channel({
|
|
29440
|
+
channelName: "tool.runAsync",
|
|
29441
|
+
kind: "async"
|
|
29442
|
+
})
|
|
29443
|
+
},
|
|
29444
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_ADK }
|
|
29445
|
+
);
|
|
28576
29446
|
|
|
28577
29447
|
// src/instrumentation/plugins/google-adk-plugin.ts
|
|
28578
29448
|
var GoogleADKPlugin = class extends BasePlugin {
|
|
@@ -28597,12 +29467,17 @@ var GoogleADKPlugin = class extends BasePlugin {
|
|
|
28597
29467
|
const createState = (event) => {
|
|
28598
29468
|
const params = event.arguments[0] ?? {};
|
|
28599
29469
|
const contextKey = extractRunnerContextKey(params);
|
|
28600
|
-
const span = startSpan(
|
|
28601
|
-
|
|
28602
|
-
|
|
28603
|
-
|
|
28604
|
-
|
|
28605
|
-
|
|
29470
|
+
const span = startSpan(
|
|
29471
|
+
withSpanInstrumentationName(
|
|
29472
|
+
{
|
|
29473
|
+
name: "Google ADK Runner",
|
|
29474
|
+
spanAttributes: {
|
|
29475
|
+
type: "task" /* TASK */
|
|
29476
|
+
}
|
|
29477
|
+
},
|
|
29478
|
+
INSTRUMENTATION_NAMES.GOOGLE_ADK
|
|
29479
|
+
)
|
|
29480
|
+
);
|
|
28606
29481
|
const startTime = getCurrentUnixTimestamp();
|
|
28607
29482
|
try {
|
|
28608
29483
|
const metadata = extractRunnerMetadata(params);
|
|
@@ -28688,18 +29563,23 @@ var GoogleADKPlugin = class extends BasePlugin {
|
|
|
28688
29563
|
this.activeRunnerSpans
|
|
28689
29564
|
);
|
|
28690
29565
|
const contextKey = extractInvocationContextKey(parentContext);
|
|
28691
|
-
const span = startSpan(
|
|
28692
|
-
|
|
28693
|
-
|
|
28694
|
-
|
|
28695
|
-
|
|
28696
|
-
|
|
28697
|
-
|
|
28698
|
-
|
|
28699
|
-
|
|
28700
|
-
|
|
28701
|
-
|
|
28702
|
-
|
|
29566
|
+
const span = startSpan(
|
|
29567
|
+
withSpanInstrumentationName(
|
|
29568
|
+
{
|
|
29569
|
+
name: agentName ? `Agent: ${agentName}` : "Google ADK Agent",
|
|
29570
|
+
spanAttributes: {
|
|
29571
|
+
type: "task" /* TASK */
|
|
29572
|
+
},
|
|
29573
|
+
...runnerParentSpan ? {
|
|
29574
|
+
parentSpanIds: {
|
|
29575
|
+
spanId: runnerParentSpan.spanId,
|
|
29576
|
+
rootSpanId: runnerParentSpan.rootSpanId
|
|
29577
|
+
}
|
|
29578
|
+
} : {}
|
|
29579
|
+
},
|
|
29580
|
+
INSTRUMENTATION_NAMES.GOOGLE_ADK
|
|
29581
|
+
)
|
|
29582
|
+
);
|
|
28703
29583
|
const startTime = getCurrentUnixTimestamp();
|
|
28704
29584
|
try {
|
|
28705
29585
|
const metadata = {
|
|
@@ -28792,22 +29672,27 @@ var GoogleADKPlugin = class extends BasePlugin {
|
|
|
28792
29672
|
this.activeAgentSpans,
|
|
28793
29673
|
this.activeRunnerSpans
|
|
28794
29674
|
);
|
|
28795
|
-
const createSpan = () => startSpan(
|
|
28796
|
-
|
|
28797
|
-
|
|
28798
|
-
|
|
28799
|
-
|
|
28800
|
-
|
|
28801
|
-
|
|
28802
|
-
|
|
28803
|
-
|
|
28804
|
-
|
|
28805
|
-
|
|
28806
|
-
|
|
29675
|
+
const createSpan = () => startSpan(
|
|
29676
|
+
withSpanInstrumentationName(
|
|
29677
|
+
{
|
|
29678
|
+
name: toolName ? `tool: ${toolName}` : "Google ADK Tool",
|
|
29679
|
+
spanAttributes: {
|
|
29680
|
+
type: "tool" /* TOOL */
|
|
29681
|
+
},
|
|
29682
|
+
event: {
|
|
29683
|
+
input: req.args,
|
|
29684
|
+
metadata: {
|
|
29685
|
+
provider: "google-adk",
|
|
29686
|
+
...toolName && { "google_adk.tool_name": toolName },
|
|
29687
|
+
...extractToolCallId(req) && {
|
|
29688
|
+
"google_adk.tool_call_id": extractToolCallId(req)
|
|
29689
|
+
}
|
|
29690
|
+
}
|
|
28807
29691
|
}
|
|
28808
|
-
}
|
|
28809
|
-
|
|
28810
|
-
|
|
29692
|
+
},
|
|
29693
|
+
INSTRUMENTATION_NAMES.GOOGLE_ADK
|
|
29694
|
+
)
|
|
29695
|
+
);
|
|
28811
29696
|
const span = parentSpan ? withCurrent(parentSpan, () => createSpan()) : createSpan();
|
|
28812
29697
|
const startTime = getCurrentUnixTimestamp();
|
|
28813
29698
|
states.set(event, { span, startTime });
|
|
@@ -29206,24 +30091,28 @@ function cleanMetrics4(metrics) {
|
|
|
29206
30091
|
}
|
|
29207
30092
|
|
|
29208
30093
|
// src/instrumentation/plugins/cohere-channels.ts
|
|
29209
|
-
var cohereChannels = defineChannels(
|
|
29210
|
-
|
|
29211
|
-
|
|
29212
|
-
|
|
29213
|
-
|
|
29214
|
-
|
|
29215
|
-
|
|
29216
|
-
|
|
29217
|
-
|
|
29218
|
-
|
|
29219
|
-
|
|
29220
|
-
|
|
29221
|
-
|
|
29222
|
-
|
|
29223
|
-
|
|
29224
|
-
|
|
29225
|
-
|
|
29226
|
-
|
|
30094
|
+
var cohereChannels = defineChannels(
|
|
30095
|
+
"cohere-ai",
|
|
30096
|
+
{
|
|
30097
|
+
chat: channel({
|
|
30098
|
+
channelName: "chat",
|
|
30099
|
+
kind: "async"
|
|
30100
|
+
}),
|
|
30101
|
+
chatStream: channel({
|
|
30102
|
+
channelName: "chatStream",
|
|
30103
|
+
kind: "async"
|
|
30104
|
+
}),
|
|
30105
|
+
embed: channel({
|
|
30106
|
+
channelName: "embed",
|
|
30107
|
+
kind: "async"
|
|
30108
|
+
}),
|
|
30109
|
+
rerank: channel({
|
|
30110
|
+
channelName: "rerank",
|
|
30111
|
+
kind: "async"
|
|
30112
|
+
})
|
|
30113
|
+
},
|
|
30114
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.COHERE }
|
|
30115
|
+
);
|
|
29227
30116
|
|
|
29228
30117
|
// src/instrumentation/plugins/cohere-plugin.ts
|
|
29229
30118
|
var CoherePlugin = class extends BasePlugin {
|
|
@@ -29892,18 +30781,20 @@ function aggregateCohereChatStreamChunks(chunks) {
|
|
|
29892
30781
|
}
|
|
29893
30782
|
|
|
29894
30783
|
// src/instrumentation/plugins/groq-channels.ts
|
|
29895
|
-
var groqChannels = defineChannels(
|
|
29896
|
-
|
|
29897
|
-
|
|
29898
|
-
|
|
29899
|
-
|
|
29900
|
-
|
|
29901
|
-
|
|
30784
|
+
var groqChannels = defineChannels(
|
|
30785
|
+
"groq-sdk",
|
|
30786
|
+
{
|
|
30787
|
+
chatCompletionsCreate: channel({
|
|
30788
|
+
channelName: "chat.completions.create",
|
|
30789
|
+
kind: "async"
|
|
30790
|
+
}),
|
|
30791
|
+
embeddingsCreate: channel({
|
|
29902
30792
|
channelName: "embeddings.create",
|
|
29903
30793
|
kind: "async"
|
|
29904
|
-
}
|
|
29905
|
-
|
|
29906
|
-
}
|
|
30794
|
+
})
|
|
30795
|
+
},
|
|
30796
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GROQ }
|
|
30797
|
+
);
|
|
29907
30798
|
|
|
29908
30799
|
// src/instrumentation/plugins/groq-plugin.ts
|
|
29909
30800
|
var GroqPlugin = class extends BasePlugin {
|
|
@@ -30006,15 +30897,27 @@ var clientSendChannel = channel({
|
|
|
30006
30897
|
channelName: "client.send",
|
|
30007
30898
|
kind: "async"
|
|
30008
30899
|
});
|
|
30009
|
-
var bedrockRuntimeChannels = defineChannels(
|
|
30010
|
-
|
|
30011
|
-
|
|
30012
|
-
|
|
30013
|
-
|
|
30014
|
-
}
|
|
30015
|
-
|
|
30016
|
-
|
|
30017
|
-
|
|
30900
|
+
var bedrockRuntimeChannels = defineChannels(
|
|
30901
|
+
"aws-bedrock-runtime",
|
|
30902
|
+
{
|
|
30903
|
+
clientSend: clientSendChannel
|
|
30904
|
+
},
|
|
30905
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.BEDROCK_RUNTIME }
|
|
30906
|
+
);
|
|
30907
|
+
var smithyCoreChannels = defineChannels(
|
|
30908
|
+
"@smithy/core",
|
|
30909
|
+
{
|
|
30910
|
+
clientSend: clientSendChannel
|
|
30911
|
+
},
|
|
30912
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.BEDROCK_RUNTIME }
|
|
30913
|
+
);
|
|
30914
|
+
var smithyClientChannels = defineChannels(
|
|
30915
|
+
"@smithy/smithy-client",
|
|
30916
|
+
{
|
|
30917
|
+
clientSend: clientSendChannel
|
|
30918
|
+
},
|
|
30919
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.BEDROCK_RUNTIME }
|
|
30920
|
+
);
|
|
30018
30921
|
|
|
30019
30922
|
// src/instrumentation/plugins/bedrock-runtime-common.ts
|
|
30020
30923
|
var BEDROCK_RUNTIME_COMMAND_OPERATIONS = {
|
|
@@ -30648,38 +31551,46 @@ function extractTextFromJsonLike(value) {
|
|
|
30648
31551
|
}
|
|
30649
31552
|
|
|
30650
31553
|
// src/instrumentation/plugins/genkit-channels.ts
|
|
30651
|
-
var genkitChannels = defineChannels(
|
|
30652
|
-
|
|
30653
|
-
|
|
30654
|
-
|
|
30655
|
-
|
|
30656
|
-
|
|
30657
|
-
|
|
30658
|
-
|
|
30659
|
-
|
|
30660
|
-
|
|
30661
|
-
|
|
30662
|
-
|
|
30663
|
-
|
|
30664
|
-
|
|
30665
|
-
|
|
30666
|
-
|
|
30667
|
-
|
|
30668
|
-
|
|
30669
|
-
|
|
30670
|
-
|
|
30671
|
-
|
|
30672
|
-
|
|
30673
|
-
|
|
30674
|
-
|
|
30675
|
-
|
|
30676
|
-
|
|
30677
|
-
|
|
30678
|
-
|
|
30679
|
-
|
|
30680
|
-
|
|
30681
|
-
|
|
30682
|
-
|
|
31554
|
+
var genkitChannels = defineChannels(
|
|
31555
|
+
"@genkit-ai/ai",
|
|
31556
|
+
{
|
|
31557
|
+
generate: channel({
|
|
31558
|
+
channelName: "generate",
|
|
31559
|
+
kind: "async"
|
|
31560
|
+
}),
|
|
31561
|
+
generateStream: channel({
|
|
31562
|
+
channelName: "generateStream",
|
|
31563
|
+
kind: "sync-stream"
|
|
31564
|
+
}),
|
|
31565
|
+
embed: channel({
|
|
31566
|
+
channelName: "embed",
|
|
31567
|
+
kind: "async"
|
|
31568
|
+
}),
|
|
31569
|
+
embedMany: channel({
|
|
31570
|
+
channelName: "embedMany",
|
|
31571
|
+
kind: "async"
|
|
31572
|
+
}),
|
|
31573
|
+
actionRun: channel({
|
|
31574
|
+
channelName: "action.run",
|
|
31575
|
+
kind: "async"
|
|
31576
|
+
}),
|
|
31577
|
+
actionStream: channel({
|
|
31578
|
+
channelName: "action.stream",
|
|
31579
|
+
kind: "sync-stream"
|
|
31580
|
+
})
|
|
31581
|
+
},
|
|
31582
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GENKIT }
|
|
31583
|
+
);
|
|
31584
|
+
var genkitCoreChannels = defineChannels(
|
|
31585
|
+
"@genkit-ai/core",
|
|
31586
|
+
{
|
|
31587
|
+
actionSpan: channel({
|
|
31588
|
+
channelName: "action.span",
|
|
31589
|
+
kind: "async"
|
|
31590
|
+
})
|
|
31591
|
+
},
|
|
31592
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GENKIT }
|
|
31593
|
+
);
|
|
30683
31594
|
|
|
30684
31595
|
// src/instrumentation/plugins/genkit-plugin.ts
|
|
30685
31596
|
var GenkitPlugin = class extends BasePlugin {
|
|
@@ -30864,12 +31775,17 @@ function startActionSpanState(args) {
|
|
|
30864
31775
|
if (!shouldTraceAction(args.metadata, args.runStepName)) {
|
|
30865
31776
|
return void 0;
|
|
30866
31777
|
}
|
|
30867
|
-
const span = startSpan(
|
|
30868
|
-
|
|
30869
|
-
|
|
30870
|
-
|
|
30871
|
-
|
|
30872
|
-
|
|
31778
|
+
const span = startSpan(
|
|
31779
|
+
withSpanInstrumentationName(
|
|
31780
|
+
{
|
|
31781
|
+
name: actionSpanName(args.metadata, args.runStepName),
|
|
31782
|
+
spanAttributes: {
|
|
31783
|
+
type: actionSpanType(args.metadata)
|
|
31784
|
+
}
|
|
31785
|
+
},
|
|
31786
|
+
INSTRUMENTATION_NAMES.GENKIT
|
|
31787
|
+
)
|
|
31788
|
+
);
|
|
30873
31789
|
const startTime = getCurrentUnixTimestamp();
|
|
30874
31790
|
span.log({
|
|
30875
31791
|
input: args.input,
|
|
@@ -31230,20 +32146,24 @@ function stringValue(value) {
|
|
|
31230
32146
|
}
|
|
31231
32147
|
|
|
31232
32148
|
// src/instrumentation/plugins/github-copilot-channels.ts
|
|
31233
|
-
var gitHubCopilotChannels = defineChannels(
|
|
31234
|
-
|
|
31235
|
-
|
|
31236
|
-
|
|
31237
|
-
|
|
31238
|
-
|
|
31239
|
-
|
|
31240
|
-
|
|
31241
|
-
|
|
31242
|
-
|
|
31243
|
-
|
|
31244
|
-
|
|
31245
|
-
|
|
31246
|
-
|
|
32149
|
+
var gitHubCopilotChannels = defineChannels(
|
|
32150
|
+
"@github/copilot-sdk",
|
|
32151
|
+
{
|
|
32152
|
+
createSession: channel({
|
|
32153
|
+
channelName: "client.createSession",
|
|
32154
|
+
kind: "async"
|
|
32155
|
+
}),
|
|
32156
|
+
resumeSession: channel({
|
|
32157
|
+
channelName: "client.resumeSession",
|
|
32158
|
+
kind: "async"
|
|
32159
|
+
}),
|
|
32160
|
+
sendAndWait: channel({
|
|
32161
|
+
channelName: "session.sendAndWait",
|
|
32162
|
+
kind: "async"
|
|
32163
|
+
})
|
|
32164
|
+
},
|
|
32165
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GITHUB_COPILOT }
|
|
32166
|
+
);
|
|
31247
32167
|
|
|
31248
32168
|
// src/instrumentation/plugins/github-copilot-plugin.ts
|
|
31249
32169
|
var ROOT_AGENT_KEY = "__root__";
|
|
@@ -31334,11 +32254,16 @@ async function handleTurnStart(state, agentId) {
|
|
|
31334
32254
|
return;
|
|
31335
32255
|
}
|
|
31336
32256
|
const parentId = await getParentIdForAgent(state, agentId);
|
|
31337
|
-
const span = startSpan(
|
|
31338
|
-
|
|
31339
|
-
|
|
31340
|
-
|
|
31341
|
-
|
|
32257
|
+
const span = startSpan(
|
|
32258
|
+
withSpanInstrumentationName(
|
|
32259
|
+
{
|
|
32260
|
+
name: "Copilot Turn",
|
|
32261
|
+
parent: parentId,
|
|
32262
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
32263
|
+
},
|
|
32264
|
+
INSTRUMENTATION_NAMES.GITHUB_COPILOT
|
|
32265
|
+
)
|
|
32266
|
+
);
|
|
31342
32267
|
const pendingUserMessage = state.pendingUserMessages.get(key);
|
|
31343
32268
|
if (pendingUserMessage) {
|
|
31344
32269
|
span.log({ input: pendingUserMessage });
|
|
@@ -31369,11 +32294,16 @@ async function handleUsage(state, agentId, usage) {
|
|
|
31369
32294
|
const parentId = turn ? await turn.id : await state.session.id;
|
|
31370
32295
|
const content = state.currentMessageContent.get(key);
|
|
31371
32296
|
const { metrics, metadata } = extractMetricsFromUsage(usage);
|
|
31372
|
-
const llmSpan = startSpan(
|
|
31373
|
-
|
|
31374
|
-
|
|
31375
|
-
|
|
31376
|
-
|
|
32297
|
+
const llmSpan = startSpan(
|
|
32298
|
+
withSpanInstrumentationName(
|
|
32299
|
+
{
|
|
32300
|
+
name: "github.copilot.llm",
|
|
32301
|
+
parent: parentId,
|
|
32302
|
+
spanAttributes: { type: "llm" /* LLM */ }
|
|
32303
|
+
},
|
|
32304
|
+
INSTRUMENTATION_NAMES.GITHUB_COPILOT
|
|
32305
|
+
)
|
|
32306
|
+
);
|
|
31377
32307
|
llmSpan.log({
|
|
31378
32308
|
output: content ?? void 0,
|
|
31379
32309
|
metadata,
|
|
@@ -31399,11 +32329,16 @@ async function handleToolStart(state, agentId, toolCallId, toolName, args, mcpSe
|
|
|
31399
32329
|
}
|
|
31400
32330
|
const parentId = await getToolParentId(state, agentId);
|
|
31401
32331
|
const displayName = mcpServerName ? `tool: ${mcpServerName}/${toolName}` : `tool: ${toolName}`;
|
|
31402
|
-
const span = startSpan(
|
|
31403
|
-
|
|
31404
|
-
|
|
31405
|
-
|
|
31406
|
-
|
|
32332
|
+
const span = startSpan(
|
|
32333
|
+
withSpanInstrumentationName(
|
|
32334
|
+
{
|
|
32335
|
+
name: displayName,
|
|
32336
|
+
parent: parentId,
|
|
32337
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
32338
|
+
},
|
|
32339
|
+
INSTRUMENTATION_NAMES.GITHUB_COPILOT
|
|
32340
|
+
)
|
|
32341
|
+
);
|
|
31407
32342
|
const metadata = {
|
|
31408
32343
|
"gen_ai.tool.name": toolName,
|
|
31409
32344
|
"gen_ai.tool.call.id": toolCallId
|
|
@@ -31439,11 +32374,16 @@ async function handleSubagentStarted(state, agentId, toolCallId, agentDisplayNam
|
|
|
31439
32374
|
}
|
|
31440
32375
|
const tool = state.activeTools.get(toolCallId);
|
|
31441
32376
|
const parentId = tool ? await tool.id : await state.session.id;
|
|
31442
|
-
const span = startSpan(
|
|
31443
|
-
|
|
31444
|
-
|
|
31445
|
-
|
|
31446
|
-
|
|
32377
|
+
const span = startSpan(
|
|
32378
|
+
withSpanInstrumentationName(
|
|
32379
|
+
{
|
|
32380
|
+
name: `Agent: ${agentDisplayName}`,
|
|
32381
|
+
parent: parentId,
|
|
32382
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
32383
|
+
},
|
|
32384
|
+
INSTRUMENTATION_NAMES.GITHUB_COPILOT
|
|
32385
|
+
)
|
|
32386
|
+
);
|
|
31447
32387
|
span.log({
|
|
31448
32388
|
metadata: {
|
|
31449
32389
|
"github_copilot.agent_name": agentDisplayName,
|
|
@@ -31669,10 +32609,15 @@ function makeSessionHandlers(sessionStates, configArgIndex, includeProviderMetad
|
|
|
31669
32609
|
if (!config3 || typeof config3 !== "object") {
|
|
31670
32610
|
return;
|
|
31671
32611
|
}
|
|
31672
|
-
const sessionSpan = startSpan(
|
|
31673
|
-
|
|
31674
|
-
|
|
31675
|
-
|
|
32612
|
+
const sessionSpan = startSpan(
|
|
32613
|
+
withSpanInstrumentationName(
|
|
32614
|
+
{
|
|
32615
|
+
name: "Copilot Session",
|
|
32616
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
32617
|
+
},
|
|
32618
|
+
INSTRUMENTATION_NAMES.GITHUB_COPILOT
|
|
32619
|
+
)
|
|
32620
|
+
);
|
|
31676
32621
|
const metadata = {};
|
|
31677
32622
|
if (config3.model) {
|
|
31678
32623
|
metadata["github_copilot.model"] = config3.model;
|
|
@@ -31760,12 +32705,16 @@ var GitHubCopilotPlugin = class extends BasePlugin {
|
|
|
31760
32705
|
};
|
|
31761
32706
|
|
|
31762
32707
|
// src/instrumentation/plugins/flue-channels.ts
|
|
31763
|
-
var flueChannels = defineChannels(
|
|
31764
|
-
|
|
31765
|
-
|
|
31766
|
-
|
|
31767
|
-
|
|
31768
|
-
|
|
32708
|
+
var flueChannels = defineChannels(
|
|
32709
|
+
"@flue/runtime",
|
|
32710
|
+
{
|
|
32711
|
+
createContext: channel({
|
|
32712
|
+
channelName: "createFlueContext",
|
|
32713
|
+
kind: "sync-stream"
|
|
32714
|
+
})
|
|
32715
|
+
},
|
|
32716
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.FLUE }
|
|
32717
|
+
);
|
|
31769
32718
|
|
|
31770
32719
|
// src/instrumentation/plugins/flue-plugin.ts
|
|
31771
32720
|
var FLUE_AUTO_STATE = /* @__PURE__ */ Symbol.for("braintrust.flue.auto-state");
|
|
@@ -32108,15 +33057,20 @@ var FlueObserveBridge = class {
|
|
|
32108
33057
|
safeLog3(existing.span, { input, metadata });
|
|
32109
33058
|
return;
|
|
32110
33059
|
}
|
|
32111
|
-
const span = startSpan(
|
|
32112
|
-
|
|
32113
|
-
|
|
32114
|
-
|
|
32115
|
-
|
|
32116
|
-
|
|
32117
|
-
|
|
32118
|
-
|
|
32119
|
-
|
|
33060
|
+
const span = startSpan(
|
|
33061
|
+
withSpanInstrumentationName(
|
|
33062
|
+
{
|
|
33063
|
+
name: `workflow:${workflowName}`,
|
|
33064
|
+
spanAttributes: { type: "task" /* TASK */ },
|
|
33065
|
+
startTime: eventTime(event.startedAt ?? event.timestamp),
|
|
33066
|
+
event: {
|
|
33067
|
+
input,
|
|
33068
|
+
metadata
|
|
33069
|
+
}
|
|
33070
|
+
},
|
|
33071
|
+
INSTRUMENTATION_NAMES.FLUE
|
|
33072
|
+
)
|
|
33073
|
+
);
|
|
32120
33074
|
this.runsById.set(event.runId, { metadata, span });
|
|
32121
33075
|
}
|
|
32122
33076
|
handleRunResume(event, ctx) {
|
|
@@ -32136,12 +33090,17 @@ var FlueObserveBridge = class {
|
|
|
32136
33090
|
safeLog3(existing.span, { metadata });
|
|
32137
33091
|
return;
|
|
32138
33092
|
}
|
|
32139
|
-
const span = startSpan(
|
|
32140
|
-
|
|
32141
|
-
|
|
32142
|
-
|
|
32143
|
-
|
|
32144
|
-
|
|
33093
|
+
const span = startSpan(
|
|
33094
|
+
withSpanInstrumentationName(
|
|
33095
|
+
{
|
|
33096
|
+
name: `workflow:${workflowName}`,
|
|
33097
|
+
spanAttributes: { type: "task" /* TASK */ },
|
|
33098
|
+
startTime: eventTime(event.startedAt ?? event.timestamp),
|
|
33099
|
+
event: { metadata }
|
|
33100
|
+
},
|
|
33101
|
+
INSTRUMENTATION_NAMES.FLUE
|
|
33102
|
+
)
|
|
33103
|
+
);
|
|
32145
33104
|
this.runsById.set(event.runId, { metadata, span });
|
|
32146
33105
|
}
|
|
32147
33106
|
handleRunEnd(event) {
|
|
@@ -32780,7 +33739,14 @@ function stateMatchesRun(state, runId) {
|
|
|
32780
33739
|
return state.metadata["flue.run_id"] === runId;
|
|
32781
33740
|
}
|
|
32782
33741
|
function startFlueSpan(parent, args) {
|
|
32783
|
-
return parent ? withCurrent(
|
|
33742
|
+
return parent ? withCurrent(
|
|
33743
|
+
parent,
|
|
33744
|
+
() => startSpan(
|
|
33745
|
+
withSpanInstrumentationName(args, INSTRUMENTATION_NAMES.FLUE)
|
|
33746
|
+
)
|
|
33747
|
+
) : startSpan(
|
|
33748
|
+
withSpanInstrumentationName(args, INSTRUMENTATION_NAMES.FLUE)
|
|
33749
|
+
);
|
|
32784
33750
|
}
|
|
32785
33751
|
function runWithCurrentSpanStore(span, next) {
|
|
32786
33752
|
const state = _internalGetGlobalState();
|
|
@@ -32870,9 +33836,13 @@ var BraintrustLangChainCallbackHandler = class {
|
|
|
32870
33836
|
...this.options.debug ? { runId, parentRunId } : {}
|
|
32871
33837
|
}
|
|
32872
33838
|
};
|
|
32873
|
-
|
|
33839
|
+
const spanArgs = withSpanInstrumentationName(
|
|
33840
|
+
args,
|
|
33841
|
+
INSTRUMENTATION_NAMES.LANGCHAIN
|
|
33842
|
+
);
|
|
33843
|
+
let span = parentSpan.startSpan(spanArgs);
|
|
32874
33844
|
if (!Object.is(this.options.logger, NOOP_SPAN) && Object.is(span, NOOP_SPAN)) {
|
|
32875
|
-
span = initLogger().startSpan(
|
|
33845
|
+
span = initLogger().startSpan(spanArgs);
|
|
32876
33846
|
}
|
|
32877
33847
|
this.spans.set(runId, span);
|
|
32878
33848
|
}
|
|
@@ -33169,16 +34139,20 @@ function isRecord(value) {
|
|
|
33169
34139
|
}
|
|
33170
34140
|
|
|
33171
34141
|
// src/instrumentation/plugins/langchain-channels.ts
|
|
33172
|
-
var langChainChannels = defineChannels(
|
|
33173
|
-
|
|
33174
|
-
|
|
33175
|
-
|
|
33176
|
-
|
|
33177
|
-
|
|
33178
|
-
|
|
33179
|
-
|
|
33180
|
-
|
|
33181
|
-
|
|
34142
|
+
var langChainChannels = defineChannels(
|
|
34143
|
+
"@langchain/core",
|
|
34144
|
+
{
|
|
34145
|
+
configure: channel({
|
|
34146
|
+
channelName: "CallbackManager.configure",
|
|
34147
|
+
kind: "sync-stream"
|
|
34148
|
+
}),
|
|
34149
|
+
configureSync: channel({
|
|
34150
|
+
channelName: "CallbackManager._configureSync",
|
|
34151
|
+
kind: "sync-stream"
|
|
34152
|
+
})
|
|
34153
|
+
},
|
|
34154
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.LANGCHAIN }
|
|
34155
|
+
);
|
|
33182
34156
|
|
|
33183
34157
|
// src/instrumentation/plugins/langchain-plugin.ts
|
|
33184
34158
|
var LangChainPlugin = class extends BasePlugin {
|
|
@@ -33266,20 +34240,24 @@ function isBraintrustHandler(handler) {
|
|
|
33266
34240
|
}
|
|
33267
34241
|
|
|
33268
34242
|
// src/instrumentation/plugins/langsmith-channels.ts
|
|
33269
|
-
var langSmithChannels = defineChannels(
|
|
33270
|
-
|
|
33271
|
-
|
|
33272
|
-
|
|
33273
|
-
|
|
33274
|
-
|
|
33275
|
-
|
|
33276
|
-
|
|
33277
|
-
|
|
33278
|
-
|
|
33279
|
-
|
|
33280
|
-
|
|
33281
|
-
|
|
33282
|
-
|
|
34243
|
+
var langSmithChannels = defineChannels(
|
|
34244
|
+
"langsmith",
|
|
34245
|
+
{
|
|
34246
|
+
createRun: channel({
|
|
34247
|
+
channelName: "Client.createRun",
|
|
34248
|
+
kind: "async"
|
|
34249
|
+
}),
|
|
34250
|
+
updateRun: channel({
|
|
34251
|
+
channelName: "Client.updateRun",
|
|
34252
|
+
kind: "async"
|
|
34253
|
+
}),
|
|
34254
|
+
batchIngestRuns: channel({
|
|
34255
|
+
channelName: "Client.batchIngestRuns",
|
|
34256
|
+
kind: "async"
|
|
34257
|
+
})
|
|
34258
|
+
},
|
|
34259
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.LANGSMITH }
|
|
34260
|
+
);
|
|
33283
34261
|
|
|
33284
34262
|
// src/instrumentation/plugins/langsmith-plugin.ts
|
|
33285
34263
|
var MAX_COMPLETED_RUNS = 1e4;
|
|
@@ -33443,19 +34421,24 @@ var LangSmithPlugin = class extends BasePlugin {
|
|
|
33443
34421
|
const traceId = stringValue2(ownValue(run2, "trace_id")) ?? id;
|
|
33444
34422
|
const parentId = stringValue2(ownValue(run2, "parent_run_id")) ?? stringValue2(ownValue(ownValue(run2, "parent_run"), "id"));
|
|
33445
34423
|
const startTime = timestampSeconds(ownValue(run2, "start_time"));
|
|
33446
|
-
return startSpan(
|
|
33447
|
-
|
|
33448
|
-
|
|
33449
|
-
|
|
33450
|
-
|
|
33451
|
-
|
|
33452
|
-
|
|
33453
|
-
|
|
33454
|
-
|
|
33455
|
-
|
|
33456
|
-
|
|
33457
|
-
|
|
33458
|
-
|
|
34424
|
+
return startSpan(
|
|
34425
|
+
withSpanInstrumentationName(
|
|
34426
|
+
{
|
|
34427
|
+
name: stringValue2(ownValue(run2, "name")) ?? "LangSmith run",
|
|
34428
|
+
spanId: id,
|
|
34429
|
+
parentSpanIds: {
|
|
34430
|
+
parentSpanIds: parentId ? [parentId] : [],
|
|
34431
|
+
rootSpanId: traceId
|
|
34432
|
+
},
|
|
34433
|
+
spanAttributes: {
|
|
34434
|
+
type: mapRunType(ownValue(run2, "run_type"))
|
|
34435
|
+
},
|
|
34436
|
+
...startTime === void 0 ? {} : { startTime },
|
|
34437
|
+
event: { id }
|
|
34438
|
+
},
|
|
34439
|
+
INSTRUMENTATION_NAMES.LANGSMITH
|
|
34440
|
+
)
|
|
34441
|
+
);
|
|
33459
34442
|
}
|
|
33460
34443
|
logRun(span, run2, previous, includeOutput) {
|
|
33461
34444
|
const inputs = preferOwnValue(run2, previous, "inputs");
|
|
@@ -33713,7 +34696,8 @@ var piCodingAgentChannels = defineChannels(
|
|
|
33713
34696
|
channelName: "AgentSession.prompt",
|
|
33714
34697
|
kind: "async"
|
|
33715
34698
|
})
|
|
33716
|
-
}
|
|
34699
|
+
},
|
|
34700
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.PI_CODING_AGENT }
|
|
33717
34701
|
);
|
|
33718
34702
|
|
|
33719
34703
|
// src/instrumentation/plugins/pi-coding-agent-plugin.ts
|
|
@@ -33797,14 +34781,19 @@ function startPiPromptRun(event, onFinalize) {
|
|
|
33797
34781
|
...session.model?.id || agent.state?.model?.id ? { model: session.model?.id ?? agent.state?.model?.id } : {},
|
|
33798
34782
|
...event.moduleVersion ? { "pi_coding_agent.version": event.moduleVersion } : {}
|
|
33799
34783
|
};
|
|
33800
|
-
const span = startSpan(
|
|
33801
|
-
|
|
33802
|
-
|
|
33803
|
-
|
|
33804
|
-
|
|
33805
|
-
|
|
33806
|
-
|
|
33807
|
-
|
|
34784
|
+
const span = startSpan(
|
|
34785
|
+
withSpanInstrumentationName(
|
|
34786
|
+
{
|
|
34787
|
+
event: {
|
|
34788
|
+
input: extractPromptInput(event.arguments[0], event.arguments[1]),
|
|
34789
|
+
metadata
|
|
34790
|
+
},
|
|
34791
|
+
name: "AgentSession.prompt",
|
|
34792
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
34793
|
+
},
|
|
34794
|
+
INSTRUMENTATION_NAMES.PI_CODING_AGENT
|
|
34795
|
+
)
|
|
34796
|
+
);
|
|
33808
34797
|
const streamPatchState = installPiStreamPatch(agent);
|
|
33809
34798
|
const options = event.arguments[1];
|
|
33810
34799
|
const promptText = event.arguments[0];
|
|
@@ -33974,15 +34963,20 @@ async function startPiLlmSpan(state, model, context2, options) {
|
|
|
33974
34963
|
...extractToolMetadata(context2.tools),
|
|
33975
34964
|
"pi_coding_agent.operation": "agent.streamFn"
|
|
33976
34965
|
};
|
|
33977
|
-
const span = startSpan(
|
|
33978
|
-
|
|
33979
|
-
|
|
33980
|
-
|
|
33981
|
-
|
|
33982
|
-
|
|
33983
|
-
|
|
33984
|
-
|
|
33985
|
-
|
|
34966
|
+
const span = startSpan(
|
|
34967
|
+
withSpanInstrumentationName(
|
|
34968
|
+
{
|
|
34969
|
+
event: {
|
|
34970
|
+
input: processInputAttachments(normalizePiContextInput(context2)),
|
|
34971
|
+
metadata
|
|
34972
|
+
},
|
|
34973
|
+
name: getLlmSpanName(model),
|
|
34974
|
+
parent: await state.span.export(),
|
|
34975
|
+
spanAttributes: { type: "llm" /* LLM */ }
|
|
34976
|
+
},
|
|
34977
|
+
INSTRUMENTATION_NAMES.PI_CODING_AGENT
|
|
34978
|
+
)
|
|
34979
|
+
);
|
|
33986
34980
|
const llmState = {
|
|
33987
34981
|
finalized: false,
|
|
33988
34982
|
metadata,
|
|
@@ -34150,15 +35144,20 @@ async function startPiToolSpan(state, event) {
|
|
|
34150
35144
|
"pi_coding_agent.tool.name": event.toolName
|
|
34151
35145
|
};
|
|
34152
35146
|
try {
|
|
34153
|
-
const span = startSpan(
|
|
34154
|
-
|
|
34155
|
-
|
|
34156
|
-
|
|
34157
|
-
|
|
34158
|
-
|
|
34159
|
-
|
|
34160
|
-
|
|
34161
|
-
|
|
35147
|
+
const span = startSpan(
|
|
35148
|
+
withSpanInstrumentationName(
|
|
35149
|
+
{
|
|
35150
|
+
event: {
|
|
35151
|
+
input: event.args,
|
|
35152
|
+
metadata
|
|
35153
|
+
},
|
|
35154
|
+
name: event.toolName || "tool",
|
|
35155
|
+
parent: await state.span.export(),
|
|
35156
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
35157
|
+
},
|
|
35158
|
+
INSTRUMENTATION_NAMES.PI_CODING_AGENT
|
|
35159
|
+
)
|
|
35160
|
+
);
|
|
34162
35161
|
state.activeToolSpans.set(event.toolCallId, {
|
|
34163
35162
|
restoreAutoInstrumentation,
|
|
34164
35163
|
span
|
|
@@ -34590,20 +35589,24 @@ function logInstrumentationError4(context2, error2) {
|
|
|
34590
35589
|
}
|
|
34591
35590
|
|
|
34592
35591
|
// src/instrumentation/plugins/strands-agent-sdk-channels.ts
|
|
34593
|
-
var strandsAgentSDKChannels = defineChannels(
|
|
34594
|
-
|
|
34595
|
-
|
|
34596
|
-
|
|
34597
|
-
|
|
34598
|
-
|
|
34599
|
-
|
|
34600
|
-
|
|
34601
|
-
|
|
34602
|
-
|
|
34603
|
-
|
|
34604
|
-
|
|
34605
|
-
|
|
34606
|
-
|
|
35592
|
+
var strandsAgentSDKChannels = defineChannels(
|
|
35593
|
+
"@strands-agents/sdk",
|
|
35594
|
+
{
|
|
35595
|
+
agentStream: channel({
|
|
35596
|
+
channelName: "Agent.stream",
|
|
35597
|
+
kind: "sync-stream"
|
|
35598
|
+
}),
|
|
35599
|
+
graphStream: channel({
|
|
35600
|
+
channelName: "Graph.stream",
|
|
35601
|
+
kind: "sync-stream"
|
|
35602
|
+
}),
|
|
35603
|
+
swarmStream: channel({
|
|
35604
|
+
channelName: "Swarm.stream",
|
|
35605
|
+
kind: "sync-stream"
|
|
35606
|
+
})
|
|
35607
|
+
},
|
|
35608
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK }
|
|
35609
|
+
);
|
|
34607
35610
|
|
|
34608
35611
|
// src/instrumentation/plugins/strands-agent-sdk-plugin.ts
|
|
34609
35612
|
var MAX_STRANDS_STRING_ATTACHMENT_CACHE_ENTRIES = 32;
|
|
@@ -34758,22 +35761,32 @@ function startAgentStream(event, activeChildParents) {
|
|
|
34758
35761
|
);
|
|
34759
35762
|
const span = parentSpan ? withCurrent(
|
|
34760
35763
|
parentSpan,
|
|
34761
|
-
() => startSpan(
|
|
34762
|
-
|
|
34763
|
-
|
|
34764
|
-
|
|
35764
|
+
() => startSpan(
|
|
35765
|
+
withSpanInstrumentationName(
|
|
35766
|
+
{
|
|
35767
|
+
event: {
|
|
35768
|
+
input,
|
|
35769
|
+
metadata
|
|
35770
|
+
},
|
|
35771
|
+
name: formatAgentSpanName(agent),
|
|
35772
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
35773
|
+
},
|
|
35774
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
35775
|
+
)
|
|
35776
|
+
)
|
|
35777
|
+
) : startSpan(
|
|
35778
|
+
withSpanInstrumentationName(
|
|
35779
|
+
{
|
|
35780
|
+
event: {
|
|
35781
|
+
input,
|
|
35782
|
+
metadata
|
|
35783
|
+
},
|
|
35784
|
+
name: formatAgentSpanName(agent),
|
|
35785
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
34765
35786
|
},
|
|
34766
|
-
|
|
34767
|
-
|
|
34768
|
-
|
|
34769
|
-
) : startSpan({
|
|
34770
|
-
event: {
|
|
34771
|
-
input,
|
|
34772
|
-
metadata
|
|
34773
|
-
},
|
|
34774
|
-
name: formatAgentSpanName(agent),
|
|
34775
|
-
spanAttributes: { type: "task" /* TASK */ }
|
|
34776
|
-
});
|
|
35787
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
35788
|
+
)
|
|
35789
|
+
);
|
|
34777
35790
|
return {
|
|
34778
35791
|
activeTools: /* @__PURE__ */ new Map(),
|
|
34779
35792
|
attachmentCache,
|
|
@@ -34795,22 +35808,32 @@ function startMultiAgentStream(event, operation, activeChildParents) {
|
|
|
34795
35808
|
const input = processStrandsInputAttachments(event.arguments[0]);
|
|
34796
35809
|
const span = parentSpan ? withCurrent(
|
|
34797
35810
|
parentSpan,
|
|
34798
|
-
() => startSpan(
|
|
34799
|
-
|
|
34800
|
-
|
|
34801
|
-
|
|
35811
|
+
() => startSpan(
|
|
35812
|
+
withSpanInstrumentationName(
|
|
35813
|
+
{
|
|
35814
|
+
event: {
|
|
35815
|
+
input,
|
|
35816
|
+
metadata
|
|
35817
|
+
},
|
|
35818
|
+
name: operation === "Graph.stream" ? "Strands Graph" : "Strands Swarm",
|
|
35819
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
35820
|
+
},
|
|
35821
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
35822
|
+
)
|
|
35823
|
+
)
|
|
35824
|
+
) : startSpan(
|
|
35825
|
+
withSpanInstrumentationName(
|
|
35826
|
+
{
|
|
35827
|
+
event: {
|
|
35828
|
+
input,
|
|
35829
|
+
metadata
|
|
35830
|
+
},
|
|
35831
|
+
name: operation === "Graph.stream" ? "Strands Graph" : "Strands Swarm",
|
|
35832
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
34802
35833
|
},
|
|
34803
|
-
|
|
34804
|
-
|
|
34805
|
-
|
|
34806
|
-
) : startSpan({
|
|
34807
|
-
event: {
|
|
34808
|
-
input,
|
|
34809
|
-
metadata
|
|
34810
|
-
},
|
|
34811
|
-
name: operation === "Graph.stream" ? "Strands Graph" : "Strands Swarm",
|
|
34812
|
-
spanAttributes: { type: "task" /* TASK */ }
|
|
34813
|
-
});
|
|
35834
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
35835
|
+
)
|
|
35836
|
+
);
|
|
34814
35837
|
return {
|
|
34815
35838
|
activeNodes: /* @__PURE__ */ new Map(),
|
|
34816
35839
|
finalized: false,
|
|
@@ -34912,17 +35935,22 @@ function startModelSpan(state, event) {
|
|
|
34912
35935
|
};
|
|
34913
35936
|
const span = withCurrent(
|
|
34914
35937
|
state.span,
|
|
34915
|
-
() => startSpan(
|
|
34916
|
-
|
|
34917
|
-
|
|
34918
|
-
event
|
|
34919
|
-
|
|
34920
|
-
|
|
34921
|
-
|
|
34922
|
-
|
|
34923
|
-
|
|
34924
|
-
|
|
34925
|
-
|
|
35938
|
+
() => startSpan(
|
|
35939
|
+
withSpanInstrumentationName(
|
|
35940
|
+
{
|
|
35941
|
+
event: {
|
|
35942
|
+
input: Array.isArray(event.agent?.messages) ? processStrandsInputAttachments(
|
|
35943
|
+
event.agent.messages,
|
|
35944
|
+
state.attachmentCache
|
|
35945
|
+
) : void 0,
|
|
35946
|
+
metadata
|
|
35947
|
+
},
|
|
35948
|
+
name: formatModelSpanName(model),
|
|
35949
|
+
spanAttributes: { type: "llm" /* LLM */ }
|
|
35950
|
+
},
|
|
35951
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
35952
|
+
)
|
|
35953
|
+
)
|
|
34926
35954
|
);
|
|
34927
35955
|
state.activeModel = {
|
|
34928
35956
|
metadata,
|
|
@@ -34974,20 +36002,25 @@ function startToolSpan2(state, event) {
|
|
|
34974
36002
|
const name = extractToolName3(toolUse, event.tool);
|
|
34975
36003
|
const span = withCurrent(
|
|
34976
36004
|
state.span,
|
|
34977
|
-
() => startSpan(
|
|
34978
|
-
|
|
34979
|
-
|
|
34980
|
-
|
|
34981
|
-
|
|
34982
|
-
|
|
34983
|
-
|
|
34984
|
-
|
|
34985
|
-
|
|
34986
|
-
|
|
34987
|
-
|
|
34988
|
-
|
|
34989
|
-
|
|
34990
|
-
|
|
36005
|
+
() => startSpan(
|
|
36006
|
+
withSpanInstrumentationName(
|
|
36007
|
+
{
|
|
36008
|
+
event: {
|
|
36009
|
+
input: toolUse?.input,
|
|
36010
|
+
metadata: {
|
|
36011
|
+
"gen_ai.tool.call.id": toolUse?.toolUseId,
|
|
36012
|
+
"gen_ai.tool.name": name,
|
|
36013
|
+
"strands.operation": "tool.call",
|
|
36014
|
+
"strands.tool.name": name,
|
|
36015
|
+
provider: "strands"
|
|
36016
|
+
}
|
|
36017
|
+
},
|
|
36018
|
+
name: `tool: ${name}`,
|
|
36019
|
+
spanAttributes: { type: "tool" /* TOOL */ }
|
|
36020
|
+
},
|
|
36021
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
36022
|
+
)
|
|
36023
|
+
)
|
|
34991
36024
|
);
|
|
34992
36025
|
state.activeTools.set(key, {
|
|
34993
36026
|
span,
|
|
@@ -35058,11 +36091,16 @@ function startNodeSpan(state, event, activeChildParents) {
|
|
|
35058
36091
|
};
|
|
35059
36092
|
const span = withCurrent(
|
|
35060
36093
|
state.span,
|
|
35061
|
-
() => startSpan(
|
|
35062
|
-
|
|
35063
|
-
|
|
35064
|
-
|
|
35065
|
-
|
|
36094
|
+
() => startSpan(
|
|
36095
|
+
withSpanInstrumentationName(
|
|
36096
|
+
{
|
|
36097
|
+
event: { metadata },
|
|
36098
|
+
name: `node: ${nodeId}`,
|
|
36099
|
+
spanAttributes: { type: "task" /* TASK */ }
|
|
36100
|
+
},
|
|
36101
|
+
INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK
|
|
36102
|
+
)
|
|
36103
|
+
)
|
|
35066
36104
|
);
|
|
35067
36105
|
const nodeState = {
|
|
35068
36106
|
...child ? { child } : {},
|
|
@@ -36176,17 +37214,20 @@ var BraintrustObservabilityExporter = class {
|
|
|
36176
37214
|
}
|
|
36177
37215
|
onStart(exported) {
|
|
36178
37216
|
if (this.spans.has(exported.id)) return;
|
|
36179
|
-
const args =
|
|
36180
|
-
|
|
36181
|
-
|
|
36182
|
-
|
|
36183
|
-
|
|
36184
|
-
|
|
36185
|
-
|
|
36186
|
-
|
|
36187
|
-
|
|
36188
|
-
|
|
36189
|
-
|
|
37217
|
+
const args = withSpanInstrumentationName(
|
|
37218
|
+
{
|
|
37219
|
+
name: exported.name,
|
|
37220
|
+
spanAttributes: { type: spanTypeFor(exported.type) },
|
|
37221
|
+
startTime: epochSeconds(exported.startTime),
|
|
37222
|
+
// Use the Mastra span id as the Braintrust row id so that
|
|
37223
|
+
// `logFeedback({ id: <mastra span id> })` (and Mastra's score events)
|
|
37224
|
+
// attach to the right row. Without this, `SpanImpl` auto-generates a
|
|
37225
|
+
// row id (`this._id = eventId ?? idGenerator.getSpanId()`) that no
|
|
37226
|
+
// external caller could know.
|
|
37227
|
+
event: { id: exported.id }
|
|
37228
|
+
},
|
|
37229
|
+
INSTRUMENTATION_NAMES.MASTRA
|
|
37230
|
+
);
|
|
36190
37231
|
const parentRecord = exported.parentSpanId ? this.spans.get(exported.parentSpanId) : void 0;
|
|
36191
37232
|
if (!this.capturedParent) {
|
|
36192
37233
|
const probe = currentSpan();
|
|
@@ -36343,6 +37384,12 @@ function configureNode() {
|
|
|
36343
37384
|
isomorph_default.gzip = (0, import_node_util3.promisify)(zlib.gzip);
|
|
36344
37385
|
isomorph_default.gunzip = (0, import_node_util3.promisify)(zlib.gunzip);
|
|
36345
37386
|
isomorph_default.hash = (data) => crypto.createHash("sha256").update(data).digest("hex");
|
|
37387
|
+
isomorph_default.hmacSha256 = (key, data) => crypto.createHmac("sha256", key).update(data).digest("hex");
|
|
37388
|
+
isomorph_default.timingSafeEqual = (left, right) => {
|
|
37389
|
+
const leftBuffer = Buffer.from(left);
|
|
37390
|
+
const rightBuffer = Buffer.from(right);
|
|
37391
|
+
return leftBuffer.length === rightBuffer.length && crypto.timingSafeEqual(leftBuffer, rightBuffer);
|
|
37392
|
+
};
|
|
36346
37393
|
_internalSetInitialState();
|
|
36347
37394
|
const disabled = readDisabledInstrumentationEnvConfig(
|
|
36348
37395
|
isomorph_default.getEnv("BRAINTRUST_DISABLE_INSTRUMENTATION")
|