Skip to content

feat(ai): add telemetry and lifecycle callbacks to experimental_extract - #25232

Merged
dancer merged 8 commits into
mainfrom
josh/extract-telemetry
Nov 19, 2026
Merged

dancer merged 8 commits into
mainfrom
josh/extract-telemetry

Conversation

@dancer

@dancer dancer commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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

otel example, both spans exported, model call span parented to the root
$ 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 }
model call end event vs raw openai response, and a failing call
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
recordInputs false, gpt-6.2-sol

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"}}
request headers and provider options, gpt-6.2-sol

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

signed file url, real download, gpt-6.2-sol

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"
tracing channel example
$ pnpm tsx src/telemetry/tracing-channel/extract.ts
[tracing-channel] experimental_extract {
  "operationId": "ai.extract",
  "runtimeContext": {},

checklist

  • tests have been added / updated (for bug fixes / features)
  • documentation has been added / updated (for bug fixes / features)
  • a patch changeset for relevant packages has been added (run pnpm changeset in root)
  • i have reviewed this pull request (self-review)

@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-tarballs Ready Ready Preview, v0 Nov 19, 2026 6:23pm UTC

@dancer
dancer merged commit 15bfd6b into main Nov 19, 2026
57 checks passed
@dancer
dancer deleted the josh/extract-telemetry branch November 19, 2026 18:29
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.178 github npm
@ai-sdk/alibaba 2.0.93 github npm
@ai-sdk/amazon-bedrock 5.0.146 github npm
@ai-sdk/angular 3.0.178 github npm
@ai-sdk/anthropic 4.0.107 github npm
@ai-sdk/anthropic-aws 2.0.100 github npm
@ai-sdk/assemblyai 3.0.84 github npm
@ai-sdk/azure 4.0.130 github npm
@ai-sdk/baseten 2.1.73 github npm
@ai-sdk/black-forest-labs 2.0.87 github npm
@ai-sdk/bytedance 2.0.88 github npm
@ai-sdk/cartesia 3.0.78 github npm
@ai-sdk/cerebras 3.0.95 github npm
@ai-sdk/code-mode 1.0.135 github npm
@ai-sdk/cohere 4.0.86 github npm
@ai-sdk/deepgram 3.1.55 github npm
@ai-sdk/deepinfra 3.0.95 github npm
@ai-sdk/deepseek 3.0.89 github npm
@ai-sdk/devtools 1.0.81 github npm
@ai-sdk/elevenlabs 3.0.88 github npm
@ai-sdk/fal 3.0.86 github npm
@ai-sdk/fireworks 3.0.98 github npm
@ai-sdk/fish-audio 3.0.61 github npm
@ai-sdk/gateway 4.0.151 github npm
@ai-sdk/gladia 3.0.84 github npm
@ai-sdk/gmicloud 3.0.66 github npm
@ai-sdk/google 4.0.123 github npm
@ai-sdk/google-vertex 5.0.143 github npm
@ai-sdk/groq 4.0.86 github npm
@ai-sdk/harness 1.0.189 github npm
@ai-sdk/harness-acp 1.0.129 github npm
@ai-sdk/harness-claude-code 1.0.193 github npm
@ai-sdk/harness-cline 1.0.117 github npm
@ai-sdk/harness-codex 1.0.191 github npm
@ai-sdk/harness-cursor 1.0.104 github npm
@ai-sdk/harness-deepagents 1.0.189 github npm
@ai-sdk/harness-fx 1.0.105 github npm
@ai-sdk/harness-github-copilot 1.0.86 github npm
@ai-sdk/harness-grok-build 1.0.128 github npm
@ai-sdk/harness-opencode 1.0.192 github npm
@ai-sdk/harness-pi 1.0.192 github npm
@ai-sdk/heygen 3.0.27 github npm
@ai-sdk/huggingface 2.0.95 github npm
@ai-sdk/hume 3.0.83 github npm
@ai-sdk/klingai 4.0.87 github npm
@ai-sdk/langchain 3.0.178 github npm
@ai-sdk/liquid 3.0.1 github npm
@ai-sdk/llamaindex 3.0.178 github npm
@ai-sdk/luma 3.0.86 github npm
@ai-sdk/mcp 2.0.102 github npm
@ai-sdk/minimax 3.0.84 github npm
@ai-sdk/mistral 4.0.89 github npm
@ai-sdk/moonshotai 3.0.95 github npm
@ai-sdk/open-responses 2.0.89 github npm
@ai-sdk/openai 4.0.122 github npm
@ai-sdk/openai-compatible 3.0.94 github npm
@ai-sdk/otel 1.0.178 github npm
@ai-sdk/parallel 3.0.11 github npm
@ai-sdk/perplexity 5.0.37 github npm
@ai-sdk/policy-opa 1.0.178 github npm
@ai-sdk/prodia 2.0.86 github npm
@ai-sdk/provider-utils 5.0.83 github npm
@ai-sdk/quiverai 2.0.85 github npm
@ai-sdk/react 4.0.182 github npm
@ai-sdk/replicate 3.0.86 github npm
@ai-sdk/revai 3.0.83 github npm
@ai-sdk/rsc 3.0.178 github npm
@ai-sdk/sandbox-just-bash 1.0.189 github npm
@ai-sdk/sandbox-vercel 1.0.189 github npm
@ai-sdk/scaledown 3.0.3 github npm
@ai-sdk/svelte 5.0.178 github npm
@ai-sdk/tencent 3.0.5 github npm
@ai-sdk/togetherai 3.0.96 github npm
@ai-sdk/tool-bash 1.0.32 github npm
@ai-sdk/tool-web-fetch 1.0.28 github npm
@ai-sdk/topaz 3.0.30 github npm
@ai-sdk/tui 1.0.179 github npm
@ai-sdk/typesafe-ai 3.0.42 github npm
@ai-sdk/valibot 3.0.83 github npm
@ai-sdk/voyage 2.0.85 github npm
@ai-sdk/vue 4.0.178 github npm
@ai-sdk/workflow 2.0.110 github npm
@ai-sdk/workflow-harness 1.0.189 github npm
@ai-sdk/xai 5.0.48 github npm
@ai-sdk/zai 3.0.57 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants