feat(eap): implement gen_ai attribute transformations#6201
Draft
constantinius wants to merge 2 commits into
Draft
feat(eap): implement gen_ai attribute transformations#6201constantinius wants to merge 2 commits into
constantinius wants to merge 2 commits into
Conversation
Implement the two attribute transformations introduced in sentry-conventions PR #465: `gen_ai_request_messages_to_input_messages` and `gen_ai_response_to_output_messages`. These go beyond simple key renaming — they reshape attribute values to match the new schema. `gen_ai.request.messages` with a `content` field on each message is converted to `gen_ai.input.messages` with a `parts` array. `gen_ai.response.text` (plain string, JSON string array, or objects with content) and `gen_ai.response.tool_calls` are combined into a single `gen_ai.output.messages` assistant message with typed parts. The transformations run inside `normalize_ai` as part of AI span normalization (processing mode only). Attributes with the new `"transform"` deprecation status produce `WriteBehavior::CurrentName` so `normalize_attribute_names` leaves them alone — the dedicated transformation code handles the full move-and-reshape. The `gen_ai.request.messages`, `gen_ai.response.text`, and `gen_ai.response.tool_calls` legacy aliases are removed from SpanV1 SpanData so these deprecated keys survive into SpanV2 attributes where the transformation can process them. Key changes: - Add `Transform` variant to `DeprecationStatus` in the build script, producing `WriteBehavior::CurrentName` instead of `NewName` - New `gen_ai_transform` module with the two transformation functions - `normalize_ai` calls `transform_gen_ai` as its first step - Remove legacy aliases for the three deprecated attributes from SpanData - Update sentry-conventions submodule to PR #465 branch - 21 unit tests, 4 new integration tests covering SpanV1 and SpanV2
Clippy lint fix for the Transform arm in format_write_behavior.
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.
Summary
Implements the two gen_ai attribute transformations introduced in sentry-conventions PR #465:
gen_ai_request_messages_to_input_messages— transformsgen_ai.request.messages(withcontentfield per message) intogen_ai.input.messages(withpartsarray)gen_ai_response_to_output_messages— combinesgen_ai.response.textandgen_ai.response.tool_callsinto a singlegen_ai.output.messagesassistant message with typed partsThese go beyond simple key renaming — they reshape attribute values to match the new schema.
How it works
Attributes with
_status: "transform"in sentry-conventions produceWriteBehavior::CurrentName, sonormalize_attribute_namesleaves them alone. The dedicated transformation code in the newgen_ai_transformmodule handles the full move-and-reshape, called fromnormalize_aias part of AI span normalization (processing mode only).The
gen_ai.request.messages,gen_ai.response.text, andgen_ai.response.tool_callslegacy aliases are removed from SpanV1SpanDataso these deprecated keys survive into SpanV2 attributes where the transformation can process them.gen_ai.request.messages→gen_ai.input.messagesFor each message object, the
contentfield is converted to apartsarray:"hello"→[{"type": "text", "content": "hello"}]textcopied tocontenton each part if missinggen_ai.response.text+gen_ai.response.tool_calls→gen_ai.output.messagesgen_ai.response.texthandles multiple formats:content, JSON array of objects withcontentTool calls get
"type": "tool_call"added. Both are combined into one assistant message:[{"role": "assistant", "parts": [...]}].Changes
relay-conventions/build/attributes.rs— addTransformvariant toDeprecationStatus, producingWriteBehavior::CurrentNamerelay-event-normalization/src/eap/gen_ai_transform.rs— new module with transformation logicrelay-event-normalization/src/eap/ai.rs—normalize_aicallstransform_gen_aias its first steprelay-event-schema/src/protocol/span.rs— remove legacy aliases for the three deprecated attributesrelay-conventions/sentry-conventions— update submodule to PR fix(server): Allow multipart requests without trailing newline #465 branchTests
test_ai_spans_example_transactionexpectationsContributes to TET-2587