Repository navigation
feat(server-utils): Set gen_ai tool definitions and system instructions hashes - #27089
Draft
sentry-junior[bot] wants to merge 5 commits into
Draft
sentry-junior[bot] wants to merge 5 commits into
sentry-junior[bot] wants to merge 5 commits into
Conversation
…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>
Contributor
size-limit report 📦Compared: 9843c01 (PR test merge using develop at 29e62cd) Against: 1c10c6f (develop) · base run #68574
|
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. |
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 62 successful. See the run.
Successful checks
|
…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>
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Anthropic and OpenAI (including OpenAI-compatible) chat spans now carry
gen_ai.tool.definitions.hashandgen_ai.system_instructions.hash, as proposed in getsentry/sentry-conventions#844. This works for both auto-instrumentation and theinstrument*Clientwrappers. This depends on that PR and shouldn't merge before it does. The keys live ingen-ai-attributes.tsuntil@sentry/conventionsships 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:
recordInputsis 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 therecordInputscheck.init(), like the async context strategy. Node, Bun, Deno and the Cloudflare main entry (which already needsnodejs_compat) usenode:crypto. Vercel Edge and@sentry/cloudflare/requestuse 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.JSON.stringifyof the request value, in insertion order withcache_controlkept. The test values are this SDK's own vectors.Related: getsentry/sentry-python#8440
via @BYK.
--
View Session [Sentry]