Vercel AI: `gen_ai.system_instructions` is missing when the system prompt is a message object

Aperta Adatta ai principianti
#26,079 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
73/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js, typescript
Ambito
observability

Direzione di ricerca

Leggi vercel-ai-orchestrion-subscriber.js per v4–v6 e vercel-ai-dc-subscriber.js per v7, concentrandoti sulla gestione del prompt di sistema descritta nell’issue. Riproduci il problema con gli esempi generateText forniti, usando sia prompt di tipo stringa sia prompt come oggetti messaggio. Il lavoro è completato quando entrambe le forme valorizzano gen_ai.system_instructions sugli span invoke_agent in tutte le versioni interessate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Package: node Spans vercel ai

SDK: @sentry/node 11.10.0 (also @sentry/nextjs 11.10.0) · ai 6.0.316 and 7.0.162

Steps to reproduce
const Sentry = require('@sentry/node');
Sentry.init({
  dsn: '…',
  tracesSampleRate: 1,
  sendDefaultPii: true,
  traceLifecycle: 'stream',
  beforeSendSpan: Sentry.withStreamedSpan(span => {
    if (span.name.startsWith('invoke_agent')) console.log(span.name, span.attributes['gen_ai.system_instructions'] ?? '(missing)');
    return span;
  }),
});
const { generateText } = require('ai');
const { MockLanguageModelV3 } = require('ai/test'); // MockLanguageModelV4 on ai v7

const model = () => new MockLanguageModelV3({
  doGenerate: async () => ({ content: [{ type: 'text', text: 'ok' }], finishReason: { unified: 'stop', raw: 'stop' }, usage: { inputTokens: { total: 1 }, outputTokens: { total: 1 } }, warnings: [] }),
});

// ai v7: use `instructions` instead of `system`
await generateText({ model: model(), experimental_telemetry: { functionId: 'string' }, system: 'Be brief.', prompt: 'hi' });
await generateText({
  model: model(),
  experimental_telemetry: { functionId: 'object' },
  system: { role: 'system', content: 'Be brief.', providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } } },
  prompt: 'hi',
});
Expected result

Both invoke_agent spans have gen_ai.system_instructions.

Actual result
invoke_agent string [{"type":"text","content":"Be brief."}]
invoke_agent object (missing)

The same happens on ai v7 with instructions.

Additional context

The AI SDK accepts string | SystemModelMessage | SystemModelMessage[] for the system prompt. The object form is the documented way to set provider options on it, for example Anthropic prompt caching. The integration reads only strings:

  • v4–v6: instructions: util.asString(options.system) in vercel-ai-orchestrion-subscriber.js
  • v7: util.asString(event.instructions) in buildInputMessageAttributes (vercel-ai-dc-subscriber.js)

Possible fix: when the value is an object or an array, take each message's content.

Related: #20581 (the "System messages extracted to gen_ai.system_instructions" item).

I can open a PR if this approach works for you.

Lingua principale
TypeScript
Stelle
8.8k
Fork
1.9k
Merge medio
1g 19h
PR unite (30g)
664

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-javascript

Tutte le issue di getsentry/sentry-javascript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.