fix: shared enum for gen_ai.operation.name values (#6416) - #7623
Closed
DawnofGenX wants to merge 1 commit into
Closed
DawnofGenX wants to merge 1 commit into
DawnofGenX wants to merge 1 commit into
Conversation
Contributor
|
Going to close this because we don't have capacity to review the 5 PRs you've opened. |
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
Follow-up to the review discussion on #6404 (r3304429118): the
gen_ai.operation.namespan attribute values were hardcoded string literals scattered across the AI integrations (chat,execute_tool,invoke_agent, ...).This PR introduces a shared
GENAIOPERATIONstring enum insentry_sdk/consts.py(following the existingSPANTEMPLATE(str, Enum)precedent) and replaces all 58 static literal usages SDK-wide with enum members:sentry_sdk/consts.py— newGENAIOPERATIONenum with the 8 values currently emitted by the SDK:CHAT,CREATE_AGENT,EMBEDDINGS,EXECUTE_TOOL,HANDOFF,INVOKE_AGENT,RESPONSES,TEXT_COMPLETION.anthropic,openai,openai_agents(ai_client / execute_tool / handoff / invoke_agent),pydantic_ai(ai_client / execute_tool / invoke_agent),langchain,langgraph,litellm,mistral,google_genai, andtracing_utils(the@ai_tracktemplates).GENAIOPERATIONis astrsubclass with__str__returning the value (identical semantics toSPANTEMPLATE), sof"{GENAIOPERATION.CHAT} model"(used by litellm span names) and every serializer path produce the exact same bytes as before.operation_nameinhuggingface_hubderives from theOPconstant, so it is unchanged by design.Wire values are byte-identical — this is a pure refactor, no behavior change.
Closes #6416
Wire-compatibility evidence
Ran the pydantic_ai integration suite (which asserts
gen_ai.operation.namevalues on captured envelopes) on unpatched upstream/master and on this branch, same env, same command:Additionally verified serialization identity directly:
Test plan
tests/test_consts.py: pins everyGENAIOPERATIONmember name and value to the exact wire strings, plusstr()/f-string/json.dumpsround-trips — a rename or revalue now fails CI (regression guard requested in Create an enum for possiblegen_ai.operation.namevalues #6416).py3.14-common(full core suite incl. new tests):2252 passed, 174 skippedpy3.14-pydantic_ai-latest:331 passed(before/after above)py3.14-anthropic-latest:587 passedpy3.14-openai_agents-latest:305 passedpy3.14-openai-base-latest:686 passedpy3.14-langchain-base-latest:625 passedpy3.14-langgraph-v0.6.11:146 passedpy3.14-litellm-latest:171 passedpy3.14-mistral-latest:88 passedpy3.14-google_genai-latest:526 passed, 1 skippeduv run ruff check --fix sentry_sdk tests→ All checks passeduv run ruff format sentry_sdk tests→ formatteduv run --group typing mypy sentry_sdk→Success: no issues found in 194 source files