Skip to content

feat(server-utils): Set gen_ai tool definitions and system instructions hashes - #27089

Draft
sentry-junior[bot] wants to merge 5 commits into
developfrom
feat/gen-ai-prefix-hashes
Draft

sentry-junior[bot] wants to merge 5 commits into
developfrom
feat/gen-ai-prefix-hashes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Anthropic and OpenAI (including OpenAI-compatible) chat spans now carry gen_ai.tool.definitions.hash and gen_ai.system_instructions.hash, as proposed in getsentry/sentry-conventions#844. This works for both auto-instrumentation and the instrument*Client wrappers. This depends on that PR and shouldn't merge before it does. The keys live in gen-ai-attributes.ts until @sentry/conventions ships them.

Why

When cache reads drop, the hashes tell "the tools or system prompt changed" apart from "the provider cache expired". Decisions worth a look:

  • They are set even when recordInputs is off, because that's the case where Sentry has nothing else to compare. Whether that's acceptable is the open PII question on the conventions PR. If it isn't, the fix is to move the calls under the recordInputs check.
  • Each runtime SDK sets the SHA-256 function in init(), like the async context strategy. Node, Bun, Deno and the Cloudflare main entry (which already needs nodejs_compat) use node:crypto. Vercel Edge and @sentry/cloudflare/request use a plain-JS SHA-256, so it stays out of the Node bundle. WebCrypto is async, so it can't set the attribute when the span starts. Only recording spans pay for the hashing.
  • The hash input is JSON.stringify of the request value, in insertion order with cache_control kept. The test values are this SDK's own vectors.

Related: getsentry/sentry-python#8440

via @BYK.

--

View Session [Sentry]

…ns hashes

Hash the tools and system instructions of Anthropic and OpenAI requests, so a reader can tell a changed prompt prefix apart from an expired provider cache. The hashes are set even when inputs are not recorded.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 9843c01 (PR test merge using develop at 29e62cd)

Against: 1c10c6f (develop) · base run #68574

⚠️ Baseline mismatch: 5 commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once the baseline build for 29e62cd finishes.

Path Size % Change Change
@sentry/browser 30.64 kB - -
@sentry/browser - with treeshaking flags 28.73 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.62 kB - -
@sentry/browser (incl. Tracing) 53.98 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing Core) 40.82 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 53.98 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Profiling) 56.86 kB - -
@sentry/browser (incl. Tracing, Replay) 93.96 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 82.52 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 98.8 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 111.75 kB - -
@sentry/browser (incl. Feedback) 48.51 kB +0.01% +1 B 🔺
@sentry/browser (incl. sendFeedback) 31.2 kB - -
@sentry/browser (incl. FeedbackAsync) 36.26 kB +0.01% +1 B 🔺
@sentry/browser (incl. Metrics) 31.96 kB - -
@sentry/browser (incl. Logs) 32.25 kB - -
@sentry/browser (incl. Metrics & Logs) 32.91 kB - -
@sentry/react 32.5 kB - -
@sentry/react (incl. Tracing) 56.46 kB - -
@sentry/vue 38.99 kB - -
@sentry/vue (incl. Tracing) 57.05 kB -0.01% -1 B 🔽
@sentry/svelte 30.68 kB - -
@sentry/effect (client) 42.21 kB -0.01% -1 B 🔽
@sentry/effect (client, incl. Tracing) 55.02 kB - -
@sentry/effect (client, incl. Tracing, Logs, Metrics) 66.5 kB - -
@sentry/remix (Remix 3 client bundle) 59.47 kB -0.01% -1 B 🔽
CDN Bundle 32.45 kB - -
CDN Bundle (incl. Tracing) 54.12 kB - -
CDN Bundle (incl. Logs, Metrics) 35.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 56.57 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.15 kB - -
CDN Bundle (incl. Tracing, Replay) 91.93 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 94.44 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.85 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 160.02 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 103.01 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 167.65 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.4 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 280.45 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 288.08 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.39 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 300 kB - -
@sentry/nextjs (client) 59.75 kB - -
@sentry/sveltekit (client) 54.8 kB - -
@sentry/astro (client) - rolldown, without tracing 35.73 kB +0.01% +1 B 🔺
@sentry/core/server 45.91 kB - -
@sentry/core/browser 14.55 kB - -
@sentry/node 157.91 kB +0.16% +251 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.63 kB - -
@sentry/node - without tracing 89.67 kB +0.02% +16 B 🔺
@sentry/node - without channel injection 147.28 kB +0.2% +289 B 🔺
@sentry/aws-serverless 100.58 kB +0.01% +10 B 🔺
@sentry/cloudflare (withSentry) - minified 213.02 kB +0.07% +149 B 🔺
@sentry/cloudflare (withSentry) 493.84 kB +0.09% +408 B 🔺
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 215.96 kB +0.07% +149 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 238.44 kB +0.07% +149 B 🔺

View base workflow run

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 1 not successful, 62 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-express-mcp-v2 (MCP SDK OpenTelemetry) Test (optional) Failing after 1m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7 (static trace lifecycle) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hono-5 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14-supabase Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hono-5 (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (0.x) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hono-5 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-4-sourcemaps (Vite server) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry (static trace lifecycle) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps enabled by Sentry) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (cloudflare) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (bun) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vinext-cf-workers (workers cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details

sentry-junior Bot and others added 2 commits December 2, 2026 15:56
…ntime has it

Each runtime SDK sets the SHA-256 function in init(): node:crypto for Node, Bun, Deno and the Cloudflare main entry (which needs nodejs_compat already), the plain-JS hash for Vercel Edge and @sentry/cloudflare/request. This keeps the plain-JS SHA-256 out of the @sentry/node bundle.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot and others added 2 commits December 2, 2026 22:13
…request hashes

Copy each object with sorted keys in a JSON.stringify replacer, and fall back to the hand-built JSON when a key starts with a digit, because JS objects enumerate integer-like keys first. The hashes stay the same. Drop the debug warning for values that can't be hashed to stay under the size limit.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…sends them

Hash JSON.stringify of the value, in insertion order and with cache_control kept, instead of a canonical form. A key reorder or a moved cache_control breakpoint now changes the hash, because the provider sees different bytes. This removes the canonical JSON code.

Co-Authored-By: Burak Yigit Kaya <126780+BYK@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant