Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ai-sdk-v7-telemetry-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": patch
---

fix(ai-sdk): Close `braintrustAISDKTelemetry()` parent spans with AI SDK 7 `onEnd` callbacks
19 changes: 13 additions & 6 deletions e2e/helpers/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ type TokenMaps = {

export type NormalizeOptions = {
additionalProviderIdKeys?: Iterable<string>;
omittedKeys?: Iterable<string>;
};

type ResolvedNormalizeOptions = {
omittedKeys: Set<string>;
providerIdKeys: Set<string>;
};

Expand Down Expand Up @@ -231,16 +233,20 @@ function normalizeObject(
shouldNormalizeNodeInternalStyleCaller(callerFilename);

return Object.fromEntries(
Object.entries(value).map(([key, entry]) => {
Object.entries(value).flatMap(([key, entry]) => {
if (options.omittedKeys.has(key)) {
return [];
}

if (isNodeInternalCaller) {
if (key === "caller_filename") {
return [key, "<node-internal>"];
return [[key, "<node-internal>"]];
}
if (key === "caller_functionname") {
return [key, "<node-internal>"];
return [[key, "<node-internal>"]];
}
if (key === "caller_lineno") {
return [key, 0];
return [[key, 0]];
}
}

Expand All @@ -249,10 +255,10 @@ function normalizeObject(
typeof entry === "string" &&
(value.type === "thought" || value.type === "thought_signature")
) {
return [key, tokenFor(tokenMaps.ids, entry, "signature")];
return [[key, tokenFor(tokenMaps.ids, entry, "signature")]];
}

return [key, normalizeValue(entry as Json, tokenMaps, options, key)];
return [[key, normalizeValue(entry as Json, tokenMaps, options, key)]];
}),
);
}
Expand Down Expand Up @@ -430,6 +436,7 @@ function resolveNormalizeOptions(
options: NormalizeOptions | undefined,
): ResolvedNormalizeOptions {
return {
omittedKeys: new Set(options?.omittedKeys ?? []),
providerIdKeys: new Set([
...PROVIDER_ID_KEYS,
...(options?.additionalProviderIdKeys ?? []),
Expand Down
Loading
Loading