-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[STG-2284] feat(evals): richer OTEL traces — task root, thread grouping, trajectory #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
miguelg719
wants to merge
1
commit into
miguelgonzalez/evals-braintrust-3
from
miguelgonzalez/evals-otel-trace-detail
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { capForSpan } from "../../framework/runner.js"; | ||
|
|
||
| const MAX_SPAN_PAYLOAD_BYTES = 2_000_000; | ||
|
|
||
| function jsonBytes(value: unknown): number { | ||
| return Buffer.byteLength(JSON.stringify(value), "utf8"); | ||
| } | ||
|
|
||
| describe("capForSpan", () => { | ||
| it("returns small payloads unchanged", () => { | ||
| const value = { _success: true, metrics: { steps: 3 }, logs: ["a", "b"] }; | ||
| expect(capForSpan(value)).toBe(value); | ||
| }); | ||
|
|
||
| it("flags payloads that cannot be serialized", () => { | ||
| const circular: Record<string, unknown> = { _success: true }; | ||
| circular.self = circular; | ||
| expect(capForSpan(circular)).toEqual({ | ||
| _truncated: "payload not serializable", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps a tail of logs when the payload exceeds the cap", () => { | ||
| // ~4MB of logs: 400 entries × ~10KB each. Entries are distinguishable so | ||
| // we can assert the *tail* (newest) is what survives. | ||
| const logs = Array.from( | ||
| { length: 400 }, | ||
| (_, i) => `entry-${i}-${"x".repeat(10_000)}`, | ||
| ); | ||
| const value = { _success: false, logs }; | ||
|
|
||
| const capped = capForSpan(value); | ||
|
|
||
| expect(jsonBytes(capped)).toBeLessThanOrEqual(MAX_SPAN_PAYLOAD_BYTES); | ||
| const keptLogs = capped.logs as string[]; | ||
| expect(keptLogs.length).toBeGreaterThan(0); | ||
| expect(keptLogs.length).toBeLessThan(logs.length); | ||
| // Tail-preserving: the kept entries are a contiguous suffix of the input. | ||
| expect(keptLogs).toEqual(logs.slice(logs.length - keptLogs.length)); | ||
| expect(keptLogs[keptLogs.length - 1]).toBe(logs[logs.length - 1]); | ||
| expect(capped._truncated).toMatch(/kept the last \d+ of 400 log entries/); | ||
| }); | ||
|
|
||
| it("drops oversized non-log fields so the result is always within the cap (P1)", () => { | ||
| // A single non-`logs` field alone blows the cap; trimming logs can't help. | ||
| const value = { | ||
| _success: false, | ||
| error: "e".repeat(2_500_000), | ||
| metrics: { steps: 2 }, | ||
| logs: ["a", "b"], | ||
| }; | ||
|
|
||
| const capped = capForSpan(value); | ||
|
|
||
| expect(jsonBytes(capped)).toBeLessThanOrEqual(MAX_SPAN_PAYLOAD_BYTES); | ||
| expect(capped.error).toBeUndefined(); | ||
| expect(capped._success).toBe(false); // small scalar survives | ||
| expect(capped.metrics).toEqual({ steps: 2 }); // small object survives | ||
| expect(capped._truncated).toMatch(/oversized fields omitted/); | ||
| }); | ||
|
|
||
| it("measures bytes, not UTF-16 code units (P2)", () => { | ||
| // "€" is 1 UTF-16 unit but 3 UTF-8 bytes. This string's JSON char length | ||
| // is under the cap, but its byte length is over — a char-counting cap | ||
| // would wrongly pass it through whole. | ||
| const value = { note: "€".repeat(700_000) }; | ||
| expect(JSON.stringify(value).length).toBeLessThan(MAX_SPAN_PAYLOAD_BYTES); | ||
| expect(jsonBytes(value)).toBeGreaterThan(MAX_SPAN_PAYLOAD_BYTES); | ||
|
|
||
| const capped = capForSpan(value); | ||
|
|
||
| expect(jsonBytes(capped)).toBeLessThanOrEqual(MAX_SPAN_PAYLOAD_BYTES); | ||
| expect(capped.note).toBeUndefined(); | ||
| expect(capped._truncated).toBeDefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.