Repository navigation
feat(ai): Set gen_ai.tool.definitions.hash and gen_ai.system_instructions.hash - #8440
Open
sentry-junior[bot] wants to merge 5 commits into
Open
sentry-junior[bot] wants to merge 5 commits into
sentry-junior[bot] wants to merge 5 commits into
Conversation
…ions.hash 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
PR risk: mediumFor commit Main concerns: reach, data sent to Sentry, host performance. This label is a hint for reviewers, not an approval. |
Contributor
Coverage Results 📊✅ 59569 passed | ⏭️ 3149 skipped | Total: 62718 | Pass Rate: 94.98% | Execution Time: 160m 33s 📊 Comparison with Base Branch
➖ Removed Tests (1)View removed tests
All tests are passing successfully. ✅ Patch coverage is 92.68% (38 of 41 changed executable lines covered; target 80%). Changed files with executable lines (4)
Coverage diff@@ Coverage Diff @@
## master #8440 +/-##
==========================================
+ Coverage 90.17% 90.18% +0.01%
==========================================
Files 201 201 —
Tracked lines 22184 22224 +40
Branches 7772 7788 +16
==========================================
+ Hits 20003 20041 +38
- Misses 2181 2183 +2
- Partials 1283 1286 +3Generated by Coverage Action |
BYK
marked this pull request as ready for review
December 2, 2026 15:57
…t have none Hash list items one by one with a shared JSON encoder, and copy an item without cache_control only when its JSON has that key. The hashes stay the same. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Hash the JSON in insertion order and keep cache_control, instead of a canonical form. A key reorder or a moved cache_control breakpoint now changes the hash, because the provider sees different bytes. The expected values are now per-SDK vectors. 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.
Description
Implements the attributes proposed in getsentry/sentry-conventions#844 for the Anthropic and OpenAI (Chat Completions and Responses) integrations. This depends on that PR and shouldn't merge before it does.
The two hashes cover the stable start of a request, the tools and the system instructions. With them, a drop in
gen_ai.usage.cache_read.input_tokenscan be read as "the prefix changed" (a hash differs from the previous call) or "the cache expired" (both hashes and the model match).Decisions worth a look:
data_collection.gen_ai.inputsis off. That's the main reason this has to happen in the SDK. Whether that's acceptable is the open PII question on feat(attributes): Add gen_ai.tool.definitions.hash and gen_ai.system_instructions.hash sentry-conventions#844. If it isn't, the fix is to move the call under the inputs check.NoOpSpan, so unsampled calls pay nothing. Otherwise the cost is onejson.dumpsand one SHA-256 of the tools and system prompt per call.list/tupletools and messages are hashed, so a generator passed by the caller is never consumed. Values that can't be serialized to JSON are skipped instead of guessed.json.dumps(value, separators=(",", ":"), ensure_ascii=False)of the request value, in insertion order withcache_controlkept. The test values are this SDK's own vectors.Other gen_ai integrations (Google GenAI, LiteLLM, LangChain, ...) can follow once the convention is settled.
Issues
via @BYK.
--
View Session [Sentry]