Skip to content

feat: add telemetry support to experimental_evaluate - #21162

Merged
n1ckoates merged 8 commits into
mainfrom
nick/evaluate-telemetry
Sep 22, 2026
Merged

n1ckoates merged 8 commits into
mainfrom
nick/evaluate-telemetry

Conversation

@n1ckoates

@n1ckoates n1ckoates commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Background

experimental_evaluate didn't have telemetry integration

Summary

  • Added lifecycle events, callbacks, tracing-channel support, and OpenTelemetry spans for experimental_evaluate.
  • Added support to both OpenTelemetry and LegacyOpenTelemetry.
  • Used standard gen_ai.* attributes for operation, provider, model, and token usage.
  • Added opt-in ai.evaluation.state, ai.evaluation.questions, and ai.evaluation.answers attributes.
    • OpenTelemetry’s gen_ai.evaluation.result describes a score/label on an existing model response for evals
    • AI SDK evaluation differs - it's a model operation over arbitrary state deciding between multiple questions.
  • Kept experimental prefixes on unstable public extension points, while keeping emitted span names and attributes semantic.

End-to-End Verification

Ran the lifecycle-hook, OpenTelemetry, and tracing-channel examples against TypeSafe AI jev-latest.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • 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 (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

@vercel-internal-security-reviewer

Copy link
Copy Markdown
Contributor

Security review details

@n1ckoates
n1ckoates marked this pull request as ready for review September 22, 2026 17:42
@n1ckoates
n1ckoates enabled auto-merge (squash) September 22, 2026 17:46
@n1ckoates
n1ckoates disabled auto-merge September 22, 2026 17:48
@n1ckoates
n1ckoates enabled auto-merge (squash) September 22, 2026 17:50
@n1ckoates
n1ckoates merged commit 31d24ce into main Sep 22, 2026
53 checks passed
@n1ckoates
n1ckoates deleted the nick/evaluate-telemetry branch September 22, 2026 17:54
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.111 github npm
@ai-sdk/angular 3.0.111 github npm
@ai-sdk/code-mode 1.0.68 github npm
@ai-sdk/harness 1.0.121 github npm
@ai-sdk/harness-acp 1.0.59 github npm
@ai-sdk/harness-claude-code 1.0.125 github npm
@ai-sdk/harness-cline 1.0.48 github npm
@ai-sdk/harness-codex 1.0.123 github npm
@ai-sdk/harness-cursor 1.0.34 github npm
@ai-sdk/harness-deepagents 1.0.121 github npm
@ai-sdk/harness-fx 1.0.34 github npm
@ai-sdk/harness-github-copilot 1.0.16 github npm
@ai-sdk/harness-grok-build 1.0.58 github npm
@ai-sdk/harness-opencode 1.0.123 github npm
@ai-sdk/harness-pi 1.0.123 github npm
@ai-sdk/langchain 3.0.111 github npm
@ai-sdk/llamaindex 3.0.111 github npm
@ai-sdk/otel 1.0.111 github npm
@ai-sdk/policy-opa 1.0.111 github npm
@ai-sdk/react 4.0.114 github npm
@ai-sdk/rsc 3.0.111 github npm
@ai-sdk/sandbox-just-bash 1.0.121 github npm
@ai-sdk/sandbox-vercel 1.0.121 github npm
@ai-sdk/svelte 5.0.111 github npm
@ai-sdk/tui 1.0.112 github npm
@ai-sdk/vue 4.0.111 github npm
@ai-sdk/workflow 2.0.42 github npm
@ai-sdk/workflow-harness 1.0.121 github npm

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

1 active deployment
Preview — 2833ab47 Deployed Sep 22, 2026 by vercel[bot]
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