feat: correlate managed agent requests (#103476)

This commit is contained in:
Peter Steinberger
2026-07-10 08:42:55 +01:00
committed by GitHub
parent 3bec587d74
commit b07ebe3ff3
16 changed files with 463 additions and 53 deletions
@@ -973,6 +973,7 @@ describe("wrapStreamFnWithDiagnosticModelCallEvents", () => {
expect(capturedOptions[0]).not.toBe(callerOptions);
const capturedOption = requireRecord(capturedOptions[0], "captured stream options");
expect(capturedOption.sessionId).toBe("provider-session");
expect(capturedOption.requestId).toBe("call-traceparent");
const headers = readRecordField(capturedOption, "headers", "captured stream headers");
expect(headers["X-Custom"]).toBe("kept");
expect(typeof headers.traceparent).toBe("string");
@@ -622,10 +622,11 @@ function emitModelCallError(
});
}
function withDiagnosticTraceparentHeader(
function withDiagnosticRequestContext(
options: ModelCallStreamOptions,
trace: DiagnosticTraceContext,
state: ModelCallObservationState,
callId: string,
): ModelCallStreamOptions {
const traceparent = formatDiagnosticTraceparent(trace);
const originalOnPayload = options?.onPayload;
@@ -648,6 +649,7 @@ function withDiagnosticTraceparentHeader(
if (!traceparent) {
return {
...options,
requestId: callId,
onPayload,
};
}
@@ -662,6 +664,7 @@ function withDiagnosticTraceparentHeader(
headers[TRACEPARENT_HEADER_NAME] = traceparent;
return {
...options,
requestId: callId,
headers,
onPayload,
};
@@ -867,7 +870,9 @@ export function wrapStreamFnWithDiagnosticModelCallEvents(
modelContent,
contentCapture: ctx.contentCapture,
};
const propagatedOptions = withDiagnosticTraceparentHeader(options, trace, state);
// Provider wrappers consume this same call id for transport correlation,
// keeping external request evidence joined to the emitted diagnostics.
const propagatedOptions = withDiagnosticRequestContext(options, trace, state, callId);
try {
const result = streamFn(model, streamContext, propagatedOptions);