Repository navigation
feat: add telemetry support to experimental_evaluate - #21162
Merged
Merged
Conversation
Contributor
n1ckoates
marked this pull request as ready for review
September 22, 2026 17:42
gr2m
approved these changes
Sep 22, 2026
n1ckoates
enabled auto-merge (squash)
September 22, 2026 17:46
n1ckoates
disabled auto-merge
September 22, 2026 17:48
n1ckoates
enabled auto-merge (squash)
September 22, 2026 17:50
Contributor
|
🚀 Published in:
|
4 tasks done
dancer
added a commit
that referenced
this pull request
Nov 19, 2026
…ct (#25232) ## background `experimental_extract` shipped without telemetry, `runtimeContext` or `onStart` / `onEnd`, same as decide's first pr. this adds them the same way #21162 did for decide, matching how decide works today (context allowlists, `aiVersion`, recording flags in the tracing channel) ## summary - add `telemetry`, `runtimeContext`, `onStart` and `onEnd` to `experimental_extract` - add `Experimental_ExtractStartEvent`, `Experimental_ExtractEndEvent`, `Experimental_ExtractionModelCallStartEvent` and `Experimental_ExtractionModelCallEndEvent` - add `experimental_onExtractStart`, `experimental_onExtractionModelCallStart`, `experimental_onExtractionModelCallEnd` and `experimental_onExtractEnd` to telemetry integrations, kept out of the stable `onStart` / `onEnd` unions like decide - add an `experimental_extract` tracing channel span - `OpenTelemetry` records an `extract {modelId}` operation span and a child model call span with usage and response id. state, fields, reference date and answers go under `ai.extraction.*` behind a new opt-in `experimental_extraction` option - hide extraction `fields` and `referenceDate` from integrations when `recordInputs` is false, next to decide's `questions`. both go into the model prompt. answers were already covered by the `answers` output rule - keep request headers and provider options out of extract telemetry and the tracing channel, since they can carry credentials like auth headers or provider api keys. `onStart` / `onEnd` and the provider call still get them - replace file urls and provider file references in extraction state with `[redacted]` for telemetry, since they can be signed links. the download and `onStart` / `onEnd` still use the originals - don't record provider metadata on extraction spans, it can hold document content like ocr text. integrations still get it in the events - redact the file url from download errors sent to telemetry, for every operation. the error the app catches keeps the url - docs for the telemetry and lifecycle callbacks pages, the `experimental_extract` reference and a telemetry section in the extractions guide, plus otel and tracing channel examples same order as decide: invalid input and unsupported field types throw before any event, a refusal fires `onError` and no end events, and the model call end event has the normalized answers that are validated and returned left out on purpose: no `LegacyOpenTelemetry` support since legacy is fading out, and no deprecated hook aliases since extract never had old names bundle limit goes from 661 to 664 kb, node is 662.87 kb ## verification <details> <summary>otel example, both spans exported, model call span parented to the root</summary> ``` $ pnpm tsx src/telemetry/otel/extract.ts parentSpanContext: { spanId: '0f3449a6acb52236' } name: 'extract gpt-6.2-sol' id: '666538fdf2fef816' 'gen_ai.operation.name': 'extract' 'gen_ai.response.id': 'resp_04ca3908...' 'gen_ai.usage.input_tokens': 449 'gen_ai.usage.output_tokens': 41 'ai.extraction.answers': '{"invoiceNumber":{"type":"text","value":"INV-2041"},...}' status: { code: 0 } parentSpanContext: undefined name: 'extract gpt-6.2-sol' id: '0f3449a6acb52236' status: { code: 0 } ``` </details> <details> <summary>model call end event vs raw openai response, and a failing call</summary> ``` raw vs event: {"id":["resp_02f2e798...","resp_02f2e798..."],"input":[304,304],"output":[23,23]} invalid api key: threw: AI_APICallError onError calls: 1 span extract gpt-6.2-sol status=2 events=exception span extract gpt-6.2-sol status=2 events=exception ``` </details> <details> <summary>recordInputs false, gpt-6.2-sol</summary> the integration and the tracing channel get no state, fields or reference date. `onStart` still gets everything and the extraction still uses the reference date ``` {"tracing":{"state":"","fields":{}},"callback":{"referenceDate":"2026-11-18"},"integration":{"state":"","fields":{}},"answer":{"type":"date","value":"2027-03-03"}} ``` </details> <details> <summary>request headers and provider options, gpt-6.2-sol</summary> the provider still gets them, telemetry doesn't ``` {"tracing":false,"callback":{"header":"secret-header","options":{"openai":{"safetyIdentifier":"secret-user"}}},"integration":false,"provider":{"header":"secret-header","user":"secret-user"},"answer":"INV-2041"} ``` `tracing` and `integration` are whether the event contained `secret` </details> <details> <summary>signed file url, real download, gpt-6.2-sol</summary> the url has a fake `?sig=secret` query. one run succeeds, one hits a 10 byte download limit ``` success: spans=2 secret-in-spans=false redacted=true statuses=0,0 answer="Dummy PDF file" size limit: spans=1 secret-in-spans=false redacted=true statuses=2 answer=undefined AI_DownloadError url-in-error=true legacy only: spans=0 secret-in-spans=false redacted=false statuses= answer="Dummy PDF file" ``` </details> <details> <summary>tracing channel example</summary> ``` $ pnpm tsx src/telemetry/tracing-channel/extract.ts [tracing-channel] experimental_extract { "operationId": "ai.extract", "runtimeContext": {}, ``` </details> ## checklist - [x] tests have been added / updated (for bug fixes / features) - [x] documentation has been added / updated (for bug fixes / features) - [x] a _patch_ changeset for relevant packages has been added (run `pnpm changeset` in root) - [x] i have reviewed this pull request (self-review)
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
experimental_evaluatedidn't have telemetry integrationSummary
experimental_evaluate.OpenTelemetryandLegacyOpenTelemetry.gen_ai.*attributes for operation, provider, model, and token usage.ai.evaluation.state,ai.evaluation.questions, andai.evaluation.answersattributes.gen_ai.evaluation.resultdescribes a score/label on an existing model response for evalsEnd-to-End Verification
Ran the lifecycle-hook, OpenTelemetry, and tracing-channel examples against TypeSafe AI
jev-latest.Checklist
pnpm changesetin the project root)