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

Offen Anfängerfreundlich
#26,079 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@biggdawg320 arbeitet bereits daran.

Seit 04.11.2026.

  • #26090 von @biggdawg320 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
73/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Bereich
observability

Rechercherichtung

Lies vercel-ai-orchestrion-subscriber.js für v4–v6 und vercel-ai-dc-subscriber.js für v7 und konzentriere dich auf die im Issue beschriebene Verarbeitung des System-Prompts. Reproduziere das Problem mit den bereitgestellten generateText-Beispielen, die sowohl String-Prompts als auch Nachrichtenobjekte verwenden. Fertig ist die Arbeit, wenn beide Formen gen_ai.system_instructions auf invoke_agent-Spans über alle betroffenen Versionen hinweg befüllen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
8.8k
Forks
1.9k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
664

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus getsentry/sentry-javascript

Alle Issues in getsentry/sentry-javascript

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.